]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/power/snapshot.c
Hibernation: Update messages
[linux-2.6-omap-h63xx.git] / kernel / power / snapshot.c
index 48383ea7229095c2b3a1c6791e87219336ee85b7..f6a5df934f8d40848fb5ac8487b81560e29742c9 100644 (file)
@@ -607,7 +607,8 @@ static LIST_HEAD(nosave_regions);
  */
 
 void __init
-register_nosave_region(unsigned long start_pfn, unsigned long end_pfn)
+__register_nosave_region(unsigned long start_pfn, unsigned long end_pfn,
+                        int use_kmalloc)
 {
        struct nosave_region *region;
 
@@ -623,13 +624,18 @@ register_nosave_region(unsigned long start_pfn, unsigned long end_pfn)
                        goto Report;
                }
        }
-       /* This allocation cannot fail */
-       region = alloc_bootmem_low(sizeof(struct nosave_region));
+       if (use_kmalloc) {
+               /* during init, this shouldn't fail */
+               region = kmalloc(sizeof(struct nosave_region), GFP_KERNEL);
+               BUG_ON(!region);
+       } else
+               /* This allocation cannot fail */
+               region = alloc_bootmem_low(sizeof(struct nosave_region));
        region->start_pfn = start_pfn;
        region->end_pfn = end_pfn;
        list_add_tail(&region->list, &nosave_regions);
  Report:
-       printk("swsusp: Registered nosave memory region: %016lx - %016lx\n",
+       printk(KERN_INFO "PM: Registered nosave memory: %016lx - %016lx\n",
                start_pfn << PAGE_SHIFT, end_pfn << PAGE_SHIFT);
 }
 
@@ -698,12 +704,13 @@ static void mark_nosave_pages(struct memory_bitmap *bm)
        list_for_each_entry(region, &nosave_regions, list) {
                unsigned long pfn;
 
-               printk("swsusp: Marking nosave pages: %016lx - %016lx\n",
+               pr_debug("PM: Marking nosave pages: %016lx - %016lx\n",
                                region->start_pfn << PAGE_SHIFT,
                                region->end_pfn << PAGE_SHIFT);
 
                for (pfn = region->start_pfn; pfn < region->end_pfn; pfn++)
-                       memory_bm_set_bit(bm, pfn);
+                       if (pfn_valid(pfn))
+                               memory_bm_set_bit(bm, pfn);
        }
 }
 
@@ -742,7 +749,7 @@ int create_basic_memory_bitmaps(void)
        free_pages_map = bm2;
        mark_nosave_pages(forbidden_pages_map);
 
-       printk("swsusp: Basic memory bitmaps created\n");
+       pr_debug("PM: Basic memory bitmaps created\n");
 
        return 0;
 
@@ -777,7 +784,7 @@ void free_basic_memory_bitmaps(void)
        memory_bm_free(bm2, PG_UNSAFE_CLEAR);
        kfree(bm2);
 
-       printk("swsusp: Basic memory bitmaps freed\n");
+       pr_debug("PM: Basic memory bitmaps freed\n");
 }
 
 /**
@@ -865,7 +872,6 @@ unsigned int count_highmem_pages(void)
 }
 #else
 static inline void *saveable_highmem_page(unsigned long pfn) { return NULL; }
-static inline unsigned int count_highmem_pages(void) { return 0; }
 #endif /* CONFIG_HIGHMEM */
 
 /**
@@ -998,11 +1004,12 @@ copy_data_pages(struct memory_bitmap *copy_bm, struct memory_bitmap *orig_bm)
        }
        memory_bm_position_reset(orig_bm);
        memory_bm_position_reset(copy_bm);
-       do {
+       for(;;) {
                pfn = memory_bm_next_pfn(orig_bm);
-               if (likely(pfn != BM_END_OF_MAP))
-                       copy_data_page(memory_bm_next_pfn(copy_bm), pfn);
-       } while (pfn != BM_END_OF_MAP);
+               if (unlikely(pfn == BM_END_OF_MAP))
+                       break;
+               copy_data_page(memory_bm_next_pfn(copy_bm), pfn);
+       }
 }
 
 /* Total number of image pages */
@@ -1081,7 +1088,7 @@ static int enough_free_mem(unsigned int nr_pages, unsigned int nr_highmem)
        }
 
        nr_pages += count_pages_for_highmem(nr_highmem);
