EXPERIMENTAL: global suspend cleanup
Subsystems (6)
PATCH 1/1 EXPERIMENTAL: global suspend cleanup
Hi !
(This is not to be merged upstream or anywhere else yet)
This patch applies on top of my previous ones. It moves all of the PowerMac PM code away from drivers/macintosh/via-pmu.c to a new arch/ppc/platforms/pmac_pm.c file, and "merges" the code for supporting suspend to RAM and suspend to disk in a more consistent way. It also fixes issues with suspend to disk. Currently, the refrigerator is still used for suspend to RAM _and_ suspend to disk, I may consider keeping it if it gets fast & reliable enough in 2.6.13 as it does work around issues with misbehaved userland processes vs. kernel driver races, though i'd rather have the kernel fixed :)
Note to linux-pm citizens: This merges the pmac PM code into the "core" PM infrastructure. In order to do that properly, I had to add a significant amount of callbacks to pm_ops, in fact, I need basically a hook between every step for various reasons. There is also some significant discrepancy between the hooks used by "generic" stuffs and the ones used by swsusp. The later doesn't call all the normal hooks in all cases but then has it's own support functions (arch_prepare_suspend(), save/restore_cpu_state()) that are not in pm_ops... this is rather a mess, though I got it all together for pmac.
Please comment on those changes.
I also fixed what I think is a possible bug in device_suspend() if it fails, it can leave some stuffs in the dpm_irq_off list forever.
I've also had to remove the sysdev I used for the interrupt controllers. I have an ordering problems here. I absolutely need the interrupt controller suspend code to be run after cpufreq and the resume one before cpufreq, which is simply not possible right now with a sysdev (unless I hook on the cpu class itself suspend/resume routines but that's ugly). cpufreq is a driver of class cpu, which is first registered, and thus is always the first in the list.
For now, the PIC suspend/resume code is back into arch specific realm.
I'm still having some problems with the refrigerator. It tends to regulary fail to freeze pmud for some reason I haven't yet explained. I need to add more debugging to it. But I may not bother if Nigel's new implementation gets in 2.6.13.
I did some tests of both suspend to ram and to disk on an old tipb model and it appears to work fine, but I haven't stressed it nor tested on any other machine yet.
Note that with this patch, you can use echo "mem" /sys/power/state to trigger suspend-to-RAM. The old ioctl on /dev/pmu still works, and will trigger suspend-to-RAM on machiens where it's supported and will fallback to suspend-to-disk when not.
arch/ppc/platforms/Makefile +3 -2
@@ -10,8 +10,9 @@ obj-$(CONFIG_PCI) += apus_pci.o endif obj-$(CONFIG_PPC_PMAC) += pmac_pic.o pmac_setup.o pmac_time.o \ - pmac_feature.o pmac_pci.o pmac_sleep.o \ - pmac_low_i2c.o pmac_cache.o + pmac_feature.o pmac_pci.o pmac_sleep.o \ + pmac_low_i2c.o pmac_cache.o pmac_pm.o + obj-$(CONFIG_PPC_CHRP) += chrp_setup.o chrp_time.o chrp_pci.o \ chrp_pegasos_eth.o obj-$(CONFIG_PPC_PREP) += prep_pci.o prep_setup.o
arch/ppc/platforms/pmac_pm.c new file +782 -0
782 lines not on this page · raw message
arch/ppc/platforms/pmac_setup.c +1 -63
76 lines not on this page · raw message
drivers/base/power/suspend.c +12 -1
@@ -100,8 +100,19 @@put_device (dev); }up (&dpm_list_sem); -if (error) +if (error) { +/* we failed... before resuming, bring back devices from +* dpm_off_irq list back to main dpm_off list, we do want +* to call resume() on them, in case they partially suspended +* despite returning -EAGAIN +*/ +while (!list_empty (&dpm_off_irq)) { +struct list_head * entry = dpm_off_irq.next; +list_del (entry); +list_add (entry, &dpm_off); + }dpm_resume (); + }up (&dpm_sem);return error; }
drivers/macintosh/via-pmu.c +41 -667
986 lines not on this page · raw message
include/asm-ppc/machdep.h +6 -0
@@ -110,6 +110,12 @@*/ long (*feature_call)(unsigned int feature, ...); +#ifdef CONFIG_SOFTWARE_SUSPEND +int (*arch_prepare_suspend)(void ); +void (*save_processor_state)(void ); +void (*restore_processor_state)(void ); +#endif /* CONFIG_SOFTWARE_SUSPEND */ +#ifdef CONFIG_SMP /* functions for dealing with other cpus */ struct smp_ops_t *smp_ops;
include/asm-ppc/suspend.h +32 -0
@@ -1,12 +1,44 @@ +#ifndef __PPC_SUSPEND_H +#define __PPC_SUSPEND_H + +#include <linux/config.h> +#include <linux/types.h> +#include <asm/machdep.h> + + +#ifdef CONFIG_SOFTWARE_SUSPEND static inline int arch_prepare_suspend (void ) { +if (ppc_md.arch_prepare_suspend) +return ppc_md.arch_prepare_suspend ();return 0 ; }static inline void save_processor_state (void ) { +if (ppc_md.save_processor_state) +return ppc_md.save_processor_state (); }static inline void restore_processor_state (void ) { +if (ppc_md.restore_processor_state) +return ppc_md.restore_processor_state (); } +#else +static inline int arch_prepare_suspend (void ) +{ +return 0 ; +} + +static inline void save_processor_state (void ) +{ +} + +static inline void restore_processor_state (void ) +{ +} +#endif + + +#endif /* __PPC_SUSPEND_H */
include/linux/pm.h +30 -1
@@ -169,9 +169,38 @@struct pm_ops {suspend_disk_method_t pm_disk_mode; + +/* Call before process freezing. If returns 0, then no freeze +* should be done, if 1, freeze, negative -> error +*/ +int (*pre_freeze)(suspend_state_t state); + +/* called before devices are suspended */ int (*prepare)(suspend_state_t state); + +/* called just before irqs are off and device second pass +* and sysdevs are suspended. This function can on some archs +* shut irqs off, in which case, they'll still be off when +* finish_irqs() is called. +*/ +int (*prepare_irqs)(suspend_state_t state); + +/* called for entering the actual suspend state. Exits with +* machine worken up and interrupts off +*/ int (*enter)(suspend_state_t state); -int (*finish)(suspend_state_t state); + +/* called after sysdevs and "irq off" devices have been +* worken up, irqs have just been restored to whatever state +* prepare_irqs() left them in. +*/ +void (*finish_irqs)(suspend_state_t state); + +/* called after all devices are woken up, processes still frozen */ +void (*finish)(suspend_state_t state); + +/* called after unfreezing userland */ +void (*post_freeze)(suspend_state_t state); };extern void pm_set_ops (struct pm_ops *);
include/linux/pmu.h +3 -0
@@ -151,6 +151,9 @@extern void pmu_suspend (void );extern void pmu_resume (void ); +extern void pmu_save_via_state (void ); +extern void pmu_restore_via_state (void ); +extern void pmu_enable_irled (int on);extern void pmu_restart (void );
kernel/power/main.c +34 -4
@@ -23,6 +23,7 @@struct pm_ops * pm_ops =NULL ;suspend_disk_method_t pm_disk_mode =PM_DISK_SHUTDOWN ; +static int pm_process_frozen;/** * pm_set_ops - Set the global power method table.
@@ -49,32 +50,53 @@static int suspend_prepare (suspend_state_t state) {int error =0 ; +int freeze =1 ;if (!pm_ops || !pm_ops->enter)return -EPERM ;pm_prepare_console (); -if (freeze_processes ()) { +if (pm_ops->pre_freeze) + freeze = pm_ops->pre_freeze (state); +if (freeze <0 ) + goto Console; + +if (freeze &&freeze_processes ()) { error = -EAGAIN ; goto Thaw; } + pm_process_frozen = freeze;if (pm_ops->prepare) { +pr_debug ("preparing arch...\n" );if ((error = pm_ops->prepare (state))) goto Thaw; } +pr_debug ("suspending devices...\n" );if ((error =device_suspend (PMSG_SUSPEND ))) {printk (KERN_ERR "Some devices failed to suspend\n" ); goto Finish; } + +if (pm_ops->prepare_irqs) { +pr_debug ("preparing arch irqs...\n" ); +if ((error = pm_ops->prepare_irqs (state))) + goto Finish; + } +return 0 ; Finish:if (pm_ops->finish) pm_ops->finish (state); Thaw: -thaw_processes (); +if (freeze) +thaw_processes (); + +if (pm_ops->post_freeze) + pm_ops->post_freeze (state); + Console:pm_restore_console ();return error; }
@@ -109,10 +131,18 @@static void suspend_finish (suspend_state_t state) { +if (!pm_ops) +return ; + +if (pm_ops->finish_irqs) + pm_ops->finish_irqs (state);device_resume (); -if (pm_ops && pm_ops->finish) +if (pm_ops->finish) pm_ops->finish (state); -thaw_processes (); +if (pm_process_frozen) +thaw_processes (); +if (pm_ops->post_freeze) + pm_ops->post_freeze (state);pm_restore_console (); }
arch/ppc/platforms/pmac_pic.c +4 -7
@@ -619,7 +619,7 @@return viaint; } -static int pmacpic_suspend (struct sys_device *sysdev,u32 state) +void __pmac pmacpic_suspend(void) {int viaint =pmacpic_find_viaint ();
@@ -636,11 +636,9 @@/* make sure mask gets to controller before we return to caller */ mb (); (void )in_le32 (&pmac_irq_hw[0 ]->enable); - -return 0 ; } -static int pmacpic_resume (struct sys_device *sysdev) +void __pmac pmacpic_resume(void) {int i;
@@ -651,12 +649,11 @@for (i =0 ; i < max_real_irqs; ++i)if (test_bit (i, sleep_save_mask)) pmac_unmask_irq(i); - - return 0; }#endif /* CONFIG_PM */ +#if 0 static struct sysdev_class pmacpic_sysclass = {set_kset_name ("pmac_pic" ), };
@@ -686,4 +683,4 @@ }subsys_initcall (init_pmacpic_sysfs); - +#endif
arch/ppc/syslib/open_pic.c +13 -19
@@ -948,11 +948,7 @@ save_irq_src_vp[irq - open_pic_irq_offset] |=OPENPIC_MASK ; } -/* WARNING: Can be called directly by the cpufreq code with NULL parameter, -* we need something better to deal with that... Maybe switch to S1 for -* cpufreq changes -*/ -int openpic_suspend (struct sys_device *sysdev,u32 state) +void openpic_suspend (void ) {int i;unsigned long flags;
@@ -961,11 +957,9 @@if (openpic_suspend_count++ >0 ) {spin_unlock_irqrestore (&openpic_setup_lock, flags); -return 0 ; +return ; } -openpic_set_priority (0xf ); - open_pic.enable = openpic_cached_enable_irq; open_pic.disable = openpic_cached_disable_irq;
@@ -975,6 +969,8 @@ OPENPIC_CURRENT_TASK_PRIORITY_MASK, 0xf); } +openpic_set_priority (0xf ); +for (i=0 ; i<OPENPIC_NUM_IPI ; i++) save_ipi_vp[i] =openpic_read (&OpenPIC->Global.IPI_Vector_Priority (i));for (i=0 ; i<NumSources; i++) {
@@ -985,15 +981,13 @@ }spin_unlock_irqrestore (&openpic_setup_lock, flags); - -return 0 ; }/* WARNING: Can be called directly by the cpufreq code with NULL parameter, * we need something better to deal with that... Maybe switch to S1 for * cpufreq changes */ -int openpic_resume (struct sys_device *sysdev) +void openpic_resume (void ) {int i;unsigned long flags;
@@ -1005,9 +999,11 @@if ((--openpic_suspend_count) >0 ) {spin_unlock_irqrestore (&openpic_setup_lock, flags); -return 0 ; +return ; } +openpic_set_priority (0xf ); +/* OpenPIC sometimes seem to need some time to be fully back up... */ do { openpic_set_spurious(OPENPIC_VEC_SPURIOUS);
@@ -1030,22 +1026,19 @@ } while (openpic_readfield(&ISR[i]->Vector_Priority, vppmask) != (save_irq_src_vp[i] & vppmask)); } -for (i=0 ; i<NumProcessors; i++) -openpic_write (&OpenPIC->Processor[i].Current_Task_Priority, - save_cpu_task_pri[i]); - open_pic.enable = openpic_enable_irq; open_pic.disable = openpic_disable_irq; -openpic_set_priority (0 ); +for (i=0 ; i<NumProcessors; i++) +openpic_write (&OpenPIC->Processor[i].Current_Task_Priority, + save_cpu_task_pri[i]);spin_unlock_irqrestore (&openpic_setup_lock, flags); - -return 0 ; }#endif /* CONFIG_PM */ +#if 0 static struct sysdev_class openpic_sysclass = {set_kset_name ("openpic" ), };
@@ -1089,3 +1082,4 @@subsys_initcall (init_openpic_sysfs); +#endif
include/asm-ppc/open_pic.h +3 -0
@@ -64,6 +64,9 @@extern void openpic_set_priority (u_int pri);extern u_int openpic_get_priority (void ); +extern void openpic_suspend (void ); +extern void openpic_resume (void ); +extern inline int openpic_to_irq (int irq) {/* IRQ 0 usually means 'disabled'.. don't mess with it