2005-04-16 18:20:36 -04:00
|
|
|
#include <linux/suspend.h>
|
2007-10-25 19:05:05 -04:00
|
|
|
#include <linux/suspend_ioctls.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
#include <linux/utsname.h>
|
2008-01-15 23:17:00 -05:00
|
|
|
#include <linux/freezer.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
struct swsusp_info {
|
|
|
|
struct new_utsname uts;
|
|
|
|
u32 version_code;
|
|
|
|
unsigned long num_physpages;
|
|
|
|
int cpus;
|
|
|
|
unsigned long image_pages;
|
2006-01-06 03:13:05 -05:00
|
|
|
unsigned long pages;
|
2006-03-23 06:00:03 -05:00
|
|
|
unsigned long size;
|
2005-04-16 18:20:36 -04:00
|
|
|
} __attribute__((aligned(PAGE_SIZE)));
|
|
|
|
|
2007-10-18 06:04:52 -04:00
|
|
|
#ifdef CONFIG_HIBERNATION
|
|
|
|
#ifdef CONFIG_ARCH_HIBERNATION_HEADER
|
|
|
|
/* Maximum size of architecture specific data in a hibernation header */
|
|
|
|
#define MAX_ARCH_HEADER_SIZE (sizeof(struct new_utsname) + 4)
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2007-10-18 06:04:52 -04:00
|
|
|
extern int arch_hibernation_header_save(void *addr, unsigned int max_size);
|
|
|
|
extern int arch_hibernation_header_restore(void *addr);
|
|
|
|
|
|
|
|
static inline int init_header_complete(struct swsusp_info *info)
|
|
|
|
{
|
|
|
|
return arch_hibernation_header_save(info, MAX_ARCH_HEADER_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *check_image_kernel(struct swsusp_info *info)
|
|
|
|
{
|
|
|
|
return arch_hibernation_header_restore(info) ?
|
|
|
|
"architecture specific data" : NULL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ARCH_HIBERNATION_HEADER */
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2007-05-06 17:50:52 -04:00
|
|
|
/*
|
|
|
|
* Keep some memory free so that I/O operations can succeed without paging
|
|
|
|
* [Might this be more than 4 MB?]
|
|
|
|
*/
|
|
|
|
#define PAGES_FOR_IO ((4096 * 1024) >> PAGE_SHIFT)
|
2007-10-18 06:04:52 -04:00
|
|
|
|
2007-05-06 17:50:52 -04:00
|
|
|
/*
|
|
|
|
* Keep 1 MB of memory free so that device drivers can allocate some pages in
|
|
|
|
* their .suspend() routines without breaking the suspend to disk.
|
|
|
|
*/
|
|
|
|
#define SPARE_PAGES ((1024 * 1024) >> PAGE_SHIFT)
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2009-06-09 19:27:49 -04:00
|
|
|
/* kernel/power/hibernate.c */
|
2007-07-19 04:47:29 -04:00
|
|
|
extern int hibernation_snapshot(int platform_mode);
|
swsusp: introduce restore platform operations
At least on some machines it is necessary to prepare the ACPI firmware for the
restoration of the system memory state from the hibernation image if the
"platform" mode of hibernation has been used. Namely, in that cases we need
to disable the GPEs before replacing the "boot" kernel with the "frozen"
kernel (cf. http://bugzilla.kernel.org/show_bug.cgi?id=7887). After the
restore they will be re-enabled by hibernation_ops->finish(), but if the
restore fails, they have to be re-enabled by the restore code explicitly.
For this purpose we can introduce two additional hibernation operations,
called pre_restore() and restore_cleanup() and call them from the restore code
path. Still, they should be called if the "platform" mode of hibernation has
been used, so we need to pass the information about the hibernation mode from
the "frozen" kernel to the "boot" kernel in the image header.
Apparently, we can't drop the disabling of GPEs before the restore because of
Bug #7887 . We also can't do it unconditionally, because the GPEs wouldn't
have been enabled after a successful restore if the suspend had been done in
the 'shutdown' or 'reboot' mode.
In principle we could (and probably should) unconditionally disable the GPEs
before each snapshot creation *and* before the restore, but then we'd have to
unconditionally enable them after the snapshot creation as well as after the
restore (or restore failure) Still, for this purpose we'd need to modify
acpi_enter_sleep_state_prep() and acpi_leave_sleep_state() and we'd have to
introduce some mechanism synchronizing the disablind/enabling of the GPEs with
the device drivers' .suspend()/.resume() routines and with
disable_/enable_nonboot_cpus(). However, this would have affected the
suspend (ie. s2ram) code as well as the hibernation, which I'd like to avoid
in this patch series.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 04:47:30 -04:00
|
|
|
extern int hibernation_restore(int platform_mode);
|
2007-07-19 04:47:29 -04:00
|
|
|
extern int hibernation_platform_enter(void);
|
2005-04-16 18:20:36 -04:00
|
|
|
#endif
|
2006-12-06 23:34:35 -05:00
|
|
|
|
2007-05-02 13:27:07 -04:00
|
|
|
extern int pfn_is_nosave(unsigned long);
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
#define power_attr(_name) \
|
2007-11-02 08:47:53 -04:00
|
|
|
static struct kobj_attribute _name##_attr = { \
|
2005-04-16 18:20:36 -04:00
|
|
|
.attr = { \
|
|
|
|
.name = __stringify(_name), \
|
|
|
|
.mode = 0644, \
|
|
|
|
}, \
|
|
|
|
.show = _name##_show, \
|
|
|
|
.store = _name##_store, \
|
|
|
|
}
|
|
|
|
|
2006-02-01 06:05:07 -05:00
|
|
|
/* Preferred image size in bytes (default 500 MB) */
|
|
|
|
extern unsigned long image_size;
|
2006-03-23 05:59:59 -05:00
|
|
|
extern int in_suspend;
|
2006-03-23 06:00:00 -05:00
|
|
|
extern dev_t swsusp_resume_device;
|
2006-12-06 23:34:12 -05:00
|
|
|
extern sector_t swsusp_resume_block;
|
2006-03-23 05:59:59 -05:00
|
|
|
|
2005-10-30 17:59:56 -05:00
|
|
|
extern asmlinkage int swsusp_arch_suspend(void);
|
|
|
|
extern asmlinkage int swsusp_arch_resume(void);
|
|
|
|
|
2007-05-06 17:50:43 -04:00
|
|
|
extern int create_basic_memory_bitmaps(void);
|
|
|
|
extern void free_basic_memory_bitmaps(void);
|
2009-07-08 07:24:05 -04:00
|
|
|
extern int hibernate_preallocate_memory(void);
|
2006-03-23 05:59:59 -05:00
|
|
|
|
2006-09-26 02:32:46 -04:00
|
|
|
/**
|
|
|
|
* Auxiliary structure used for reading the snapshot image data and
|
|
|
|
* metadata from and writing them to the list of page backup entries
|
|
|
|
* (PBEs) which is the main data structure of swsusp.
|
|
|
|
*
|
|
|
|
* Using struct snapshot_handle we can transfer the image, including its
|
|
|
|
* metadata, as a continuous sequence of bytes with the help of
|
|
|
|
* snapshot_read_next() and snapshot_write_next().
|
|
|
|
*
|
|
|
|
* The code that writes the image to a storage or transfers it to
|
|
|
|
* the user land is required to use snapshot_read_next() for this
|
|
|
|
* purpose and it should not make any assumptions regarding the internal
|
|
|
|
* structure of the image. Similarly, the code that reads the image from
|
|
|
|
* a storage or transfers it from the user land is required to use
|
|
|
|
* snapshot_write_next().
|
|
|
|
*
|
|
|
|
* This may allow us to change the internal structure of the image
|
|
|
|
* in the future with considerably less effort.
|
|
|
|
*/
|
|
|
|
|
2006-03-23 05:59:59 -05:00
|
|
|
struct snapshot_handle {
|
2006-09-26 02:32:46 -04:00
|
|
|
unsigned int cur; /* number of the block of PAGE_SIZE bytes the
|
|
|
|
* next operation will refer to (ie. current)
|
|
|
|
*/
|
|
|
|
void *buffer; /* address of the block to read from
|
|
|
|
* or write to
|
|
|
|
*/
|
|
|
|
int sync_read; /* Set to one to notify the caller of
|
|
|
|
* snapshot_write_next() that it may
|
|
|
|
* need to call wait_on_bio_chain()
|
|
|
|
*/
|
2006-03-23 05:59:59 -05:00
|
|
|
};
|
|
|
|
|
2006-09-26 02:32:46 -04:00
|
|
|
/* This macro returns the address from/to which the caller of
|
|
|
|
* snapshot_read_next()/snapshot_write_next() is allowed to
|
|
|
|
* read/write data after the function returns
|
|
|
|
*/
|
2010-05-01 17:52:02 -04:00
|
|
|
#define data_of(handle) ((handle).buffer)
|
2006-03-23 05:59:59 -05:00
|
|
|
|
2006-09-26 02:32:54 -04:00
|
|
|
extern unsigned int snapshot_additional_pages(struct zone *zone);
|
2007-10-25 18:59:31 -04:00
|
|
|
extern unsigned long snapshot_get_image_size(void);
|
2010-05-01 17:52:02 -04:00
|
|
|
extern int snapshot_read_next(struct snapshot_handle *handle);
|
|
|
|
extern int snapshot_write_next(struct snapshot_handle *handle);
|
[PATCH] swsusp: Improve handling of highmem
Currently swsusp saves the contents of highmem pages by copying them to the
normal zone which is quite inefficient (eg. it requires two normal pages
to be used for saving one highmem page). This may be improved by using
highmem for saving the contents of saveable highmem pages.
Namely, during the suspend phase of the suspend-resume cycle we try to
allocate as many free highmem pages as there are saveable highmem pages.
If there are not enough highmem image pages to store the contents of all of
the saveable highmem pages, some of them will be stored in the "normal"
memory. Next, we allocate as many free "normal" pages as needed to store
the (remaining) image data. We use a memory bitmap to mark the allocated
free pages (ie. highmem as well as "normal" image pages).
Now, we use another memory bitmap to mark all of the saveable pages
(highmem as well as "normal") and the contents of the saveable pages are
copied into the image pages. Then, the second bitmap is used to save the
pfns corresponding to the saveable pages and the first one is used to save
their data.
During the resume phase the pfns of the pages that were saveable during the
suspend are loaded from the image and used to mark the "unsafe" page
frames. Next, we try to allocate as many free highmem page frames as to
load all of the image data that had been in the highmem before the suspend
and we allocate so many free "normal" page frames that the total number of
allocated free pages (highmem and "normal") is equal to the size of the
image. While doing this we have to make sure that there will be some extra
free "normal" and "safe" page frames for two lists of PBEs constructed
later.
Now, the image data are loaded, if possible, into their "original" page
frames. The image data that cannot be written into their "original" page
frames are loaded into "safe" page frames and their "original" kernel
virtual addresses, as well as the addresses of the "safe" pages containing
their copies, are stored in one of two lists of PBEs.
One list of PBEs is for the copies of "normal" suspend pages (ie. "normal"
pages that were saveable during the suspend) and it is used in the same way
as previously (ie. by the architecture-dependent parts of swsusp). The
other list of PBEs is for the copies of highmem suspend pages. The pages
in this list are restored (in a reversible way) right before the
arch-dependent code is called.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-12-06 23:34:18 -05:00
|
|
|
extern void snapshot_write_finalize(struct snapshot_handle *handle);
|
2006-09-26 02:32:54 -04:00
|
|
|
extern int snapshot_image_loaded(struct snapshot_handle *handle);
|
2006-03-23 06:00:00 -05:00
|
|
|
|
2007-05-06 17:50:45 -04:00
|
|
|
/* If unset, the snapshot device cannot be open. */
|
|
|
|
extern atomic_t snapshot_device_available;
|
|
|
|
|
2007-05-06 17:50:47 -04:00
|
|
|
extern sector_t alloc_swapdev_block(int swap);
|
|
|
|
extern void free_all_swap_pages(int swap);
|
|
|
|
extern int swsusp_swap_in_use(void);
|
2006-03-23 06:00:00 -05:00
|
|
|
|
swsusp: introduce restore platform operations
At least on some machines it is necessary to prepare the ACPI firmware for the
restoration of the system memory state from the hibernation image if the
"platform" mode of hibernation has been used. Namely, in that cases we need
to disable the GPEs before replacing the "boot" kernel with the "frozen"
kernel (cf. http://bugzilla.kernel.org/show_bug.cgi?id=7887). After the
restore they will be re-enabled by hibernation_ops->finish(), but if the
restore fails, they have to be re-enabled by the restore code explicitly.
For this purpose we can introduce two additional hibernation operations,
called pre_restore() and restore_cleanup() and call them from the restore code
path. Still, they should be called if the "platform" mode of hibernation has
been used, so we need to pass the information about the hibernation mode from
the "frozen" kernel to the "boot" kernel in the image header.
Apparently, we can't drop the disabling of GPEs before the restore because of
Bug #7887 . We also can't do it unconditionally, because the GPEs wouldn't
have been enabled after a successful restore if the suspend had been done in
the 'shutdown' or 'reboot' mode.
In principle we could (and probably should) unconditionally disable the GPEs
before each snapshot creation *and* before the restore, but then we'd have to
unconditionally enable them after the snapshot creation as well as after the
restore (or restore failure) Still, for this purpose we'd need to modify
acpi_enter_sleep_state_prep() and acpi_leave_sleep_state() and we'd have to
introduce some mechanism synchronizing the disablind/enabling of the GPEs with
the device drivers' .suspend()/.resume() routines and with
disable_/enable_nonboot_cpus(). However, this would have affected the
suspend (ie. s2ram) code as well as the hibernation, which I'd like to avoid
in this patch series.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 04:47:30 -04:00
|
|
|
/*
|
|
|
|
* Flags that can be passed from the hibernatig hernel to the "boot" kernel in
|
|
|
|
* the image header.
|
|
|
|
*/
|
|
|
|
#define SF_PLATFORM_MODE 1
|
|
|
|
|
2009-06-09 19:27:49 -04:00
|
|
|
/* kernel/power/hibernate.c */
|
2006-03-23 06:00:01 -05:00
|
|
|
extern int swsusp_check(void);
|
|
|
|
extern void swsusp_free(void);
|
swsusp: introduce restore platform operations
At least on some machines it is necessary to prepare the ACPI firmware for the
restoration of the system memory state from the hibernation image if the
"platform" mode of hibernation has been used. Namely, in that cases we need
to disable the GPEs before replacing the "boot" kernel with the "frozen"
kernel (cf. http://bugzilla.kernel.org/show_bug.cgi?id=7887). After the
restore they will be re-enabled by hibernation_ops->finish(), but if the
restore fails, they have to be re-enabled by the restore code explicitly.
For this purpose we can introduce two additional hibernation operations,
called pre_restore() and restore_cleanup() and call them from the restore code
path. Still, they should be called if the "platform" mode of hibernation has
been used, so we need to pass the information about the hibernation mode from
the "frozen" kernel to the "boot" kernel in the image header.
Apparently, we can't drop the disabling of GPEs before the restore because of
Bug #7887 . We also can't do it unconditionally, because the GPEs wouldn't
have been enabled after a successful restore if the suspend had been done in
the 'shutdown' or 'reboot' mode.
In principle we could (and probably should) unconditionally disable the GPEs
before each snapshot creation *and* before the restore, but then we'd have to
unconditionally enable them after the snapshot creation as well as after the
restore (or restore failure) Still, for this purpose we'd need to modify
acpi_enter_sleep_state_prep() and acpi_leave_sleep_state() and we'd have to
introduce some mechanism synchronizing the disablind/enabling of the GPEs with
the device drivers' .suspend()/.resume() routines and with
disable_/enable_nonboot_cpus(). However, this would have affected the
suspend (ie. s2ram) code as well as the hibernation, which I'd like to avoid
in this patch series.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 04:47:30 -04:00
|
|
|
extern int swsusp_read(unsigned int *flags_p);
|
|
|
|
extern int swsusp_write(unsigned int flags);
|
2007-10-08 13:21:10 -04:00
|
|
|
extern void swsusp_close(fmode_t);
|
2006-12-06 23:34:32 -05:00
|
|
|
|
2010-05-01 17:52:34 -04:00
|
|
|
/* kernel/power/block_io.c */
|
|
|
|
extern struct block_device *hib_resume_bdev;
|
|
|
|
|
|
|
|
extern int hib_bio_read_page(pgoff_t page_off, void *addr,
|
|
|
|
struct bio **bio_chain);
|
|
|
|
extern int hib_bio_write_page(pgoff_t page_off, void *addr,
|
|
|
|
struct bio **bio_chain);
|
|
|
|
extern int hib_wait_on_bio_chain(struct bio **bio_chain);
|
|
|
|
|
2006-12-06 23:34:32 -05:00
|
|
|
struct timeval;
|
2007-07-19 04:47:36 -04:00
|
|
|
/* kernel/power/swsusp.c */
|
2006-12-06 23:34:32 -05:00
|
|
|
extern void swsusp_show_speed(struct timeval *, struct timeval *,
|
|
|
|
unsigned int, char *);
|
2007-07-19 04:47:36 -04:00
|
|
|
|
2007-07-29 17:27:18 -04:00
|
|
|
#ifdef CONFIG_SUSPEND
|
2009-06-09 19:27:12 -04:00
|
|
|
/* kernel/power/suspend.c */
|
|
|
|
extern const char *const pm_states[];
|
|
|
|
|
|
|
|
extern bool valid_state(suspend_state_t state);
|
2007-07-19 04:47:38 -04:00
|
|
|
extern int suspend_devices_and_enter(suspend_state_t state);
|
2009-06-09 19:27:12 -04:00
|
|
|
extern int enter_state(suspend_state_t state);
|
2007-07-29 17:27:18 -04:00
|
|
|
#else /* !CONFIG_SUSPEND */
|
|
|
|
static inline int suspend_devices_and_enter(suspend_state_t state)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2009-06-09 19:27:12 -04:00
|
|
|
static inline int enter_state(suspend_state_t state) { return -ENOSYS; }
|
|
|
|
static inline bool valid_state(suspend_state_t state) { return false; }
|
2007-07-29 17:27:18 -04:00
|
|
|
#endif /* !CONFIG_SUSPEND */
|
|
|
|
|
2009-06-09 19:27:12 -04:00
|
|
|
#ifdef CONFIG_PM_TEST_SUSPEND
|
|
|
|
/* kernel/power/suspend_test.c */
|
|
|
|
extern void suspend_test_start(void);
|
|
|
|
extern void suspend_test_finish(const char *label);
|
|
|
|
#else /* !CONFIG_PM_TEST_SUSPEND */
|
|
|
|
static inline void suspend_test_start(void) {}
|
|
|
|
static inline void suspend_test_finish(const char *label) {}
|
|
|
|
#endif /* !CONFIG_PM_TEST_SUSPEND */
|
|
|
|
|
2007-11-19 17:49:18 -05:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
/* kernel/power/main.c */
|
|
|
|
extern int pm_notifier_call_chain(unsigned long val);
|
|
|
|
#endif
|
2007-11-19 17:36:20 -05:00
|
|
|
|
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
int restore_highmem(void);
|
|
|
|
#else
|
|
|
|
static inline unsigned int count_highmem_pages(void) { return 0; }
|
|
|
|
static inline int restore_highmem(void) { return 0; }
|
|
|
|
#endif
|
Suspend: Testing facility (rev. 2)
Introduce sysfs attribute /sys/power/pm_test allowing one to test the suspend
core code. Namely, writing one of the strings:
freezer
devices
platform
processors
core
to this file causes the suspend code to work in one of the test modes defined as
follows:
freezer
- test the freezing of processes
devices
- test the freezing of processes and suspending of devices
platform
- test the freezing of processes, suspending of devices and platform global
control methods(*)
processors
- test the freezing of processes, suspending of devices, platform global
control methods and the disabling of nonboot CPUs
core
- test the freezing of processes, suspending of devices, platform global
control methods, the disabling of nonboot CPUs and suspending of
platform/system devices
(*) These are ACPI global control methods on ACPI systems
Then, if a suspend is started by normal means, the suspend core will perform
its normal operations up to the point indicated by given test level. Next, it
will wait for 5 seconds and carry out the resume operations needed to transition
the system back to the fully functional state.
Writing "none" to /sys/power/pm_test turns the testing off.
When open for reading, /sys/power/pm_test contains a space-separated list of all
available tests (including "none" that represents the normal functionality) in
which the current test level is indicated by square brackets.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Len Brown <len.brown@intel.com>
2007-11-19 17:41:19 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Suspend test levels
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
/* keep first */
|
|
|
|
TEST_NONE,
|
|
|
|
TEST_CORE,
|
|
|
|
TEST_CPUS,
|
|
|
|
TEST_PLATFORM,
|
|
|
|
TEST_DEVICES,
|
|
|
|
TEST_FREEZER,
|
|
|
|
/* keep last */
|
|
|
|
__TEST_AFTER_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TEST_FIRST TEST_NONE
|
|
|
|
#define TEST_MAX (__TEST_AFTER_LAST - 1)
|
2007-11-19 17:42:31 -05:00
|
|
|
|
|
|
|
extern int pm_test_level;
|
2008-01-15 23:17:00 -05:00
|
|
|
|
|
|
|
#ifdef CONFIG_SUSPEND_FREEZER
|
|
|
|
static inline int suspend_freeze_processes(void)
|
|
|
|
{
|
|
|
|
return freeze_processes();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void suspend_thaw_processes(void)
|
|
|
|
{
|
|
|
|
thaw_processes();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline int suspend_freeze_processes(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void suspend_thaw_processes(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|