-       pr_debug("swsusp: Normal pages needed: %u + %u + %u, available pages: %u\n",
+       pr_debug("PM: Normal pages needed: %u + %u + %u, available pages: %u\n",
                nr_pages, PAGES_FOR_IO, meta, free);
 
        return free > nr_pages + PAGES_FOR_IO + meta;
@@ -1194,20 +1201,20 @@ asmlinkage int swsusp_save(void)
 {
        unsigned int nr_pages, nr_highmem;
 
-       printk("swsusp: critical section: \n");
+       printk(KERN_INFO "PM: Creating hibernation image: \n");
 
        drain_local_pages();
        nr_pages = count_data_pages();
        nr_highmem = count_highmem_pages();
-       printk("swsusp: Need to copy %u pages\n", nr_pages + nr_highmem);
+       printk(KERN_INFO "PM: Need to copy %u pages\n", nr_pages + nr_highmem);
 
        if (!enough_free_mem(nr_pages, nr_highmem)) {
-               printk(KERN_ERR "swsusp: Not enough free memory\n");
+               printk(KERN_ERR "PM: Not enough free memory\n");
                return -ENOMEM;
        }
 
        if (swsusp_alloc(&orig_bm, &copy_bm, nr_pages, nr_highmem)) {
-               printk(KERN_ERR "swsusp: Memory allocation failed\n");
+               printk(KERN_ERR "PM: Memory allocation failed\n");
                return -ENOMEM;
        }
 
@@ -1227,22 +1234,50 @@ asmlinkage int swsusp_save(void)
        nr_copy_pages = nr_pages;
        nr_meta_pages = DIV_ROUND_UP(nr_pages * sizeof(long), PAGE_SIZE);
 
-       printk("swsusp: critical section: done (%d pages copied)\n", nr_pages);
+       printk(KERN_INFO "PM: Hibernation image created (%d pages copied)\n",
+               nr_pages);
 
        return 0;
 }
 
-static void init_header(struct swsusp_info *info)
+#ifndef CONFIG_ARCH_HIBERNATION_HEADER
+static int init_header_complete(struct swsusp_info *info)
 {
-       memset(info, 0, sizeof(struct swsusp_info));
+       memcpy(&info->uts, init_utsname(), sizeof(struct new_utsname));
        info->version_code = LINUX_VERSION_CODE;
+       return 0;
+}
+
+static char *check_image_kernel(struct swsusp_info *info)
+{
+       if (info->version_code != LINUX_VERSION_CODE)
+               return "kernel version";
+       if (strcmp(info->uts.sysname,init_utsname()->sysname))
+               return "system type";
+       if (strcmp(info->uts.release,init_utsname()->release))
+               return "kernel release";
+       if (strcmp(info->uts.version,init_utsname()->version))
+               return "version";
+       if (strcmp(info->uts.machine,init_utsname()->machine))
+               return "machine";
+       return NULL;
+}
+#endif /* CONFIG_ARCH_HIBERNATION_HEADER */
+
+unsigned long snapshot_get_image_size(void)
+{
+       return nr_copy_pages + nr_meta_pages + 1;
+}
+
+static int init_header(struct swsusp_info *info)
+{
+       memset(info, 0, sizeof(struct swsusp_info));
        info->num_physpages = num_physpages;
-       memcpy(&info->uts, init_utsname(), sizeof(struct new_utsname));
-       info->cpus = num_online_cpus();
        info->image_pages = nr_copy_pages;
-       info->pages = nr_copy_pages + nr_meta_pages + 1;
+       info->pages = snapshot_get_image_size();
        info->size = info->pages;
        info->size <<= PAGE_SHIFT;
+       return init_header_complete(info);
 }
 
 /**
@@ -1296,7 +1331,11 @@ int snapshot_read_next(struct snapshot_handle *handle, size_t count)
                        return -ENOMEM;
        }
        if (!handle->offset) {
-               init_header((struct swsusp_info *)buffer);
+               int error;
+
+               error = init_header((struct swsusp_info *)buffer);
+               if (error)
+                       return error;
                handle->buffer = buffer;
                memory_bm_position_reset(&orig_bm);
                memory_bm_position_reset(&copy_bm);
@@ -1387,24 +1426,15 @@ duplicate_memory_bitmap(struct memory_bitmap *dst, struct memory_bitmap *src)
        }
 }
 
-static inline int check_header(struct swsusp_info *info)
+static int check_header(struct swsusp_info *info)
 {
-       char *reason = NULL;
+       char *reason;
 
-       if (info->version_code != LINUX_VERSION_CODE)
-               reason = "kernel version";
-       if (info->num_physpages != num_physpages)
+       reason = check_image_kernel(info);
+       if (!reason && info->num_physpages != num_physpages)
                reason = "memory size";
-       if (strcmp(info->uts.sysname,init_utsname()->sysname))
-               reason = "system type";
-       if (strcmp(info->uts.release,init_utsname()->release))
-               reason = "kernel release";
-       if (strcmp(info->uts.version,init_utsname()->version))
-               reason = "version";
-       if (strcmp(info->uts.machine,init_utsname()->machine))
-               reason = "machine";
        if (reason) {
-               printk(KERN_ERR "swsusp: Resume mismatch: %s\n", reason);
+               printk(KERN_ERR "PM: Image mismatch: %s\n", reason);
                return -EPERM;
        }
        return 0;