Skip to contentSkip to conversation

Do not suspend PCI devices twice [PATCH for testing]

PATCH Pavel Machek 1 participant 3 messages Aug 4, 2003 Kbuild

lore
Share & tools
lore
#0 lore raw

Hi!

PCI devices are suspendend twice; once using pm_send_all() and once because of driver model (when using ACPI). That's bad.

If I kill pm_send_all() hook, they will not be suspended at all with APM, because APM does not call device_suspend(..., SUSPEND_SAVE_STATE). This patch fixes both of these.

Ouch, no it does not. You should > drivers/pci/power.c. Its no longer needed.

It compiles, and I'd like someone to test it ;-).
Pavel

usr/src/linux/arch/i386/kernel/apm.c renamed from usr/src/tmp/linux/arch/i386/kernel/apm.c +21 -7
@@ -1185,19 +1185,23 @@
 	int		err;
 	struct apm_user	*as;
 
+	if (device_suspend(3, SUSPEND_NOTIFY))
+		if (vetoable)
+			goto veto;
+	if (device_suspend(3, SUSPEND_SAVE_STATE)) {
+		if (vetoable) {
+			device_resume(RESUME_RESTORE_STATE);
+			goto veto;
+		}
+	}
 	if (pm_send_all(PM_SUSPEND, (void *)3)) {
 		/* Vetoed */
 		if (vetoable) {
-			if (apm_info.connection_version > 0x100)
-				set_system_power_state(APM_STATE_REJECT);
-			err = -EBUSY;
-			ignore_sys_suspend = 0;
-			printk(KERN_WARNING "apm: suspend was vetoed.\n");
-			goto out;
+			device_resume(RESUME_RESTORE_STATE);
+			goto veto;
 		}
 		printk(KERN_CRIT "apm: suspend was vetoed, but suspending anyway.\n");
 	}
-
 	device_suspend(3, SUSPEND_POWER_DOWN);
 
 	/* serialize with the timer interrupt */
@@ -1234,7 +1238,17 @@
 	err = (err == APM_SUCCESS) ? 0 : -EIO;
 	device_resume(RESUME_POWER_ON);
 	pm_send_all(PM_RESUME, (void *)0);
+	device_resume(RESUME_RESTORE_STATE);
 	queue_event(APM_NORMAL_RESUME, NULL);
+
+	if (0) {
+ veto:
+		if (apm_info.connection_version > 0x100)
+			set_system_power_state(APM_STATE_REJECT);
+		err = -EBUSY;
+		ignore_sys_suspend = 0;
+		printk(KERN_WARNING "apm: suspend was vetoed.\n");
+	}
  out:
 	spin_lock(&user_list_lock);
 	for (as = user_list; as != NULL; as = as->next) {
usr/src/linux/drivers/pci/power.c renamed from usr/src/tmp/linux/drivers/pci/power.c +1 -0
@@ -157,3 +157,4 @@
 }
 
 subsys_initcall(pci_pm_init);
+
usr/src/linux/drivers/pci/probe.c renamed from usr/src/tmp/linux/drivers/pci/probe.c +4 -0
diff -ur -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x vmlinuz -x TAGS -x bootsect -x '*RCS*' -x conmakehash -x map -x build -x build -x configure -x '*target*' -x '*.flags' -x '*.bak' -x '*.cmd' /usr/src/tmp/linux/drivers/pci/probe.c /usr/src/linux/drivers/pci/probe.c
@@ -633,6 +633,9 @@
 	return max;
 }
 
