Il Sat, Apr 14, 2007 at 11:09:01PM +0200, Tim Dijkstra ha scritto: 
> Hi,
> 
> This patch fixes all my concerns I raised in the previous e-mail. It
> applies on top of lucas patch. So if you apply 1/2, I'll do this one
> on top. If everybody agrees that is...
> 
> grts 
> 
> diff -urN a/Makefile b/Makefile
> --- a/Makefile        2007-04-14 22:55:32.000000000 +0200
> +++ b/Makefile        2007-04-14 22:52:34.000000000 +0200
> @@ -14,7 +14,7 @@
>  
>  ###############################################################
>  
> -ARCH:=$(shell uname -m)
> +ARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/ppc.*/ppc/)
>  
>  CC_FLAGS=-I/usr/local/include -DS2RAM $(CFLAGS)
>  LD_FLAGS=-L/usr/local/lib

Just noticed: why the standard vars (CFLAGS, LDFLAGS) are not used
instead?

> @@ -22,11 +22,18 @@
>  BINARIES=s2disk s2both s2ram swap-offset resume
>  BINARIES_MIN=s2disk swap-offset
>  
> -S2RAM_OBJ=vt.o vbetool/vbetool.o radeontool.o dmidecode.o
> +S2RAM_OBJ=vt.o
>  SWSUSP_OBJ=vt.o md5.o encrypt.o config.o loglevel.o splash.o bootsplash.o 
>  
> -S2RAM_LD_FLAGS = $(LD_FLAGS) -lpci -lz -lx86
> +S2RAM_LD_FLAGS = $(LD_FLAGS)
>  SWSUSP_LD_FLAGS = $(LD_FLAGS)
> +ARCH=ppc

Ops :)

