PM / ACPI: Move NVS saving and restoring code to drivers/acpi
authorRafael J. Wysocki <rjw@sisk.pl>
Fri, 7 Jan 2011 00:43:44 +0000 (01:43 +0100)
committerLen Brown <len.brown@intel.com>
Fri, 7 Jan 2011 05:36:55 +0000 (00:36 -0500)
The saving of the ACPI NVS area during hibernation and suspend and
restoring it during the subsequent resume is entirely specific to
ACPI, so move it to drivers/acpi and drop the CONFIG_SUSPEND_NVS
configuration option which is redundant.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Len Brown <len.brown@intel.com>
arch/x86/kernel/e820.c
drivers/acpi/Makefile
drivers/acpi/internal.h
drivers/acpi/nvs.c [new file with mode: 0644]
include/linux/acpi.h
include/linux/suspend.h
kernel/power/Kconfig
kernel/power/Makefile
kernel/power/nvs.c [deleted file]

index 0c2b7ef7a34d5453d510ba3a598e5b15c2af6b53..294f26da0c0ce448f294ceacd162da3ff77b1f5f 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/bootmem.h>
 #include <linux/pfn.h>
 #include <linux/suspend.h>
+#include <linux/acpi.h>
 #include <linux/firmware-map.h>
 #include <linux/memblock.h>
 
index 3d031d02e54b556a038be7ae2a64ebde1fa92f84..9cc9f2c4da79e7fd5322d7c001c117e66295735b 100644 (file)
@@ -24,7 +24,7 @@ acpi-y                                += atomicio.o
 # sleep related files
 acpi-y                         += wakeup.o
 acpi-y                         += sleep.o
-acpi-$(CONFIG_ACPI_SLEEP)      += proc.o
+acpi-$(CONFIG_ACPI_SLEEP)      += proc.o nvs.o
 
 
 #
index a212bfeddf8c0247e2ccfd9a34da8df325bc6576..7c23b76e8eca24b696fa777f24630cf16ba1c0d5 100644 (file)
@@ -82,8 +82,16 @@ extern int acpi_sleep_init(void);
 
 #ifdef CONFIG_ACPI_SLEEP
 int acpi_sleep_proc_init(void);
+int suspend_nvs_alloc(void);
+void suspend_nvs_free(void);
+int suspend_nvs_save(void);
+void suspend_nvs_restore(void);
 #else
 static inline int acpi_sleep_proc_init(void) { return 0; }
+static inline int suspend_nvs_alloc(void) { return 0; }
+static inline void suspend_nvs_free(void) {}
+static inline int suspend_nvs_save(void) {}
+static inline void suspend_nvs_restore(void) {}
 #endif
 
 #endif /* _ACPI_INTERNAL_H_ */
diff --git a/drivers/acpi/nvs.c b/drivers/acpi/nvs.c
new file mode 100644 (file)
index 0000000..57c6fab
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * linux/kernel/power/hibernate_nvs.c - Routines for handling NVS memory
+ *
+ * Copyright (C) 2008,2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
+ *
+ * This file is released under the GPLv2.
+ */
+
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/suspend.h>
+
+/*
+ * Platforms, like ACPI, may want us to save some memory used by them during
+ * suspend 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);
+
+/**
+ *     suspend_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 suspend_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;
+}
+
+/**
+ *     suspend_nvs_free - free data pages allocated for saving NVS regions
+ */
+void suspend_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;
+                       }
+               }
+}
+
+/**
+ *     suspend_nvs_alloc - allocate memory necessary for saving NVS regions
+ */
+int suspend_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) {
+                       suspend_nvs_free();
+                       return -ENOMEM;
+               }
+       }
+       return 0;
+}
+
+/**
+ *     suspend_nvs_save - save NVS memory regions
+ */
+int suspend_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);
+                       if (!entry->kaddr) {
+                               suspend_nvs_free();
+                               return -ENOMEM;
+                       }
+                       memcpy(entry->data, entry->kaddr, entry->size);
+               }
+
+       return 0;
+}
+
+/**
+ *     suspend_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 suspend_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);
+}
index 67c91b4418b06e59ea9de82e0c67dfb4cc5a7554..fa7ed6a983d0b2bbd4367c053eb6b77b0deb5e22 100644 (file)
@@ -254,6 +254,15 @@ void __init acpi_old_suspend_ordering(void);
 void __init acpi_nvs_nosave(void);
 #endif /* CONFIG_PM_SLEEP */
 
