On Wed, Jan 10, 2007 at 12:26:07PM +0100, Pavel Machek wrote:
> Hi!
> 
> > > Well, Frank was wrong here for subtle reason, and I did not like it:
> > >
> > > If malloc failed (basically can not happen, but...) he'd suspend,
> > > anyway, failing to restore PCI config at the exit, and bringing video
> > > corruption back to us... Without knowing that pci save state failed.
> > You are absolutly right, this wan't that nice. But it still could happen, 
> > that find_vga returns NULL (eventhoug of course this is now very unlikely)
> > and furthermore we now have a second global variable for
> > the same thing (global static pointer to global static struct).
> > 
> > So, i did a further cleanup to this patch. This version has only one global
> > struct for the vga_dev and terminates execution if vga_dev 
> > couldn't be found.
> 
> If you can get me version relative to current cvs,

here it is (some small changes to Frank's patch are: do not initialize *pacc,
static vga_pci_state, a comment on why we fail suspend, whitespace cleanups):

 s2ram.c |   42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

Index: s2ram.c
===================================================================
RCS file: /cvsroot/suspend/suspend/s2ram.c,v
retrieving revision 1.46
diff -u -p -r1.46 s2ram.c
--- s2ram.c     10 Jan 2007 08:04:55 -0000      1.46
+++ s2ram.c     10 Jan 2007 12:03:55 -0000
@@ -20,7 +20,7 @@
 
 static void *vbe_buffer;
 static unsigned char vga_pci_state[256];
-static struct pci_dev *vga_dev;
+static struct pci_dev vga_dev;
 static struct pci_access *pacc;
 /* Flags set from whitelist */
 static int flags, vbe_mode = -1;
@@ -150,9 +150,7 @@ int s2ram_check(int id)
        return ret;
 }
 
-static struct pci_dev vga_dev_s;
-
-struct pci_dev *find_vga(void)
+int find_vga(void)
 {
        struct pci_dev *dev;
 
@@ -165,21 +163,22 @@ struct pci_dev *find_vga(void)
        }
 
        if (!dev)
-               return NULL;
+               return 0;
+
+       memcpy(&vga_dev, dev, sizeof(*dev));
+       vga_dev.next = NULL;
 
-       memcpy(&vga_dev_s, dev, sizeof(*dev));
-       vga_dev_s.next = NULL;
-       return &vga_dev_s;
+       return 1;
 }
 
-void save_vga_pci(struct pci_dev *dev)
+void save_vga_pci(void)
 {
-       pci_read_block(dev, 0, vga_pci_state, 256);
+       pci_read_block(&vga_dev, 0, vga_pci_state, 256);
 }
 
-void restore_vga_pci(struct pci_dev *dev)
+void restore_vga_pci(void)
 {
-       pci_write_block(dev, 0, vga_pci_state, 256);
+       pci_write_block(&vga_dev, 0, vga_pci_state, 256);
 }
 
 /* warning: we have to be on a text console when calling this */
@@ -212,14 +211,15 @@ int s2ram_hacks(void)
        }
        if (flags & PCI_SAVE) {
                pacc = pci_alloc();     /* Get the pci_access structure */
-               pci_init(pacc);         /* Initialize the PCI library */
+               pci_init(pacc);         /* Initialize the PCI library */
 
-               vga_dev = find_vga();
-               if (vga_dev) {
+               if (find_vga()) {
                        printf("saving PCI config of device %02x:%02x.%d\n",
-                               vga_dev->bus, vga_dev->dev, vga_dev->func);
-                       save_vga_pci(vga_dev);
-               }
+                               vga_dev.bus, vga_dev.dev, vga_dev.func);
+                       save_vga_pci();
+               } else
+                       /* pci_save requested, no VGA device found => abort */
+                       return 1;
        }
 
        return 0;
@@ -266,10 +266,10 @@ int s2ram_do(void)
 
 void s2ram_resume(void)
 {
-       if ((flags & PCI_SAVE) && vga_dev) {
+       if ((flags & PCI_SAVE) && vga_dev.device_class == 0x300) {
                printf("restoring PCI config of device %02x:%02x.%d\n",
-                       vga_dev->bus, vga_dev->dev, vga_dev->func);
-               restore_vga_pci(vga_dev);
+                       vga_dev.bus, vga_dev.dev, vga_dev.func);
+               restore_vga_pci();
 
                pci_cleanup(pacc);
        }

-- 
Stefan Seyfried
QA / R&D Team Mobile Devices        |              "Any ideas, John?"
SUSE LINUX Products GmbH, Nürnberg  | "Well, surrounding them's out." 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Suspend-devel mailing list
Suspend-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to