> +ifeq ($(ARCH), x86)
> +     S2RAM_OBJ += s2ram-x86.o dmidecode.o radeontool.o vbetool/vbetool.o
> +     S2RAM_LD_FLAGS += -lx86 -lpci -lz
> +else ifeq ($(ARCH), ppc)  
> +     S2RAM_OBJ += s2ram-ppc.o
> +endif
> diff -urN a/s2ram.c b/s2ram.c
> --- a/s2ram.c 2007-04-14 21:51:22.000000000 +0200
> +++ b/s2ram.c 2007-04-14 22:52:34.000000000 +0200
> @@ -27,7 +27,16 @@
>  int s2ram_do(void)
>  {
>       int ret = 0;
> -     FILE *f = fopen("/sys/power/state", "w");
> +     FILE *f;
> +
> +     /* If this works we're done. Else we just continue as if nothing 
> +      * happened, future kernels will work with /s/p/s. */
> +     ret = s2ram_do_pmu();
> +     if (!ret)
> +             return ret;
> +     ret = 0;
> +     
> +     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;

This is what I was trying to avoid. PMU in generic code is not nice.
I've corrected the 'ARCH' bug above and added headers as per Pavel's
comment.

Anyway, since PPC actually wants to override (as in "do something
different") s2ram_do it's also possibile to make it a weak symbol so
that s2ram-ppc.c can provides its own implementation, will generic code
contains a sensitive default. I'm attacching a patch with the weak
symbol version.


diff -X exclude -uN a/Makefile b/Makefile
--- a/Makefile  2007-04-10 23:46:38.000000000 +0200
+++ b/Makefile  2007-04-15 02:07:34.000000000 +0200
@@ -14,7 +14,7 @@
 
 ###############################################################
 
-ARCH:=$(shell uname -m)
+ARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/ppc.*/ppc/)
 
 CC_FLAGS=-I/usr/local/include -DS2RAM $(CFLAGS)
 LD_FLAGS=-L/usr/local/lib
@@ -22,11 +22,17 @@
 BINARIES=s2disk s2both s2ram swap-offset resume
 BINARIES_MIN=s2disk swap-offset
 
-S2RAM_OBJ=vt.o vbetool/vbetool.o radeontool.o dmidecode.o
+S2RAM_OBJ=vt.o
 SWSUSP_OBJ=vt.o md5.o encrypt.o config.o loglevel.o splash.o bootsplash.o 
 
-S2RAM_LD_FLAGS = $(LD_FLAGS) -lpci -lz -lx86
+S2RAM_LD_FLAGS = $(LD_FLAGS)
 SWSUSP_LD_FLAGS = $(LD_FLAGS)
+ifeq ($(ARCH), x86)
+       S2RAM_OBJ += s2ram-x86.o dmidecode.o radeontool.o vbetool/vbetool.o
+       S2RAM_LD_FLAGS += -lx86 -lpci -lz
+else ifeq ($(ARCH), ppc)  
+       S2RAM_OBJ += s2ram-ppc.o
+endif
 
 ifndef CONFIG_RESUME_DYN
 STATIC_LD_FLAGS = -static
@@ -81,13 +87,13 @@
        $(CC) $(CC_FLAGS) -DCONFIG_BOTH -c $< -o $@
 
 s2ram.o: s2ram.c s2ram.h whitelist.c
-       $(CC) $(CC_FLAGS) -include s2ram-x86.h -c $< -o $@
+       $(CC) $(CC_FLAGS) -include s2ram-$(ARCH).h -c $< -o $@
 
 md5.o encrypt.o: %.o : %.c %.h md5.h
        $(CC) $(CC_FLAGS) -DHAVE_INTTYPES_H -DHAVE_STDINT_H -c $< -o $@
 
 # Simple objects with header
-config.o vt.o bootsplash.o splash.o splashy_funcs.o vbetool/vbetool.o: %.o : 
%.c %.h
+config.o vt.o bootsplash.o splash.o splashy_funcs.o vbetool/vbetool.o 
s2ram-ppc.o s2ram-x86.o: %.o : %.c %.h
        $(CC) $(CC_FLAGS) -c $< -o $@
 
 # Simple object without header
@@ -98,11 +104,11 @@
 s2disk:        $(SWSUSP_OBJ) suspend.c
        $(CC) -g $(CC_FLAGS)  $^ -o $@ $(SWSUSP_LD_FLAGS)
 
-s2ram: $(S2RAM_OBJ) s2ram.o s2ram-x86.o
+s2ram: $(S2RAM_OBJ) s2ram.o
        $(CC) -g $(CC_FLAGS)  $^ -o $@ $(S2RAM_LD_FLAGS)
 
-s2both:        $(SWSUSP_OBJ) $(S2RAM_OBJ) s2ram-both.o suspend.c s2ram-x86.o
-       $(CC) -g $(CC_FLAGS) -DCONFIG_BOTH -include s2ram-x86.h $^ -o $@ 
$(SWSUSP_LD_FLAGS) $(S2RAM_LD_FLAGS)
+s2both:        $(SWSUSP_OBJ) $(S2RAM_OBJ) s2ram-both.o suspend.c
+       $(CC) -g $(CC_FLAGS) -DCONFIG_BOTH -include s2ram-$(ARCH).h  $^ -o $@ 
$(SWSUSP_LD_FLAGS) $(S2RAM_LD_FLAGS)
 
 resume:        resume.c $(SWSUSP_OBJ)
        $(CC) $(CC_FLAGS) $(STATIC_CC_FLAGS) $^ -o $@ $(STATIC_LD_FLAGS) 
$(SWSUSP_LD_FLAGS)
diff -X exclude -uN a/s2ram.c b/s2ram.c
--- a/s2ram.c   2007-04-10 21:40:41.000000000 +0200
+++ b/s2ram.c   2007-04-15 02:07:18.000000000 +0200
@@ -27,7 +27,16 @@
 int s2ram_do(void)
 {
        int ret = 0;
-       FILE *f = fopen("/sys/power/state", "w");
+       FILE *f;
+
+       /* If this works we're done. Else we just continue as if nothing 
+        * happened, future kernels will work with /s/p/s. */
+       ret = s2ram_do_pmu();
+       if (!ret)
+               return ret;
+       ret = 0;
+       
+       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;
diff -X exclude -uN a/s2ram.h b/s2ram.h
--- a/s2ram.h   2007-04-10 21:39:19.000000000 +0200
+++ b/s2ram.h   2007-04-15 02:23:38.000000000 +0200
@@ -30,5 +30,5 @@
 int s2ram_do(void);
 void s2ram_resume(void);
 void s2ram_add_flag(int opt, const char *arg);
-
+int s2ram_do_pmu(void);
 
diff -X exclude -uN a/s2ram-ppc.c b/s2ram-ppc.c
--- a/s2ram-ppc.c       1970-01-01 01:00:00.000000000 +0100
+++ b/s2ram-ppc.c       2007-04-15 02:25:00.000000000 +0200
@@ -0,0 +1,95 @@
+/*
+ * Suspend-to-RAM - PPC code
+ *
+ * Copyright 2006 Tim Dijkstra <[EMAIL PROTECTED]>
+ * Copyright 2006 Luca Tettamanti <[EMAIL PROTECTED]>
+ * Distribute under GPLv2.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <linux/pmu.h>
+
+#include "s2ram.h"
+
+void s2ram_usage_platform(void)
+{
+       /* No additional options for PPC */
+}
+
+void s2ram_add_flag(int opt, const char *arg)
+{
+}
+
+int s2ram_prepare(void)
+{
+       return 0;
+}
+
+void s2ram_resume(void)
+{
+       /* nop */
+}
+
+void identify_machine(void)
+{
+       /* TODO */
+}
+
+int s2ram_hacks(void)
+{
+       return 0;
+}
+
+int s2ram_is_supported(void)
+{
+       int fd, ret = 0;
+       unsigned long arg = 0;
+
+       /* PMU_IOC_CAN_SLEEP is going away, so we only say unsupported
+        * if PMU_IOC_CAN_SLEEP explicitly says we can't */
+       fd = open("/dev/pmu", O_RDWR);
+       if (fd < 0)
+               return 0;
+
+       ret = ioctl(fd, PMU_IOC_CAN_SLEEP, &arg);
+       if (!ret && arg != 1)
+               ret = ENOTSUP;
+
+       close(fd);
+
+       return 0;
+}
+
+int s2ram_do_pmu (void)
+{
+       int fd;
+       int ret = 0;
+       unsigned long arg = 0;
+
+       fd = open("/dev/pmu", O_RDWR);
+       if (fd < 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, 0);
+
+       if (ret)
+               ret = errno;
+
+       close(fd);
+
+       return ret;
+}
+
+
diff -X exclude -uN a/s2ram-ppc.h b/s2ram-ppc.h
--- a/s2ram-ppc.h       1970-01-01 01:00:00.000000000 +0100
+++ b/s2ram-ppc.h       2007-04-15 02:07:18.000000000 +0200
@@ -0,0 +1,2 @@
+/* No additional options for PPC */
+#define S2RAM_PLATFORM_OPTS
diff -X exclude -uN a/s2ram-x86.c b/s2ram-x86.c
--- a/s2ram-x86.c       2007-04-10 21:38:51.000000000 +0200
+++ b/s2ram-x86.c       2007-04-15 02:24:09.000000000 +0200
@@ -329,3 +329,8 @@
        }
 }
 
