Il Fri, Apr 20, 2007 at 06:59:11PM +0200, Stefan Seyfried ha scritto: 
> On Wed, Apr 18, 2007 at 09:22:20PM +0200, Tim Dijkstra wrote:
> > Luca Tettamanti <[EMAIL PROTECTED]> wrote:
> > > Well, it's possible to do something like this:
> > > 
> > > int s2ram_default_do(void) {
> > >         use /s/p/s
> > > }
> > > 
> > > __attribute__((weak)) int s2ram_do(void) {
> > >         return s2ram_default_do();
> > > }
> > > 
> > > and then in PPC code:
> > > 
> > > int s2ram_do(void) {
> > >         poke PMU;
> > > 
> > >         return s2ram_default_do();
> > > }
> > 
> > I must confess that I didn't know about these fancy weak-linking stuff,
> > learned something new;) To me it seems a bit overkill, but logically it
> > seems the OK, so be my guest...
> 
> For me, as a not-so-experienced C programmer, it is probably easier to
> understand why there is some ppc-specific code in main(), either #ifdef'd
> directly or simply where i know that this function is defined as NULL in
> the !PPC case.
> 
> But i think i will also learn about this weak linking stuff if i actually
> need to, so i don't care too much which way we go either ;-)

It's quite simple: a weak symbol may be discared by the linker if it
found another copy.

This is the updated patch. You can either use the original 2/2 or this
one:


---

 Makefile    |   22 +++++++----
 s2ram-ppc.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 s2ram-ppc.h |    2 +
 s2ram.c     |    7 +++
 s2ram.h     |    1 
 5 files changed, 131 insertions(+), 9 deletions(-)

diff -X exclude -Nu 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 -Nu a/s2ram.c b/s2ram.c
--- a/s2ram.c   2007-04-10 21:40:41.000000000 +0200
+++ b/s2ram.c   2007-04-24 00:48:21.000000000 +0200
@@ -24,7 +24,12 @@
 int force;
 int test_mode;
 
-int s2ram_do(void)
+__attribute__((weak)) int s2ram_do(void)
+{
+       return s2ram_generic_do();
+}
+
+int s2ram_generic_do(void)
 {
        int ret = 0;
        FILE *f = fopen("/sys/power/state", "w");
diff -X exclude -Nu a/s2ram.h b/s2ram.h
--- a/s2ram.h   2007-04-10 21:39:19.000000000 +0200
+++ b/s2ram.h   2007-04-24 00:48:42.000000000 +0200
@@ -28,6 +28,7 @@
 int s2ram_is_supported(void);
 void identify_machine(void);
 int s2ram_do(void);
+int s2ram_generic_do(void);
 void s2ram_resume(void);
 void s2ram_add_flag(int opt, const char *arg);
 
diff -X exclude -Nu 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-24 00:49:31.000000000 +0200
@@ -0,0 +1,108 @@
+/*
+ * 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;
+
+       /* 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;
+
+       return s2ram_generic_do();
+}
diff -X exclude -Nu 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


Luca
-- 
"Ricorda sempre che sei unico, esattamente come tutti gli altri".

-------------------------------------------------------------------------
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
Suspend-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to