]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/power/swap.c
Hibernation: Remove unnecessary variable declaration
[linux-2.6-omap-h63xx.git] / kernel / power / swap.c
index 3581f8f86acdc430d4fdd8edb09dfc8d31d2b5c0..ef41440879bade7615653f278f858397ddab9063 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/smp_lock.h>
 #include <linux/file.h>
 #include <linux/utsname.h>
 #include <linux/version.h>
 
 #include "power.h"
 
-extern char resume_file[];
-
 #define SWSUSP_SIG     "S1SUSPEND"
 
-static struct swsusp_header {
-       char reserved[PAGE_SIZE - 20 - sizeof(sector_t)];
+struct swsusp_header {
+       char reserved[PAGE_SIZE - 20 - sizeof(sector_t) - sizeof(int)];
        sector_t image;
+       unsigned int flags;     /* Flags to pass to the "boot" kernel */
        char    orig_sig[10];
        char    sig[10];
-} __attribute__((packed, aligned(PAGE_SIZE))) swsusp_header;
+} __attribute__((packed));
+
+static struct swsusp_header *swsusp_header;
 
 /*
  * General things
@@ -137,18 +137,19 @@ static int wait_on_bio_chain(struct bio **bio_chain)
  * Saving part
  */
 
-static int mark_swapfiles(sector_t start)
+static int mark_swapfiles(sector_t start, unsigned int flags)
 {
        int error;
 
-       bio_read_page(swsusp_resume_block, &swsusp_header, NULL);
-       if (!memcmp("SWAP-SPACE",swsusp_header.sig, 10) ||
-           !memcmp("SWAPSPACE2",swsusp_header.sig, 10)) {
-               memcpy(swsusp_header.orig_sig,swsusp_header.sig, 10);
-               memcpy(swsusp_header.sig,SWSUSP_SIG, 10);
-               swsusp_header.image = start;
+       bio_read_page(swsusp_resume_block, swsusp_header, NULL);
+       if (!memcmp("SWAP-SPACE",swsusp_header->sig, 10) ||
+           !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) {
+               memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10);
+               memcpy(swsusp_header->sig,SWSUSP_SIG, 10);
+               swsusp_header->image = start;
+               swsusp_header->flags = flags;
                error = bio_write_page(swsusp_resume_block,
-                                       &swsusp_header, NULL);
+                                       swsusp_header, NULL);
        } else {
                printk(KERN_ERR "swsusp: Swap header not found!\n");
                error = -ENODEV;
@@ -241,7 +242,6 @@ struct swap_map_page {
 struct swap_map_handle {
        struct swap_map_page *cur;
        sector_t cur_swap;
-       struct bitmap_page *bitmap;
        unsigned int k;
 };
 
@@ -250,9 +250,6 @@ static void release_swap_writer(struct swap_map_handle *handle)
        if (handle->cur)
                free_page((unsigned long)handle->cur);
        handle->cur = NULL;
-       if (handle->bitmap)
-               free_bitmap(handle->bitmap);
-       handle->bitmap = NULL;
 }
 
 static int get_swap_writer(struct swap_map_handle *handle)
@@ -260,12 +257,7 @@ static int get_swap_writer(struct swap_map_handle *handle)
        handle->cur = (struct swap_map_page *)get_zeroed_page(GFP_KERNEL);
        if (!handle->cur)
                return -ENOMEM;
-       handle->bitmap = alloc_bitmap(count_swap_pages(root_swap, 0));
-       if (!handle->bitmap) {
-               release_swap_writer(handle);
-               return -ENOMEM;
-       }
-       handle->cur_swap = alloc_swapdev_block(root_swap, handle->bitmap);
+       handle->cur_swap = alloc_swapdev_block(root_swap);
        if (!handle->cur_swap) {
                release_swap_writer(handle);
                return -ENOSPC;
@@ -282,7 +274,7 @@ static int swap_write_page(struct swap_map_handle *handle, void *buf,
 
        if (!handle->cur)
                return -EINVAL;
-       offset = alloc_swapdev_block(root_swap, handle->bitmap);
+       offset = alloc_swapdev_block(root_swap);
        error = write_page(buf, offset, bio_chain);
        if (error)
                return error;
@@ -291,7 +283,7 @@ static int swap_write_page(struct swap_map_handle *handle, void *buf,
                error = wait_on_bio_chain(bio_chain);
                if (error)
                        goto out;
-               offset = alloc_swapdev_block(root_swap, handle->bitmap);
+               offset = alloc_swapdev_block(root_swap);
                if (!offset)
                        return -ENOSPC;
                handle->cur->next_swap = offset;
@@ -377,6 +369,7 @@ static int enough_swap(unsigned int nr_pages)
 
 /**
  *     swsusp_write - Write entire image and metadata.
+ *     @flags: flags to pass to the "boot" kernel in the image header
  *
  *     It is important _NOT_ to umount filesystems at this point. We want
  *     them synced (in case something goes wrong) but we DO not want to mark
@@ -384,7 +377,7 @@ static int enough_swap(unsigned int nr_pages)
  *     correctly, we'll mark system clean, anyway.)
  */
 
-int swsusp_write(void)
+int swsusp_write(unsigned int flags)
 {
        struct swap_map_handle handle;
        struct snapshot_handle snapshot;
@@ -423,12 +416,13 @@ int swsusp_write(void)
                if (!error) {
                        flush_swap_writer(&handle);
                        printk("S");
-                       error = mark_swapfiles(start);
+                       error = mark_swapfiles(start, flags);
                        printk("|\n");
                }
        }
        if (error)
-               free_all_swap_pages(root_swap, handle.bitmap);
+               free_all_swap_pages(root_swap);
+
        release_swap_writer(&handle);
  out:
        swsusp_close();
@@ -547,13 +541,20 @@ static int load_image(struct swap_map_handle *handle,
        return error;
 }
 
-int swsusp_read(void)
+/**
+ *     swsusp_read - read the hibernation image.
+ *     @flags_p: flags passed by the "frozen" kernel in the image header should
+ *               be written into this memeory location
+ */
+
+int swsusp_read(unsigned int *flags_p)
 {
        int error;
        struct swap_map_handle handle;
        struct snapshot_handle snapshot;
        struct swsusp_info *header;
 
+       *flags_p = swsusp_header->flags;
        if (IS_ERR(resume_bdev)) {
                pr_debug("swsusp: block device not initialised\n");
                return PTR_ERR(resume_bdev);
@@ -564,7 +565,7 @@ int swsusp_read(void)
        if (error < PAGE_SIZE)
                return error < 0 ? error : -EFAULT;
        header = (struct swsusp_info *)data_of(snapshot);
-       error = get_swap_reader(&handle, swsusp_header.image);
+       error = get_swap_reader(&handle, swsusp_header->image);
        if (!error)
                error = swap_read_page(&handle, header, NULL);
        if (!error)
@@ -591,17 +592,17 @@ int swsusp_check(void)
        resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ);
        if (!IS_ERR(resume_bdev)) {
                set_blocksize(resume_bdev, PAGE_SIZE);
-               memset(&swsusp_header, 0, sizeof(swsusp_header));
+               memset(swsusp_header, 0, PAGE_SIZE);
                error = bio_read_page(swsusp_resume_block,
-                                       &swsusp_header, NULL);
+                                       swsusp_header, NULL);
                if (error)
                        return error;
 
-               if (!memcmp(SWSUSP_SIG, swsusp_header.sig, 10)) {
-                       memcpy(swsusp_header.sig, swsusp_header.orig_sig, 10);
+               if (!memcmp(SWSUSP_SIG, swsusp_header->sig, 10)) {
+                       memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10);
                        /* Reset swap signature now */
                        error = bio_write_page(swsusp_resume_block,
-                                               &swsusp_header, NULL);
+                                               swsusp_header, NULL);
                } else {
                        return -EINVAL;
                }
@@ -632,3 +633,13 @@ void swsusp_close(void)
 
        blkdev_put(resume_bdev);
 }
+
+static int swsusp_header_init(void)
+{
+       swsusp_header = (struct swsusp_header*) __get_free_page(GFP_KERNEL);
+       if (!swsusp_header)
+               panic("Could not allocate memory for swsusp_header\n");
+       return 0;
+}
+
+core_initcall(swsusp_header_init);