+int s2ram_do_pmu (void)
+{
+       return ENODEV;
+}
+


Luca
-- 
Se non sei parte della soluzione, allora sei parte del problema.
diff -X exclude -uN a/Makefile b/Makefile
--- a/Makefile	2007-04-10 23:46:38.000000000 +0200
+++ b/Makefile	2007-04-15 02:07:34.000000000 +0200
@@ -14,7 +14,7 @@
 
 ###############################################################
 
-ARCH:=$(shell uname -m)
+ARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/ppc.*/ppc/)
 
 CC_FLAGS=-I/usr/local/include -DS2RAM $(CFLAGS)
 LD_FLAGS=-L/usr/local/lib
@@ -22,11 +22,17 @@
 BINARIES=s2disk s2both s2ram swap-offset resume
 BINARIES_MIN=s2disk swap-offset
 
-S2RAM_OBJ=vt.o vbetool/vbetool.o radeontool.o dmidecode.o
+S2RAM_OBJ=vt.o
 SWSUSP_OBJ=vt.o md5.o encrypt.o config.o loglevel.o splash.o bootsplash.o 
 
-S2RAM_LD_FLAGS = $(LD_FLAGS) -lpci -lz -lx86
+S2RAM_LD_FLAGS = $(LD_FLAGS)
 SWSUSP_LD_FLAGS = $(LD_FLAGS)
