diff options
author | Rafael J. Wysocki <rjw@sisk.pl> | 2007-08-15 16:56:06 +0000 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2007-08-15 16:56:06 +0000 |
commit | 28429ab05fb064779a64969e961776260c0bef0b (patch) | |
tree | f5c111e6e92891a3cb4fce249749abe6116fb77e | |
parent | fbbec2e6159d82d077d6cf2f564232cc453bead0 (diff) | |
download | suspend-utils-28429ab05fb064779a64969e961776260c0bef0b.tar.gz |
Patch from Alon Bar-Lev <alon.barlev@gmail.com> to move main() from s2ram.c
into s2ram-main.c, so that s2ram.c can be built once for both s2ram and s2both.
Also, whitelist.c is no longer included into s2ram-x86.c and whitelist.h is
provided for this reason.
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | s2ram-main.c | 97 | ||||
-rw-r--r-- | s2ram-x86.c | 14 | ||||
-rw-r--r-- | s2ram.c | 79 | ||||
-rw-r--r-- | whitelist.c | 10 | ||||
-rw-r--r-- | whitelist.h | 26 |
6 files changed, 129 insertions, 103 deletions
@@ -29,7 +29,7 @@ SWSUSP_OBJ=vt.o md5.o encrypt.o config_parser.o loglevel.o splash.o bootsplash.o 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_OBJ += s2ram-x86.o whitelist.o dmidecode.o radeontool.o vbetool/vbetool.o S2RAM_LD_FLAGS += -lx86 -lpci -lz else ifeq ($(ARCH), ppc) S2RAM_OBJ += s2ram-ppc.o @@ -84,7 +84,7 @@ clean: rm -f $(BINARIES) suspend-keygen suspend.keys *.o vbetool/*.o #### Rules for objects -s2ram-x86.o: %.o : %.c %.h whitelist.c +s2ram-x86.o: %.o : %.c %.h $(CC) $(CC_FLAGS) -c $< -o $@ s2ram-both.o: s2ram.c s2ram.h @@ -105,7 +105,7 @@ dmidecode.o radeontool.o : %.o: %.c s2disk: $(SWSUSP_OBJ) suspend.c $(CC) -g $(CC_FLAGS) $^ -o $@ $(SWSUSP_LD_FLAGS) -s2ram: $(S2RAM_OBJ) s2ram.c +s2ram: $(S2RAM_OBJ) s2ram.c s2ram-main.c $(CC) -g $(CC_FLAGS) -include s2ram-$(ARCH).h $^ -o $@ $(S2RAM_LD_FLAGS) s2both: $(SWSUSP_OBJ) $(S2RAM_OBJ) s2ram-both.o suspend.c diff --git a/s2ram-main.c b/s2ram-main.c new file mode 100644 index 0000000..befbcca --- /dev/null +++ b/s2ram-main.c @@ -0,0 +1,97 @@ +/* + * Suspend-to-RAM + * + * Copyright 2006 Pavel Machek <pavel@suse.cz> + * Distribute under GPLv2. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <getopt.h> +#include <errno.h> +#include <string.h> + +#ifndef S2RAM +#define S2RAM +#endif +#include "vt.h" +#include "s2ram.h" +#include "config_parser.h" + +int main(int argc, char *argv[]) +{ + int i, ret = 0; + int active_console = -1; + struct option options[] = { + { + "help\0\tthis text.", + no_argument, NULL, 'h' + }, + { + "test\0\ttest if the machine is in the database.", + no_argument, NULL, 'n' + }, + { + "identify\0prints a string that identifies the machine.", + no_argument, NULL, 'i' + }, + HACKS_LONG_OPTS + { NULL, 0, NULL, 0 } + }; + const char *optstring = "hni" "fspmrva:"; + + while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) { + switch (i) { + case 'h': + usage("s2ram", options, optstring); + exit(0); + case 'i': + identify_machine(); + exit(0); + case 'n': + ret = machine_known(); + exit(ret); + case '?': + usage("s2ram", options, optstring); + exit(1); + break; + default: + s2ram_add_flag(i,optarg); + break; + } + } + + ret = s2ram_is_supported(); + + if (ret == S2RAM_UNKNOWN) { + printf("Machine is unknown.\n"); + identify_machine(); + goto out; + } + + if (ret == S2RAM_NOFB) + printf("This machine can only suspend without framebuffer.\n"); + + if (ret) + goto out; + + /* 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); + + ret = s2ram_hacks(); + if (ret) + goto out; + ret = s2ram_do(); + s2ram_resume(); + + out: + /* if we switched consoles before suspend, switch back */ + if (active_console > 0) { + printf("switching back to vt%d\n", active_console); + chvt(active_console); + } + + return ret; +} diff --git a/s2ram-x86.c b/s2ram-x86.c index 37d36b3..bfb08b1 100644 --- a/s2ram-x86.c +++ b/s2ram-x86.c @@ -17,6 +17,7 @@ #include "vt.h" #include "s2ram.h" #include "config_parser.h" +#include "whitelist.h" /* From dmidecode.c */ void dmi_scan(void); @@ -36,19 +37,6 @@ char bios_version[1024], sys_vendor[1024], sys_product[1024], sys_version[1024]; #define S2RAM_NOFB 126 #define S2RAM_UNKNOWN 127 -/* flags for the whitelist */ -#define S3_BIOS 0x01 /* machine needs acpi_sleep=s3_bios */ -#define S3_MODE 0x02 /* machine needs acpi_sleep=s3_mode */ -#define VBE_SAVE 0x04 /* machine needs "vbetool save / restore" */ -#define VBE_POST 0x08 /* machine needs "vbetool post" */ -#define RADEON_OFF 0x10 /* machine needs "radeontool light off" */ -#define UNSURE 0x20 /* unverified entries from acpi-support 0.59 */ -#define NOFB 0x40 /* must not use a frame buffer */ -#define VBE_MODE 0x80 /* machine needs "vbetool vbemode get / set" */ -#define PCI_SAVE 0x100 /* we need to save the VGA PCI registers */ - -#include "whitelist.c" - void identify_machine(void) { if (!dmi_scanned) { @@ -42,82 +42,3 @@ int s2ram_generic_do(void) return ret; } -#ifndef CONFIG_BOTH -int main(int argc, char *argv[]) -{ - int i, ret = 0; - int active_console = -1; - struct option options[] = { - { - "help\0\tthis text.", - no_argument, NULL, 'h' - }, - { - "test\0\ttest if the machine is in the database.", - no_argument, NULL, 'n' - }, - { - "identify\0prints a string that identifies the machine.", - no_argument, NULL, 'i' - }, - HACKS_LONG_OPTS - { NULL, 0, NULL, 0 } - }; - const char *optstring = "hni" "fspmrva:"; - - while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) { - switch (i) { - case 'h': - usage("s2ram", options, optstring); - exit(0); - case 'i': - identify_machine(); - exit(0); - case 'n': - ret = machine_known(); - exit(ret); - case '?': - usage("s2ram", options, optstring); - exit(1); - break; - default: - s2ram_add_flag(i,optarg); - break; - } - } - - ret = s2ram_is_supported(); - - if (ret == S2RAM_UNKNOWN) { - printf("Machine is unknown.\n"); - identify_machine(); - goto out; - } - - if (ret == S2RAM_NOFB) - printf("This machine can only suspend without framebuffer.\n"); - - if (ret) - goto out; - - /* 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); - - ret = s2ram_hacks(); - if (ret) - goto out; - ret = s2ram_do(); - s2ram_resume(); - - out: - /* if we switched consoles before suspend, switch back */ - if (active_console > 0) { - printf("switching back to vt%d\n", active_console); - chvt(active_console); - } - - return ret; -} -#endif diff --git a/whitelist.c b/whitelist.c index 45919a1..4e9f18e 100644 --- a/whitelist.c +++ b/whitelist.c @@ -3,14 +3,8 @@ * and all the workarounds */ -struct machine_entry -{ - const char *sys_vendor; - const char *sys_product; - const char *sys_version; - const char *bios_version; - unsigned int flags; -}; +#include <stdlib.h> +#include "whitelist.h" struct machine_entry whitelist[] = { { "IBM", "", "ThinkPad X32", "", RADEON_OFF|S3_BIOS|S3_MODE }, diff --git a/whitelist.h b/whitelist.h new file mode 100644 index 0000000..a249b81 --- /dev/null +++ b/whitelist.h @@ -0,0 +1,26 @@ +/* whitelist.h + * whitelist of machines that are known to work somehow + * and all the workarounds + */ + +/* flags for the whitelist */ +#define S3_BIOS 0x01 /* machine needs acpi_sleep=s3_bios */ +#define S3_MODE 0x02 /* machine needs acpi_sleep=s3_mode */ +#define VBE_SAVE 0x04 /* machine needs "vbetool save / restore" */ +#define VBE_POST 0x08 /* machine needs "vbetool post" */ +#define RADEON_OFF 0x10 /* machine needs "radeontool light off" */ +#define UNSURE 0x20 /* unverified entries from acpi-support 0.59 */ +#define NOFB 0x40 /* must not use a frame buffer */ +#define VBE_MODE 0x80 /* machine needs "vbetool vbemode get / set" */ +#define PCI_SAVE 0x100 /* we need to save the VGA PCI registers */ + +struct machine_entry +{ + const char *sys_vendor; + const char *sys_product; + const char *sys_version; + const char *bios_version; + unsigned int flags; +}; + +extern struct machine_entry whitelist[]; |