+#ifdef CONFIG_ACPI_SLEEP
+int suspend_nvs_register(unsigned long start, unsigned long size);
+#else
+static inline int suspend_nvs_register(unsigned long a, unsigned long b)
+{
+       return 0;
+}
+#endif
+
 struct acpi_osc_context {
        char *uuid_str; /* uuid string */
        int rev;
index acb7d911bb0cb63a81ee140a93d5510ec509e887..0e288e3c37be645103f987e80445b39fdb801f14 100644 (file)
@@ -258,23 +258,6 @@ static inline int hibernate(void) { return -ENOSYS; }
 static inline bool system_entering_hibernation(void) { return false; }
 #endif /* CONFIG_HIBERNATION */
 
-#ifdef CONFIG_SUSPEND_NVS
-extern int suspend_nvs_register(unsigned long start, unsigned long size);
-extern int suspend_nvs_alloc(void);
-extern void suspend_nvs_free(void);
-extern int suspend_nvs_save(void);
-extern void suspend_nvs_restore(void);
-#else /* CONFIG_SUSPEND_NVS */
-static inline int suspend_nvs_register(unsigned long a, unsigned long b)
-{
-       return 0;
-}
-static inline int suspend_nvs_alloc(void) { return 0; }
-static inline void suspend_nvs_free(void) {}
-static inline int suspend_nvs_save(void) {}
-static inline void suspend_nvs_restore(void) {}
-#endif /* CONFIG_SUSPEND_NVS */
-
 #ifdef CONFIG_PM_SLEEP
 void save_processor_state(void);
 void restore_processor_state(void);
index a5aff3ebad38b68629d341cb5a28856afb970796..265729966ece61898c9f37a5b8fde49978bcce8c 100644 (file)
@@ -100,13 +100,9 @@ config PM_SLEEP_ADVANCED_DEBUG
        depends on PM_ADVANCED_DEBUG
        default n
 
-config SUSPEND_NVS
-       bool
-
 config SUSPEND
        bool "Suspend to RAM and standby"
        depends on PM && ARCH_SUSPEND_POSSIBLE
-       select SUSPEND_NVS if HAS_IOMEM
        default y
        ---help---
          Allow the system to enter sleep states in which main memory is
@@ -140,7 +136,6 @@ config HIBERNATION
        depends on PM && SWAP && ARCH_HIBERNATION_POSSIBLE
        select LZO_COMPRESS
        select LZO_DECOMPRESS
-       select SUSPEND_NVS if HAS_IOMEM
        ---help---
          Enable the suspend to disk (STD) functionality, which is usually
          called "hibernation" in user interfaces.  STD checkpoints the
index f9063c6b185d2917124f06350753ad96e0b184d1..120a15823325990c1d2a16e6ad048b7a392232e9 100644 (file)
@@ -10,6 +10,5 @@ obj-$(CONFIG_SUSPEND)         += suspend.o
 obj-$(CONFIG_PM_TEST_SUSPEND)  += suspend_test.o
 obj-$(CONFIG_HIBERNATION)      += hibernate.o snapshot.o swap.o user.o \
                                   block_io.o
-obj-$(CONFIG_SUSPEND_NVS)      += nvs.o
 
 obj-$(CONFIG_MAGIC_SYSRQ)      += poweroff.o
diff --git a/kernel/power/nvs.c b/kernel/power/nvs.c
deleted file mode 100644 (file)
index 57c6fab..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * linux/kernel/power/hibernate_nvs.c - Routines for handling NVS memory
- *
- * Copyright (C) 2008,2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
- *
- * This file is released under the GPLv2.
- */
-
-#include <linux/io.h>
-#include <linux/kernel.h>
-#include <linux/list.h>
-#include <linux/mm.h>
-#include <linux/slab.h>
-#include <linux/suspend.h>
-
-/*
- * Platforms, like ACPI, may want us to save some memory used by them during
- * suspend 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);
-
-/**
- *     suspend_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 suspend_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;
-}
-
-/**
- *     suspend_nvs_free - free data pages allocated for saving NVS regions
- */
-void suspend_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;
-                       }
-               }
-}
-
-/**
- *     suspend_nvs_alloc - allocate memory necessary for saving NVS regions
- */
-int suspend_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) {
-                       suspend_nvs_free();
-                       return -ENOMEM;
-               }
-       }
-       return 0;
-}
-
-/**
- *     suspend_nvs_save - save NVS memory regions
- */
-int suspend_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);
-                       if (!entry->kaddr) {
-                               suspend_nvs_free();
-                               return -ENOMEM;
-                       }
-                       memcpy(entry->data, entry->kaddr, entry->size);
-               }
-
-       return 0;
-}
-
-/**
- *     suspend_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 suspend_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);
-}