+ifeq ($(ARCH), x86)
+	S2RAM_OBJ += s2ram-x86.o dmidecode.o radeontool.o vbetool/vbetool.o
+	S2RAM_LD_FLAGS += -lx86 -lpci -lz
+else ifeq ($(ARCH), ppc)  
+	S2RAM_OBJ += s2ram-ppc.o
+endif
 
 ifndef CONFIG_RESUME_DYN
 STATIC_LD_FLAGS = -static
@@ -81,13 +87,13 @@
 	$(CC) $(CC_FLAGS) -DCONFIG_BOTH -c $< -o $@
 
 s2ram.o: s2ram.c s2ram.h whitelist.c
-	$(CC) $(CC_FLAGS) -include s2ram-x86.h -c $< -o $@
+	$(CC) $(CC_FLAGS) -include s2ram-$(ARCH).h -c $< -o $@
 
 md5.o encrypt.o: %.o : %.c %.h md5.h
 	$(CC) $(CC_FLAGS) -DHAVE_INTTYPES_H -DHAVE_STDINT_H -c $< -o $@
 
 # Simple objects with header
-config.o vt.o bootsplash.o splash.o splashy_funcs.o vbetool/vbetool.o: %.o : %.c %.h
+config.o vt.o bootsplash.o splash.o splashy_funcs.o vbetool/vbetool.o s2ram-ppc.o s2ram-x86.o: %.o : %.c %.h
 	$(CC) $(CC_FLAGS) -c $< -o $@
 
 # Simple object without header
@@ -98,11 +104,11 @@
 s2disk:	$(SWSUSP_OBJ) suspend.c
 	$(CC) -g $(CC_FLAGS)  $^ -o $@ $(SWSUSP_LD_FLAGS)
 
-s2ram:	$(S2RAM_OBJ) s2ram.o s2ram-x86.o
+s2ram:	$(S2RAM_OBJ) s2ram.o
 	$(CC) -g $(CC_FLAGS)  $^ -o $@ $(S2RAM_LD_FLAGS)
 
-s2both:	$(SWSUSP_OBJ) $(S2RAM_OBJ) s2ram-both.o suspend.c s2ram-x86.o
-	$(CC) -g $(CC_FLAGS) -DCONFIG_BOTH -include s2ram-x86.h $^ -o $@ $(SWSUSP_LD_FLAGS) $(S2RAM_LD_FLAGS)
+s2both:	$(SWSUSP_OBJ) $(S2RAM_OBJ) s2ram-both.o suspend.c
+	$(CC) -g $(CC_FLAGS) -DCONFIG_BOTH -include s2ram-$(ARCH).h  $^ -o $@ $(SWSUSP_LD_FLAGS) $(S2RAM_LD_FLAGS)
 
 resume:	resume.c $(SWSUSP_OBJ)
 	$(CC) $(CC_FLAGS) $(STATIC_CC_FLAGS) $^ -o $@ $(STATIC_LD_FLAGS) $(SWSUSP_LD_FLAGS)
