===================================================================
@@ -22,7 +22,6 @@
*/
struct nvs_page {
- unsigned long phys_start;
unsigned int size;
void *kaddr;
void *data;
@@ -31,6 +30,8 @@ struct nvs_page {
};
static LIST_HEAD(nvs_list);
+static unsigned long nvs_start;
+static unsigned int nvs_offset;
/**
* suspend_nvs_register - register platform NVS memory region to save
@@ -44,25 +45,28 @@ static LIST_HEAD(nvs_list);
int suspend_nvs_register(unsigned long start, unsigned long size)
{
struct nvs_page *entry, *next;
+ unsigned int offset;
+ nvs_start = round_down(start, PAGE_SIZE);
+ nvs_offset = start - nvs_start;
+ offset = nvs_offset;
while (size > 0) {
- unsigned int nr_bytes;
+ unsigned int nr_bytes = PAGE_SIZE - offset;
entry = kzalloc(sizeof(struct nvs_page), GFP_KERNEL);
if (!entry)
- goto Error;
+ goto err_out;
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;
+ offset -= offset;
}
return 0;
- Error:
+ err_out:
list_for_each_entry_safe(entry, next, &nvs_list, node) {
list_del(&entry->node);
kfree(entry);
@@ -117,25 +121,32 @@ int suspend_nvs_alloc(void)
int suspend_nvs_save(void)
{
struct nvs_page *entry;
+ unsigned long page_addr = nvs_start;
+ unsigned int offset = nvs_offset;
printk(KERN_INFO "PM: Saving platform NVS memory\n");
- list_for_each_entry(entry, &nvs_list, node)
- if (entry->data) {
- unsigned long phys = entry->phys_start;
- unsigned int size = entry->size;
+ list_for_each_entry(entry, &nvs_list, node) {
+ unsigned long phys = page_addr + offset;
+ unsigned int size = entry->size;
- entry->kaddr = acpi_os_get_iomem(phys, size);
- if (!entry->kaddr) {
- entry->kaddr = acpi_os_ioremap(phys, size);
- entry->unmap = true;
- }
+ if (!entry->data)
+ return -ENOMEM;
+
+ entry->kaddr = acpi_os_get_iomem(phys, size);
+ if (!entry->kaddr) {
+ entry->kaddr = acpi_os_ioremap(phys, size);
if (!entry->kaddr) {
suspend_nvs_free();
- return -ENOMEM;
+ return -EIO;
}
- memcpy(entry->data, entry->kaddr, entry->size);
+ entry->unmap = true;
}
+ memcpy(entry->data, entry->kaddr, entry->size);
+
+ page_addr += PAGE_SIZE;
+ offset -= offset;
+ }
return 0;
}