+struct device_driver pci_driver = {
+};
+
 struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, int bus, struct pci_ops *ops, void *sysdata)
 {
 	struct pci_bus *b;
@@ -664,6 +667,7 @@
 	b->dev->parent = parent;
 	sprintf(b->dev->bus_id,"pci%04x:%02x", pci_domain_nr(b), bus);
 	strcpy(b->dev->name,"Host/PCI Bridge");
+	b->dev->driver = &pci_driver;
 	device_register(b->dev);
 
 	b->number = b->secondary = bus;
usr/src/linux/drivers/usb/core/hcd.c renamed from usr/src/tmp/linux/drivers/usb/core/hcd.c +25 -24

62 lines not on this page · raw message

usr/src/linux/drivers/usb/host/ohci-pci.c renamed from usr/src/tmp/linux/drivers/usb/host/ohci-pci.c +5 -0
diff -ur -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x vmlinuz -x TAGS -x bootsect -x '*RCS*' -x conmakehash -x map -x build -x build -x configure -x '*target*' -x '*.flags' -x '*.bak' -x '*.cmd' /usr/src/tmp/linux/drivers/usb/host/ohci-pci.c /usr/src/linux/drivers/usb/host/ohci-pci.c
@@ -199,6 +199,11 @@
 	int			retval = 0;
 	unsigned long		flags;
 
+	if (hcd->state == USB_STATE_HALT) {
+		ohci_dbg (ohci, "USB restart of halted device\n");
+		return -EL3HLT;
+	}
+
 #ifdef CONFIG_PMAC_PBOOK
 	{
 		struct device_node *of_node;

Only in /usr/src/linux/drivers/video/logo: logo_linux_clut224.c Only in /usr/src/linux/include/asm-i386: asm_offsets.h Only in /usr/src/linux/include: config

usr/src/linux/kernel/suspend.c renamed from usr/src/tmp/linux/kernel/suspend.c +10 -5
diff -ur -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinux -x vmlinuz -x TAGS -x bootsect -x '*RCS*' -x conmakehash -x map -x build -x build -x configure -x '*target*' -x '*.flags' -x '*.bak' -x '*.cmd' /usr/src/tmp/linux/kernel/suspend.c /usr/src/linux/kernel/suspend.c
@@ -630,16 +630,20 @@
 static void drivers_unsuspend(void)
 {
 	device_resume(RESUME_RESTORE_STATE);
+	pm_send_all(PM_RESUME, (void *)0);
 	device_resume(RESUME_ENABLE);
 }
 
 /* Called from process context */
 static int drivers_suspend(void)
 {
-	device_suspend(4, SUSPEND_NOTIFY);
-	device_suspend(4, SUSPEND_SAVE_STATE);
-	device_suspend(4, SUSPEND_DISABLE);
-	if(!pm_suspend_state) {
+	if (device_suspend(4, SUSPEND_NOTIFY))
+		return -EIO;
+	if (device_suspend(4, SUSPEND_SAVE_STATE)) {
+		device_resume(RESUME_RESTORE_STATE);
+		return -EIO;
+	}
+	if (!pm_suspend_state) {
 		if(pm_send_all(PM_SUSPEND,(void *)3)) {
 			printk(KERN_WARNING "Problem while sending suspend event\n");
 			return(1);
@@ -647,6 +651,7 @@
 		pm_suspend_state=1;
 	} else
 		printk(KERN_WARNING "PM suspend state already raised\n");
+	device_suspend(4, SUSPEND_DISABLE);
 	  
 	return(0);
 }
@@ -868,7 +873,7 @@
 		blk_run_queues();
 
 		/* Save state of all device drivers, and stop them. */		   
-		if(drivers_suspend()==0)
+		if (drivers_suspend()==0)
 			/* If stopping device drivers worked, we proceed basically into
 			 * suspend_save_image.
 			 *

Only in /usr/src/linux/lib: crc32table.h
Only in /usr/src/linux/lib: gen_crc32table Only in /usr/src/linux: patches
Only in /usr/src/linux/scripts: docproc
Only in /usr/src/linux/scripts: elfconfig.h Only in /usr/src/linux/scripts: fixdep
Only in /usr/src/linux/scripts: kallsyms
Only in /usr/src/linux/scripts/kconfig: conf Only in /usr/src/linux/scripts/kconfig: lex.zconf.c Only in /usr/src/linux/scripts/kconfig: libkconfig.so Only in /usr/src/linux/scripts/kconfig: zconf.tab.c Only in /usr/src/linux/scripts/kconfig: zconf.tab.h Only in /usr/src/linux/scripts: mk_elfconfig Only in /usr/src/linux/scripts: modpost
Only in /usr/src/linux/scripts: pnmtologo Only in /usr/src/linux/scripts: split-include Only in /usr/src/linux: txt
Only in /usr/src/linux/usr: gen_init_cpio Only in /usr/src/linux/usr: initramfs_data.cpio Only in /usr/src/linux/usr: initramfs_data.cpio.gz

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#1 lore raw

Hi!

Quoted 11 lines

PCI devices are suspendend twice; once using pm_send_all() and once because of driver model (when using ACPI). That's bad.

If I kill pm_send_all() hook, they will not be suspended at all with APM, because APM does not call device_suspend(..., SUSPEND_SAVE_STATE). This patch fixes both of these.

Ouch, no it does not. You should > drivers/pci/power.c. Its no longer needed.

It compiles, and I'd like someone to test it ;-).

Oops, wrong patch attached.

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#2 lore raw
In reply to Pavel Machek

Hi!

Quoted 11 lines

PCI devices are suspendend twice; once using pm_send_all() and once because of driver model (when using ACPI). That's bad.

If I kill pm_send_all() hook, they will not be suspended at all with APM, because APM does not call device_suspend(..., SUSPEND_SAVE_STATE). This patch fixes both of these.

Ouch, no it does not. You should > drivers/pci/power.c. Its no longer needed.

It compiles, and I'd like someone to test it ;-).

Here's the right patch. You no longer need to > power.c.

Pavel

usr/src/linux/arch/i386/kernel/apm.c renamed from usr/src/tmp/linux/arch/i386/kernel/apm.c +21 -7
@@ -1185,19 +1185,23 @@
 	int		err;
 	struct apm_user	*as;
 
+	if (device_suspend(3, SUSPEND_NOTIFY))
+		if (vetoable)
+			goto veto;
+	if (device_suspend(3, SUSPEND_SAVE_STATE)) {
+		if (vetoable) {
+			device_resume(RESUME_RESTORE_STATE);
+			goto veto;
+		}
+	}
 	if (pm_send_all(PM_SUSPEND, (void *)3)) {
 		/* Vetoed */
 		if (vetoable) {
-			if (apm_info.connection_version > 0x100)
-				set_system_power_state(APM_STATE_REJECT);
-			err = -EBUSY;
-			ignore_sys_suspend = 0;
-			printk(KERN_WARNING "apm: suspend was vetoed.\n");
-			goto out;
+			device_resume(RESUME_RESTORE_STATE);
+			goto veto;
 		}
 		printk(KERN_CRIT "apm: suspend was vetoed, but suspending anyway.\n");
 	}
-
 	device_suspend(3, SUSPEND_POWER_DOWN);
 
 	/* serialize with the timer interrupt */
@@ -1234,7 +1238,17 @@
 	err = (err == APM_SUCCESS) ? 0 : -EIO;
 	device_resume(RESUME_POWER_ON);
 	pm_send_all(PM_RESUME, (void *)0);
+	device_resume(RESUME_RESTORE_STATE);
 	queue_event(APM_NORMAL_RESUME, NULL);
+
+	if (0) {
+ veto:
+		if (apm_info.connection_version > 0x100)
+			set_system_power_state(APM_STATE_REJECT);
+		err = -EBUSY;
+		ignore_sys_suspend = 0;
+		printk(KERN_WARNING "apm: suspend was vetoed.\n");
+	}
  out:
 	spin_lock(&user_list_lock);
 	for (as = user_list; as != NULL; as = as->next) {
usr/src/linux/drivers/pci/power.c renamed from usr/src/tmp/linux/drivers/pci/power.c +0 -159

159 lines not on this page · raw message

usr/src/linux/kernel/suspend.c renamed from usr/src/tmp/linux/kernel/suspend.c +10 -5
@@ -630,16 +630,20 @@
 static void drivers_unsuspend(void)
 {
 	device_resume(RESUME_RESTORE_STATE);
+	pm_send_all(PM_RESUME, (void *)0);
 	device_resume(RESUME_ENABLE);
 }
 
 /* Called from process context */
 static int drivers_suspend(void)
 {
-	device_suspend(4, SUSPEND_NOTIFY);
-	device_suspend(4, SUSPEND_SAVE_STATE);
-	device_suspend(4, SUSPEND_DISABLE);
-	if(!pm_suspend_state) {
+	if (device_suspend(4, SUSPEND_NOTIFY))
+		return -EIO;
+	if (device_suspend(4, SUSPEND_SAVE_STATE)) {
+		device_resume(RESUME_RESTORE_STATE);
+		return -EIO;
+	}
+	if (!pm_suspend_state) {
 		if(pm_send_all(PM_SUSPEND,(void *)3)) {
 			printk(KERN_WARNING "Problem while sending suspend event\n");
 			return(1);
@@ -647,6 +651,7 @@
 		pm_suspend_state=1;
 	} else
 		printk(KERN_WARNING "PM suspend state already raised\n");
+	device_suspend(4, SUSPEND_DISABLE);
 	  
 	return(0);
 }
@@ -868,7 +873,7 @@
 		blk_run_queues();
 
 		/* Save state of all device drivers, and stop them. */		   
-		if(drivers_suspend()==0)
+		if (drivers_suspend()==0)
 			/* If stopping device drivers worked, we proceed basically into
 			 * suspend_save_image.
 			 *
Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]