Skip to contentSkip to conversation

Improve PCI config space writeback.

PATCH Dave Jones 2 participants 3 messages Apr 16, 2006 – Apr 17, 2006 PCI

lore
Share & tools
lore

Dave Jones

author
#0 lore raw

At least one laptop blew up on resume from suspend with a black screen due to a lack of this patch. By only writing back config space that is different, we minimise the possibility of accidents like this.

drivers/pci/pci.c renamed from drivers/pci/pci.c~ +10 -2
@@ -461,9 +461,17 @@ int 
 pci_restore_state(struct pci_dev *dev)
 {
 	int i;
+	int val;
 
-	for (i = 0; i < 16; i++)
-		pci_write_config_dword(dev,i * 4, dev->saved_config_space[i]);
+	for (i = 0; i < 16; i++) {
+		pci_read_config_dword(dev, i * 4, &val);
+		if (val != dev->saved_config_space[i]) {
+			printk (KERN_DEBUG "PM: Writing back config space on device %s at offset %x. (Was %x, writing %x)\n",
+				pci_name(dev), i,
+				val, (int) dev->saved_config_space[i]);
+			pci_write_config_dword(dev,i * 4, dev->saved_config_space[i]);
+		}
+	}
 	pci_restore_msi_state(dev);
 	pci_restore_msix_state(dev);
 	return 0;
#1 lore raw
Quoted 5 lines · Dave Jones

At least one laptop blew up on resume from suspend with a black screen due to a lack of this patch. By only writing back config space that is different, we minimise the possibility of accidents like this.

I think it's a mistake to restore the command register before the rest. It should be restored last.

Quoted 28 lines
drivers/pci/pci.c renamed from drivers/pci/pci.c~ +10 -3
@@ -461,9 +461,17 @@ int 
 pci_restore_state(struct pci_dev *dev)
 {
 	int i;
+	int val;
 
-	for (i = 0; i < 16; i++)
-		pci_write_config_dword(dev,i * 4, dev->saved_config_space[i]);
+	for (i = 0; i < 16; i++) {
+		pci_read_config_dword(dev, i * 4, &val);
+		if (val != dev->saved_config_space[i]) {
+			printk (KERN_DEBUG "PM: Writing back config space on device %s at offset %x. (Was %x, writing %x)\n",
+				pci_name(dev), i,
+				val, (int) dev->saved_config_space[i]);
+			pci_write_config_dword(dev,i * 4, dev->saved_config_space[i]);
+		}
+	}
 	pci_restore_msi_state(dev);
 	pci_restore_msix_state(dev);
 	return 0;
-

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

author
#2 lore raw
Quoted 9 lines · Ben Herrenschmidt
Quoted 5 lines · Dave Jones

At least one laptop blew up on resume from suspend with a black screen due to a lack of this patch. By only writing back config space that is different, we minimise the possibility of accidents like this.

I think it's a mistake to restore the command register before the rest. It should be restored last.

Adam Belay had a patch that did this, and a bunch of other similar things (like making sure we never set BIST when restoring).

There are likely a number of similar possible improvements.

Dave

Signature · 1 line
http://www.codemonkey.org.uk