Hi,

This is a first cut at supporting powerpc for s2*. For the s2ram bit it
basically removes the vbetool code. This has two reasons. First, there
isn't a powerpc version of libx86 yet. Second, the machines that have
support for s2ram in the kernel don't need those hacks.

As you noticed, I've asked some people to test it a bit already. The
s2ram part seems to work fine, the s2disk part still has some problems,
which could be related to its BE nature. But this will have to be fixed
anyway.

With this patch people can at least compile and give us some feedback.

grts Tim

Index: s2ram.c
===================================================================
RCS file: /cvsroot/suspend/suspend/s2ram.c,v
retrieving revision 1.51
diff -u -r1.51 s2ram.c
--- s2ram.c     16 Mar 2007 15:03:08 -0000      1.51
+++ s2ram.c     27 Mar 2007 07:55:33 -0000
@@ -10,14 +10,26 @@
 #include <getopt.h>
 #include <errno.h>
 #include <string.h>
+#ifdef CONFIG_PPC
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <linux/pmu.h>
+#endif
 
 #include <pci/pci.h>
 
 #ifndef S2RAM
 #define S2RAM
 #endif
-#include "vbetool/vbetool.h"
+
 #include "vt.h"
+#ifndef CONFIG_PPC
+#include "vbetool/vbetool.h"
 #include "s2ram.h"
 
 static void *vbe_buffer;
@@ -228,9 +240,13 @@
 
        return 0;
 }
+#endif
 
 int s2ram_prepare(void)
 {
+#ifdef CONFIG_PPC
+       return 0;
+#else
        int ret, id;
 
        dmi_scan();
@@ -243,13 +259,49 @@
        ret = s2ram_hacks();
 
        return ret;
+#endif
+}
+
+#ifdef CONFIG_PPC
+/* This will be deprecated, but is needed on older kernels (< May 2006) */ 
+int s2ram_do_pmu(void) {
+        int ret = 0,  fd;
+        unsigned long arg = 0;
+
+        if ((fd = open("/dev/pmu", O_RDWR)) < 0) 
+                return errno;
+        
+        ret = ioctl(fd, PMU_IOC_CAN_SLEEP, &arg);
+
+        if (!ret && arg != 1) 
+                ret = ENOTSUP;
+
+        if (!ret)
+                ret = ioctl(fd, PMU_IOC_SLEEP, arg);
+
+        close(fd);
+
+       return ret;
 }
+#endif
 
 /* Actually enter the suspend. May be ran on frozen system. */
 int s2ram_do(void)
 {
-       int ret = 0;
-       FILE *f = fopen("/sys/power/state", "w");
+       int ret = 0;
+       FILE *f;
+
+#ifdef CONFIG_PPC
+       ret = s2ram_do_pmu();
+       /* If the PMU says not supported, we better stop here, we could
+        * crash the machine on some kernels. On success we return too;) */
+       if (!ret || (ret == ENOTSUP))
+               return ret;
+       /* Else we just continue as if nothing happened, future kernels
+        * will work with /s/p/s. */
+       ret = 0;
+#endif
+       f = fopen("/sys/power/state", "w");
        if (!f) {
                printf("/sys/power/state does not exist; what kind of ninja 
mutant machine is this?\n");
                return ENODEV;
@@ -260,6 +322,7 @@
 } 
 
 void s2ram_resume(void)
 {
+#ifndef CONFIG_PPC
        if (flags & PCI_SAVE) {
                printf("restoring PCI config of device %02x:%02x.%d\n",
                        vga_dev.bus, vga_dev.dev, vga_dev.func);
@@ -297,6 +351,7 @@
                printf("Calling radeon_cmd_light(1)\n");
                radeon_cmd_light(1);
        }
+#endif
 }
 
 #ifndef CONFIG_BOTH
@@ -306,6 +361,7 @@
               "\n"
               "Options:\n"
               "    -h, --help:       this text.\n"
+#ifndef CONFIG_PPC
               "    -n, --test:       test if the machine is in the database.\n"
               "                      returns 0 if known and supported\n"
               "    -i, --identify:   prints a string that identifies the 
machine.\n"
@@ -322,6 +378,7 @@
                                       "suspend\n"
               "                      1=s3_bios, 2=s3_mode, 3=both\n"
               "    -v, --pci_save:   save the PCI config space for the VGA 
card.\n"
+#endif
               "\n");
        exit(1);
 }
@@ -331,8 +388,8 @@
        int i, id = -1, ret = 0, test_mode = 0, force = 0;
        int active_console = -1;
        struct option options[] = {
-               { "test",       no_argument,            NULL, 'n'},
                { "help",       no_argument,            NULL, 'h'},
+               { "test",       no_argument,            NULL, 'n'},
                { "force",      no_argument,            NULL, 'f'},
                { "vbe_save",   no_argument,            NULL, 's'},
                { "vbe_post",   no_argument,            NULL, 'p'},
@@ -349,6 +406,7 @@
                case 'h':
                        usage();
                        break;
+#ifndef CONFIG_PPC
                case 'i':
                        dmi_scan();
                        identify_machine();
@@ -377,11 +435,21 @@
                case 'v':
                        flags |= PCI_SAVE;
                        break;
+#else 
+               /* For consistency with the non-ppc version, it seems best to 
+                * me to accept, but ignore the s2ram 'hacks'. */
                default:
+                       fprintf(stderr, "The powerpc version of s2ram doesn't "
+                                       "take any options.\n");
+                       break;
+#endif
+               case '?':
                        usage();
                        break;
+
                }
        }
+#ifndef CONFIG_PPC
        if (flags && !force) {
                printf("acpi_sleep, vbe_save, vbe_post and radeontool parameter 
"
                       "must be used with --force\n\n");
@@ -414,15 +482,17 @@
 
        if (ret)
                goto out;
-
+#endif
        /* switch to console 1 first, since we might be in X */
        active_console = fgconsole();
        printf("Switching from vt%d to vt1\n", active_console);
        chvt(1);
 
+#ifndef CONFIG_PPC
        ret = s2ram_hacks();
        if (ret)
                goto out;
+#endif
        ret = s2ram_do();
        s2ram_resume();
 

Attachment: signature.asc
Description: PGP signature

-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to