]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - kernel/power/nvs.c
1836db60bbb6d56c2ba06f6a0b01b35bc2183fa2
2 * linux/kernel/power/hibernate_nvs.c - Routines for handling NVS memory
4 * Copyright (C) 2008,2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
6 * This file is released under the GPLv2.
10 #include <linux/kernel.h>
11 #include <linux/list.h>
13 #include <linux/slab.h>
14 #include <linux/suspend.h>
17 * Platforms, like ACPI, may want us to save some memory used by them during
18 * suspend and to restore the contents of this memory during the subsequent
19 * resume. The code below implements a mechanism allowing us to do that.
23 unsigned long phys_start
;
27 struct list_head node
;
30 static LIST_HEAD(nvs_list
);
33 * suspend_nvs_register - register platform NVS memory region to save
34 * @start - physical address of the region
35 * @size - size of the region
37 * The NVS region need not be page-aligned (both ends) and we arrange
38 * things so that the data from page-aligned addresses in this region will
39 * be copied into separate RAM pages.
41 int suspend_nvs_register(unsigned long start
, unsigned long size
)
43 struct nvs_page
*entry
, *next
;
46 unsigned int nr_bytes
;
48 entry
= kzalloc(sizeof(struct nvs_page
), GFP_KERNEL
);
52 list_add_tail(&entry
->node
, &nvs_list
);
53 entry
->phys_start
= start
;
54 nr_bytes
= PAGE_SIZE
- (start
& ~PAGE_MASK
);
55 entry
->size
= (size
< nr_bytes
) ? size
: nr_bytes
;
63 list_for_each_entry_safe(entry
, next
, &nvs_list
, node
) {
64 list_del(&entry
->node
);
71 * suspend_nvs_free - free data pages allocated for saving NVS regions
73 void suspend_nvs_free(void)
75 struct nvs_page
*entry
;
77 list_for_each_entry(entry
, &nvs_list
, node
)
79 free_page((unsigned long)entry
->data
);
82 iounmap(entry
->kaddr
);
89 * suspend_nvs_alloc - allocate memory necessary for saving NVS regions
91 int suspend_nvs_alloc(void)
93 struct nvs_page
*entry
;
95 list_for_each_entry(entry
, &nvs_list
, node
) {
96 entry
->data
= (void *)__get_free_page(GFP_KERNEL
);
106 * suspend_nvs_save - save NVS memory regions
108 void suspend_nvs_save(void)
110 struct nvs_page
*entry
;
112 printk(KERN_INFO
"PM: Saving platform NVS memory\n");
114 list_for_each_entry(entry
, &nvs_list
, node
)
116 entry
->kaddr
= ioremap(entry
->phys_start
, entry
->size
);
117 memcpy(entry
->data
, entry
->kaddr
, entry
->size
);
122 * suspend_nvs_restore - restore NVS memory regions
124 * This function is going to be called with interrupts disabled, so it
125 * cannot iounmap the virtual addresses used to access the NVS region.
127 void suspend_nvs_restore(void)
129 struct nvs_page
*entry
;
131 printk(KERN_INFO
"PM: Restoring platform NVS memory\n");
133 list_for_each_entry(entry
, &nvs_list
, node
)
135 memcpy(entry
->kaddr
, entry
->data
, entry
->size
);