diff -X exclude -uN a/s2ram.c b/s2ram.c
--- a/s2ram.c	2007-04-10 21:40:41.000000000 +0200
+++ b/s2ram.c	2007-04-15 02:29:11.000000000 +0200
@@ -24,7 +24,7 @@
 int force;
 int test_mode;
 
-int s2ram_do(void)
+__attribute__((weak)) int s2ram_do(void)
 {
 	int ret = 0;
 	FILE *f = fopen("/sys/power/state", "w");
diff -X exclude -uN a/s2ram-ppc.c b/s2ram-ppc.c
--- a/s2ram-ppc.c	1970-01-01 01:00:00.000000000 +0100
+++ b/s2ram-ppc.c	2007-04-15 02:33:39.000000000 +0200
@@ -0,0 +1,128 @@
+/*
+ * Suspend-to-RAM - PPC code
+ *
+ * Copyright 2006 Tim Dijkstra <[EMAIL PROTECTED]>
+ * Copyright 2006 Luca Tettamanti <[EMAIL PROTECTED]>
+ * Distribute under GPLv2.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <linux/pmu.h>
+
+#include "s2ram.h"
+
+void s2ram_usage_platform(void)
+{
+	/* No additional options for PPC */
+}
+
+void s2ram_add_flag(int opt, const char *arg)
+{
+}
+
+int s2ram_prepare(void)
+{
+	return 0;
+}
+
+void s2ram_resume(void)
+{
+	/* nop */
+}
+
+void identify_machine(void)
+{
+	/* TODO */
+}
+
+int s2ram_hacks(void)
+{
+	return 0;
+}
+
+int s2ram_is_supported(void)
+{
+	int fd, ret = 0;
+	unsigned long arg = 0;
+
+	/* PMU_IOC_CAN_SLEEP is going away, so we only say unsupported
+	 * if PMU_IOC_CAN_SLEEP explicitly says we can't */
+	fd = open("/dev/pmu", O_RDWR);
+	if (fd < 0)
+		return 0;
+
+	ret = ioctl(fd, PMU_IOC_CAN_SLEEP, &arg);
+	if (!ret && arg != 1)
+		ret = ENOTSUP;
+
+	close(fd);
+
+	return 0;
+}
+
+static int s2ram_do_pmu (void)
+{
+	int fd;
+	int ret = 0;
+	unsigned long arg = 0;
+
+	fd = open("/dev/pmu", O_RDWR);
+	if (fd < 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, 0);
+
+	if (ret)
+		ret = errno;
+
+	close(fd);
+
+	return ret;
+}
+
+int s2ram_do(void)
+{
+	int ret;
+	FILE *f;
+
+	/* If this works we're done. Else we just continue as if nothing
+	 * happened, future kernels will work with /s/p/s.
+	 */
+	ret = s2ram_do_pmu();
+	if (!ret)
+		return ret;
+	ret = 0;
+
+	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;
+	}
+
+	if (fprintf(f, "mem") < 0) {
+		ret = errno;
+		perror("s2ram_do");
+	}
+	/* usually only fclose fails, not fprintf, so it does not matter
+	 * that we might overwrite the previous error.
+	 */
+	if (fclose(f) < 0) {
+		ret = errno;
+		perror("s2ram_do");
+	}
+
+	return ret;
+}
diff -X exclude -uN a/s2ram-ppc.h b/s2ram-ppc.h
--- a/s2ram-ppc.h	1970-01-01 01:00:00.000000000 +0100
+++ b/s2ram-ppc.h	2007-04-15 02:07:18.000000000 +0200
@@ -0,0 +1,2 @@
+/* No additional options for PPC */
+#define S2RAM_PLATFORM_OPTS
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Suspend-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to