2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* linux/kernel/power/swsusp.c
|
|
|
|
*
|
2005-10-30 22:59:58 +00:00
|
|
|
* This file provides code to write suspend image to swap and read it back.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 1998-2001 Gabor Kuti <seasons@fornax.hu>
|
2005-10-30 22:59:56 +00:00
|
|
|
* Copyright (C) 1998,2001-2005 Pavel Machek <pavel@suse.cz>
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* This file is released under the GPLv2.
|
|
|
|
*
|
|
|
|
* I'd like to thank the following people for their work:
|
2005-06-25 21:55:12 +00:00
|
|
|
*
|
2005-04-16 22:20:36 +00:00
|
|
|
* Pavel Machek <pavel@ucw.cz>:
|
|
|
|
* Modifications, defectiveness pointing, being with me at the very beginning,
|
|
|
|
* suspend to swap space, stop all tasks. Port to 2.4.18-ac and 2.5.17.
|
|
|
|
*
|
2005-06-25 21:55:12 +00:00
|
|
|
* Steve Doddi <dirk@loth.demon.co.uk>:
|
2005-04-16 22:20:36 +00:00
|
|
|
* Support the possibility of hardware state restoring.
|
|
|
|
*
|
|
|
|
* Raph <grey.havens@earthling.net>:
|
|
|
|
* Support for preserving states of network devices and virtual console
|
|
|
|
* (including X and svgatextmode)
|
|
|
|
*
|
|
|
|
* Kurt Garloff <garloff@suse.de>:
|
|
|
|
* Straightened the critical function in order to prevent compilers from
|
|
|
|
* playing tricks with local variables.
|
|
|
|
*
|
|
|
|
* Andreas Mohr <a.mohr@mailto.de>
|
|
|
|
*
|
|
|
|
* Alex Badea <vampire@go.ro>:
|
|
|
|
* Fixed runaway init
|
|
|
|
*
|
2006-01-06 08:13:05 +00:00
|
|
|
* Rafael J. Wysocki <rjw@sisk.pl>
|
2006-03-23 11:00:00 +00:00
|
|
|
* Reworked the freeing of memory and the handling of swap
|
2006-01-06 08:13:05 +00:00
|
|
|
*
|
2005-04-16 22:20:36 +00:00
|
|
|
* More state savers are welcome. Especially for the scsi layer...
|
|
|
|
*
|
|
|
|
* For TODOs,FIXMEs also look in Documentation/power/swsusp.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/suspend.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/swapops.h>
|
|
|
|
#include <linux/bootmem.h>
|
|
|
|
#include <linux/syscalls.h>
|
|
|
|
#include <linux/highmem.h>
|
2006-12-07 04:34:32 +00:00
|
|
|
#include <linux/time.h>
|
2007-05-06 21:50:47 +00:00
|
|
|
#include <linux/rbtree.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "power.h"
|
|
|
|
|
2006-01-06 08:15:56 +00:00
|
|
|
/*
|
2006-02-01 11:05:07 +00:00
|
|
|
* Preferred image size in bytes (tunable via /sys/power/image_size).
|
2006-01-06 08:15:56 +00:00
|
|
|
* When it is set to N, swsusp will do its best to ensure the image
|
2006-02-01 11:05:07 +00:00
|
|
|
* size will not exceed N bytes, but if that is impossible, it will
|
2006-01-06 08:15:56 +00:00
|
|
|
* try to create the smallest image possible.
|
|
|
|
*/
|
2006-02-01 11:05:07 +00:00
|
|
|
unsigned long image_size = 500 * 1024 * 1024;
|
2006-01-06 08:15:56 +00:00
|
|
|
|
2006-03-23 10:59:59 +00:00
|
|
|
int in_suspend __nosavedata = 0;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/**
|
2006-03-23 10:59:59 +00:00
|
|
|
* The following functions are used for tracing the allocated
|
|
|
|
* swap pages, so that they can be freed in case of an error.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2006-01-06 08:13:05 +00:00
|
|
|
|
2007-05-06 21:50:47 +00:00
|
|
|
struct swsusp_extent {
|
|
|
|
struct rb_node node;
|
|
|
|
unsigned long start;
|
|
|
|
unsigned long end;
|
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-06 21:50:47 +00:00
|
|
|
static struct rb_root swsusp_extents = RB_ROOT;
|
2006-01-06 08:13:05 +00:00
|
|
|
|
2007-05-06 21:50:47 +00:00
|
|
|
static int swsusp_extents_insert(unsigned long swap_offset)
|
2006-01-06 08:13:05 +00:00
|
|
|
{
|
2007-05-06 21:50:47 +00:00
|
|
|
struct rb_node **new = &(swsusp_extents.rb_node);
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct swsusp_extent *ext;
|
|
|
|
|
|
|
|
/* Figure out where to put the new node */
|
|
|
|
while (*new) {
|
|
|
|
ext = container_of(*new, struct swsusp_extent, node);
|
|
|
|
parent = *new;
|
|
|
|
if (swap_offset < ext->start) {
|
|
|
|
/* Try to merge */
|
|
|
|
if (swap_offset == ext->start - 1) {
|
|
|
|
ext->start--;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
new = &((*new)->rb_left);
|
|
|
|
} else if (swap_offset > ext->end) {
|
|
|
|
/* Try to merge */
|
|
|
|
if (swap_offset == ext->end + 1) {
|
|
|
|
ext->end++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
new = &((*new)->rb_right);
|
|
|
|
} else {
|
|
|
|
/* It already is in the tree */
|
|
|
|
return -EINVAL;
|
2006-01-06 08:13:05 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-05-06 21:50:47 +00:00
|
|
|
/* Add the new node and rebalance the tree. */
|
|
|
|
ext = kzalloc(sizeof(struct swsusp_extent), GFP_KERNEL);
|
|
|
|
if (!ext)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ext->start = swap_offset;
|
|
|
|
ext->end = swap_offset;
|
|
|
|
rb_link_node(&ext->node, parent, new);
|
|
|
|
rb_insert_color(&ext->node, &swsusp_extents);
|
2006-03-23 10:59:59 +00:00
|
|
|
return 0;
|
2006-01-06 08:13:05 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-06 21:50:47 +00:00
|
|
|
/**
|
|
|
|
* alloc_swapdev_block - allocate a swap page and register that it has
|
|
|
|
* been allocated, so that it can be freed in case of an error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sector_t alloc_swapdev_block(int swap)
|
2006-01-06 08:13:05 +00:00
|
|
|
{
|
2006-03-23 10:59:59 +00:00
|
|
|
unsigned long offset;
|
|
|
|
|
|
|
|
offset = swp_offset(get_swap_page_of_type(swap));
|
|
|
|
if (offset) {
|
2007-05-06 21:50:47 +00:00
|
|
|
if (swsusp_extents_insert(offset))
|
2006-03-23 10:59:59 +00:00
|
|
|
swap_free(swp_entry(swap, offset));
|
2006-12-07 04:34:10 +00:00
|
|
|
else
|
|
|
|
return swapdev_block(swap, offset);
|
2006-01-06 08:13:05 +00:00
|
|
|
}
|
2006-12-07 04:34:10 +00:00
|
|
|
return 0;
|
2006-01-06 08:13:05 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-06 21:50:47 +00:00
|
|
|
/**
|
|
|
|
* free_all_swap_pages - free swap pages allocated for saving image data.
|
|
|
|
* It also frees the extents used to register which swap entres had been
|
|
|
|
* allocated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void free_all_swap_pages(int swap)
|
2006-01-06 08:13:05 +00:00
|
|
|
{
|
2007-05-06 21:50:47 +00:00
|
|
|
struct rb_node *node;
|
|
|
|
|
|
|
|
while ((node = swsusp_extents.rb_node)) {
|
|
|
|
struct swsusp_extent *ext;
|
|
|
|
unsigned long offset;
|
|
|
|
|
|
|
|
ext = container_of(node, struct swsusp_extent, node);
|
|
|
|
rb_erase(node, &swsusp_extents);
|
|
|
|
for (offset = ext->start; offset <= ext->end; offset++)
|
|
|
|
swap_free(swp_entry(swap, offset));
|
|
|
|
|
|
|
|
kfree(ext);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-01-06 08:13:05 +00:00
|
|
|
}
|
|
|
|
|
2007-05-06 21:50:47 +00:00
|
|
|
int swsusp_swap_in_use(void)
|
|
|
|
{
|
|
|
|
return (swsusp_extents.rb_node != NULL);
|
|
|
|
}
|
|
|
|
|
2006-12-07 04:34:32 +00:00
|
|
|
/**
|
|
|
|
* swsusp_show_speed - print the time elapsed between two events represented by
|
|
|
|
* @start and @stop
|
|
|
|
*
|
|
|
|
* @nr_pages - number of pages processed between @start and @stop
|
|
|
|
* @msg - introductory message to print
|
|
|
|
*/
|
|
|
|
|
|
|
|
void swsusp_show_speed(struct timeval *start, struct timeval *stop,
|
|
|
|
unsigned nr_pages, char *msg)
|
|
|
|
{
|
|
|
|
s64 elapsed_centisecs64;
|
|
|
|
int centisecs;
|
|
|
|
int k;
|
|
|
|
int kps;
|
|
|
|
|
|
|
|
elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
|
|
|
|
do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
|
|
|
|
centisecs = elapsed_centisecs64;
|
|
|
|
if (centisecs == 0)
|
|
|
|
centisecs = 1; /* avoid div-by-zero */
|
|
|
|
k = nr_pages * (PAGE_SIZE / 1024);
|
|
|
|
kps = (k * 100) / centisecs;
|
2007-12-08 01:09:43 +00:00
|
|
|
printk(KERN_INFO "PM: %s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n",
|
|
|
|
msg, k,
|
2006-12-07 04:34:32 +00:00
|
|
|
centisecs / 100, centisecs % 100,
|
|
|
|
kps / 1000, (kps % 1000) / 10);
|
|
|
|
}
|
|
|
|
|
2006-01-06 08:13:46 +00:00
|
|
|
/**
|
|
|
|
* swsusp_shrink_memory - Try to free as much memory as needed
|
|
|
|
*
|
|
|
|
* ... but do not OOM-kill anyone
|
|
|
|
*
|
|
|
|
* Notice: all userland should be stopped before it is called, or
|
|
|
|
* livelock is possible.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SHRINK_BITE 10000
|
2006-06-23 09:03:18 +00:00
|
|
|
static inline unsigned long __shrink_memory(long tmp)
|
|
|
|
{
|
|
|
|
if (tmp > SHRINK_BITE)
|
|
|
|
tmp = SHRINK_BITE;
|
|
|
|
return shrink_all_memory(tmp);
|
|
|
|
}
|
2006-01-06 08:13:46 +00:00
|
|
|
|
|
|
|
int swsusp_shrink_memory(void)
|
|
|
|
{
|
[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-07 04:34:18 +00:00
|
|
|
long tmp;
|
2006-01-06 08:13:46 +00:00
|
|
|
struct zone *zone;
|
|
|
|
unsigned long pages = 0;
|
|
|
|
unsigned int i = 0;
|
|
|
|
char *p = "-\\|/";
|
2006-12-07 04:34:32 +00:00
|
|
|
struct timeval start, stop;
|
2006-01-06 08:13:46 +00:00
|
|
|
|
2007-12-08 01:09:43 +00:00
|
|
|
printk(KERN_INFO "PM: Shrinking memory... ");
|
2006-12-07 04:34:32 +00:00
|
|
|
do_gettimeofday(&start);
|
2006-01-06 08:13:46 +00:00
|
|
|
do {
|
[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-07 04:34:18 +00:00
|
|
|
long size, highmem_size;
|
|
|
|
|
|
|
|
highmem_size = count_highmem_pages();
|
2007-05-06 21:50:52 +00:00
|
|
|
size = count_data_pages() + PAGES_FOR_IO + SPARE_PAGES;
|
2006-01-06 08:15:22 +00:00
|
|
|
tmp = size;
|
[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-07 04:34:18 +00:00
|
|
|
size += highmem_size;
|
2009-03-31 22:19:31 +00:00
|
|
|
for_each_populated_zone(zone) {
|
|
|
|
tmp += snapshot_additional_pages(zone);
|
|
|
|
if (is_highmem(zone)) {
|
|
|
|
highmem_size -=
|
2007-02-10 09:43:02 +00:00
|
|
|
zone_page_state(zone, NR_FREE_PAGES);
|
2009-03-31 22:19:31 +00:00
|
|
|
} else {
|
|
|
|
tmp -= zone_page_state(zone, NR_FREE_PAGES);
|
|
|
|
tmp += zone->lowmem_reserve[ZONE_NORMAL];
|
2006-06-23 09:04:46 +00:00
|
|
|
}
|
2009-03-31 22:19:31 +00:00
|
|
|
}
|
[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-07 04:34:18 +00:00
|
|
|
|
|
|
|
if (highmem_size < 0)
|
|
|
|
highmem_size = 0;
|
|
|
|
|
|
|
|
tmp += highmem_size;
|
2006-01-06 08:13:46 +00:00
|
|
|
if (tmp > 0) {
|
2006-06-23 09:03:18 +00:00
|
|
|
tmp = __shrink_memory(tmp);
|
2006-01-06 08:13:46 +00:00
|
|
|
if (!tmp)
|
|
|
|
return -ENOMEM;
|
|
|
|
pages += tmp;
|
2006-02-01 11:05:07 +00:00
|
|
|
} else if (size > image_size / PAGE_SIZE) {
|
2006-06-23 09:03:18 +00:00
|
|
|
tmp = __shrink_memory(size - (image_size / PAGE_SIZE));
|
2006-01-06 08:15:22 +00:00
|
|
|
pages += tmp;
|
2006-01-06 08:13:46 +00:00
|
|
|
}
|
|
|
|
printk("\b%c", p[i++%4]);
|
|
|
|
} while (tmp > 0);
|
2006-12-07 04:34:32 +00:00
|
|
|
do_gettimeofday(&stop);
|
2006-01-06 08:13:46 +00:00
|
|
|
printk("\bdone (%lu pages freed)\n", pages);
|
2006-12-07 04:34:32 +00:00
|
|
|
swsusp_show_speed(&start, &stop, pages, "Freed");
|
2006-01-06 08:13:46 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-10-26 19:52:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Platforms, like ACPI, may want us to save some memory used by them during
|
|
|
|
* hibernation and to restore the contents of this memory during the subsequent
|
|
|
|
* resume. The code below implements a mechanism allowing us to do that.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct nvs_page {
|
|
|
|
unsigned long phys_start;
|
|
|
|
unsigned int size;
|
|
|
|
void *kaddr;
|
|
|
|
void *data;
|
|
|
|
struct list_head node;
|
|
|
|
};
|
|
|
|
|
|
|
|
static LIST_HEAD(nvs_list);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hibernate_nvs_register - register platform NVS memory region to save
|
|
|
|
* @start - physical address of the region
|
|
|
|
* @size - size of the region
|
|
|
|
*
|
|
|
|
* The NVS region need not be page-aligned (both ends) and we arrange
|
|
|
|
* things so that the data from page-aligned addresses in this region will
|
|
|
|
* be copied into separate RAM pages.
|
|
|
|
*/
|
|
|
|
int hibernate_nvs_register(unsigned long start, unsigned long size)
|
|
|
|
{
|
|
|
|
struct nvs_page *entry, *next;
|
|
|
|
|
|
|
|
while (size > 0) {
|
|
|
|
unsigned int nr_bytes;
|
|
|
|
|
|
|
|
entry = kzalloc(sizeof(struct nvs_page), GFP_KERNEL);
|
|
|
|
if (!entry)
|
|
|
|
goto Error;
|
|
|
|
|
|
|
|
list_add_tail(&entry->node, &nvs_list);
|
|
|
|
entry->phys_start = start;
|
|
|
|
nr_bytes = PAGE_SIZE - (start & ~PAGE_MASK);
|
|
|
|
entry->size = (size < nr_bytes) ? size : nr_bytes;
|
|
|
|
|
|
|
|
start += entry->size;
|
|
|
|
size -= entry->size;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
Error:
|
|
|
|
list_for_each_entry_safe(entry, next, &nvs_list, node) {
|
|
|
|
list_del(&entry->node);
|
|
|
|
kfree(entry);
|
|
|
|
}
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hibernate_nvs_free - free data pages allocated for saving NVS regions
|
|
|
|
*/
|
|
|
|
void hibernate_nvs_free(void)
|
|
|
|
{
|
|
|
|
struct nvs_page *entry;
|
|
|
|
|
|
|
|
list_for_each_entry(entry, &nvs_list, node)
|
|
|
|
if (entry->data) {
|
|
|
|
free_page((unsigned long)entry->data);
|
|
|
|
entry->data = NULL;
|
|
|
|
if (entry->kaddr) {
|
|
|
|
iounmap(entry->kaddr);
|
|
|
|
entry->kaddr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hibernate_nvs_alloc - allocate memory necessary for saving NVS regions
|
|
|
|
*/
|
|
|
|
int hibernate_nvs_alloc(void)
|
|
|
|
{
|
|
|
|
struct nvs_page *entry;
|
|
|
|
|
|
|
|
list_for_each_entry(entry, &nvs_list, node) {
|
|
|
|
entry->data = (void *)__get_free_page(GFP_KERNEL);
|
|
|
|
if (!entry->data) {
|
|
|
|
hibernate_nvs_free();
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hibernate_nvs_save - save NVS memory regions
|
|
|
|
*/
|
|
|
|
void hibernate_nvs_save(void)
|
|
|
|
{
|
|
|
|
struct nvs_page *entry;
|
|
|
|
|
|
|
|
printk(KERN_INFO "PM: Saving platform NVS memory\n");
|
|
|
|
|
|
|
|
list_for_each_entry(entry, &nvs_list, node)
|
|
|
|
if (entry->data) {
|
|
|
|
entry->kaddr = ioremap(entry->phys_start, entry->size);
|
|
|
|
memcpy(entry->data, entry->kaddr, entry->size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hibernate_nvs_restore - restore NVS memory regions
|
|
|
|
*
|
|
|
|
* This function is going to be called with interrupts disabled, so it
|
|
|
|
* cannot iounmap the virtual addresses used to access the NVS region.
|
|
|
|
*/
|
|
|
|
void hibernate_nvs_restore(void)
|
|
|
|
{
|
|
|
|
struct nvs_page *entry;
|
|
|
|
|
|
|
|
printk(KERN_INFO "PM: Restoring platform NVS memory\n");
|
|
|
|
|
|
|
|
list_for_each_entry(entry, &nvs_list, node)
|
|
|
|
if (entry->data)
|
|
|
|
memcpy(entry->kaddr, entry->data, entry->size);
|
|
|
|
}
|