diff options
author | Rodolfo García Peñas <kix@kix.es> | 2012-02-27 00:37:24 +0100 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2012-02-27 00:37:24 +0100 |
commit | f63b384ad07396502d0cf54fa5f264a9dccc50ec (patch) | |
tree | 68fd72c777181c8f734e4ceec7e5911804fcc90e | |
parent | 2cbc54ec8f58a7474f86612e1c31c65765c63fdf (diff) | |
download | suspend-utils-f63b384ad07396502d0cf54fa5f264a9dccc50ec.tar.gz |
s2ram: Support quirks from configuration file
This patch permits suspend to RAM using quirks form the configuration
file. Options are:
s2ram_force=y Force the suspend.
s2ram_quirks="quirks_options" Set the quirk options to suspend.
If the quirk is set in the configuration file, then the database is not
used.
To avoid the KMS suspension, needed to read these options from the
configuration file, use the "-k" parameter in s2ram. This parameter
can be used without options in the configuration file, to use the
machines in the database.
Other minor changes, like spaces at the end of the line are included too.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
-rw-r--r-- | dmidecode.c | 2 | ||||
-rw-r--r-- | s2ram-main.c | 46 | ||||
-rw-r--r-- | s2ram-x86.c | 13 | ||||
-rw-r--r-- | s2ram-x86.h | 20 | ||||
-rw-r--r-- | s2ram.c | 85 | ||||
-rw-r--r-- | s2ram.h | 3 | ||||
-rw-r--r-- | whitelist.h | 16 | ||||
-rw-r--r-- | wlcsv2c.pl | 1 |
8 files changed, 144 insertions, 42 deletions
diff --git a/dmidecode.c b/dmidecode.c index 43e317a..a0b793b 100644 --- a/dmidecode.c +++ b/dmidecode.c @@ -18,7 +18,7 @@ #include <string.h> #include <stdlib.h> #include <sys/mman.h> -#include <whitelist.h> +#include <s2ram.h> typedef unsigned char u8; typedef unsigned short u16; diff --git a/s2ram-main.c b/s2ram-main.c index 25389ed..341f38d 100644 --- a/s2ram-main.c +++ b/s2ram-main.c @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) HACKS_LONG_OPTS { NULL, 0, NULL, 0 } }; - const char *optstring = "hVni" "fspmrva:"; + const char *optstring = "hVni" "fspmrva:k"; while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) { switch (i) { @@ -64,30 +64,44 @@ int main(int argc, char *argv[]) ret = machine_known(); exit(ret); default: - s2ram_add_flag(i,optarg); + s2ram_add_flag(i, optarg); break; } } - ret = s2ram_check_kms(); - if (!ret) { - printf("KMS graphics driver is in use, skipping quirks.\n"); - return s2ram_generic_do(); + /* Check if the KMS support is disabled by user */ + if (!no_kms_flag) { + /* KMS */ + ret = s2ram_check_kms(); + if (!ret) { + printf("KMS graphics driver is in use, skipping quirks.\n"); + return s2ram_generic_do(); + } + } else { + printf("KMS disabled by user.\n"); } - ret = s2ram_is_supported(); + /* Test if s2ram will use quirks from the configuration file */ + ret = get_s2ram_config(); - if (ret == S2RAM_UNKNOWN) { - printf("Machine is unknown.\n"); - identify_machine(); - goto out; - } + if (ret) { + /* No configuration file, using quirks form database */ + ret = s2ram_is_supported(); - if (ret == S2RAM_NOFB) - printf("This machine can only suspend without framebuffer.\n"); + if (ret == S2RAM_UNKNOWN) { + printf("Machine is unknown.\n"); + identify_machine(); + goto out; + } - if (ret) - goto out; + if (ret == S2RAM_NOFB) + printf("This machine can only suspend without framebuffer.\n"); + + if (ret) + goto out; + } else { + printf("Using quirks from the configuration file.\n"); + } /* switch to console 1 first, since we might be in X */ active_console = fgconsole(); diff --git a/s2ram-x86.c b/s2ram-x86.c index 5a5c5a6..a091af5 100644 --- a/s2ram-x86.c +++ b/s2ram-x86.c @@ -30,10 +30,7 @@ static void *vbe_buffer; static unsigned char vga_pci_state[256]; static struct pci_dev vga_dev; static struct pci_access *pacc; -/* Flags set from whitelist */ -static int flags, vbe_mode = -1, dmi_scanned; -static int force; -static int fb_nosuspend; +static int vbe_mode = -1, dmi_scanned; /* return codes for s2ram_is_supported */ #define S2RAM_OK 0 @@ -306,7 +303,7 @@ int s2ram_is_supported(void) id = machine_match(); ret = s2ram_check(id); - } + } return ret; } @@ -315,7 +312,7 @@ int s2ram_is_supported(void) int s2ram_do(void) { return s2ram_generic_do(); -} +} void s2ram_resume(void) { @@ -386,5 +383,9 @@ void s2ram_add_flag(int opt, const char *opt_arg) case 8: fb_nosuspend = 1; break; + case 9: + case 'k': + no_kms_flag = 1; + break; } } diff --git a/s2ram-x86.h b/s2ram-x86.h index 0bc5171..7149100 100644 --- a/s2ram-x86.h +++ b/s2ram-x86.h @@ -5,6 +5,22 @@ * * Distribute under GPLv2. */ +#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 */ + +/* Item size */ +#define ITEMSZ 1024 + +char bios_version[ITEMSZ], sys_vendor[ITEMSZ], sys_product[ITEMSZ], sys_version[ITEMSZ]; + +int flags, force, fb_nosuspend, no_kms_flag; #define HACKS_LONG_OPTS \ {\ @@ -38,4 +54,8 @@ {\ "acpi_sleep\0set the acpi_sleep parameter before suspend\n\t\t\t1=s3_bios, 2=s3_mode, 3=both",\ required_argument, NULL, 7 \ + },\ + {\ + "no_kms\0\tdo not set KMS (Kernel Mode Set).",\ + required_argument, NULL, 9 \ }, @@ -2,15 +2,17 @@ * Suspend-to-RAM * * Copyright 2006 Pavel Machek <pavel@suse.cz> + * Copyright 2011 Rodolfo García Peñas (kix) <kix@kix.es> * Distribute under GPLv2. */ +#include <ctype.h> #include "config.h" +#include <sys/stat.h> #include <sys/types.h> #include <dirent.h> #include <stdio.h> #include <stdlib.h> -#include <getopt.h> #include <errno.h> #include <string.h> @@ -21,6 +23,29 @@ #include "s2ram.h" #include "config_parser.h" +static char s2ram_force; +static char s2ram_quirks[MAX_STR_LEN]; + +static struct config_par s2ram_parameters[] = { + { + .name = "s2ram_force", + .fmt = "%c", + .ptr = &s2ram_force, + }, + { + .name = "s2ram_quirks", + .fmt = "%s", + .ptr = s2ram_quirks, + .len = MAX_STR_LEN + }, + { + .name = NULL, + .fmt = NULL, + .ptr = NULL, + .len = 0, + } +}; + int s2ram_check_kms(void) { @@ -66,4 +91,60 @@ int s2ram_generic_do(void) perror("s2ram_do"); } return ret; -} +} + +/* Parse the configuration file */ +int get_s2ram_config(void) +{ + int error; + char *conf_name = CONFIG_FILE; + struct stat stat_buf; + char *ret_name = NULL; + + if (stat(conf_name, &stat_buf)) { + fprintf(stderr, "%s: Could not stat configuration file\n", conf_name); + return -ENOENT; + } else { + error = parse(ret_name, conf_name, s2ram_parameters); + if (error) { + fprintf(stderr, "%s: Could not parse config file\n", ret_name); + return error; + } + if (s2ram_force == 'y') { + force = 1; + + if (strlen(s2ram_quirks) != 0) { + printf("Using s2ram_quirks %s\n", s2ram_quirks); + s2ram_add_quirks(s2ram_quirks); + } + return 0; + } + return -1; + } +} + +void s2ram_add_quirks(char *s2ram_quirks) +{ + int i; + + /* Move to lowercase */ + for (i=0; s2ram_quirks[i]; i++) + s2ram_quirks[i] = tolower(s2ram_quirks[i]); + + if (strstr(s2ram_quirks, "vbe_post") != NULL) + flags |= VBE_POST; + if (strstr(s2ram_quirks, "vbe_save") != NULL) + flags |= VBE_POST; + if (strstr(s2ram_quirks, "vbe_mode") != NULL) + flags |= VBE_MODE; + if (strstr(s2ram_quirks, "radeon_off") != NULL) + flags |= RADEON_OFF; + if (strstr(s2ram_quirks, "pci_save") != NULL) + flags |= PCI_SAVE; + if (strstr(s2ram_quirks, "s3_bios") != NULL) + flags |= S3_BIOS; + if (strstr(s2ram_quirks, "s3_mode") != NULL) + flags |= S3_MODE; + if (strstr(s2ram_quirks, "fb_nosuspend") != NULL) + fb_nosuspend = 1; +} @@ -32,4 +32,5 @@ int s2ram_check_kms(void); int s2ram_generic_do(void); void s2ram_resume(void); void s2ram_add_flag(int opt, const char *arg); - +void s2ram_add_quirks(char*); +int get_s2ram_config(void); diff --git a/whitelist.h b/whitelist.h index fc26a40..090920b 100644 --- a/whitelist.h +++ b/whitelist.h @@ -3,20 +3,6 @@ * and all the workarounds */ -/* Item size */ -#define ITEMSZ 1024 - -/* 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; @@ -26,7 +12,5 @@ struct machine_entry unsigned int flags; }; -char bios_version[ITEMSZ], sys_vendor[ITEMSZ], sys_product[ITEMSZ], sys_version[ITEMSZ]; - extern char *whitelist_version; extern struct machine_entry whitelist[]; @@ -63,6 +63,7 @@ sub print_c_header printf OUF "\#include \"config.h\"\n"; printf OUF "\#include \<stdlib.h\>\n"; printf OUF "\#include \"whitelist.h\"\n"; + printf OUF "\#include \"s2ram.h\"\n"; printf OUF "\n"; printf OUF "char *whitelist_version = \"\$Id: whitelist.c ver. "; |