lkml.org 
[lkml]   [2011]   [Jan]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 11/11] ACPI / PM: Make NVS save/restore code use slightly less memory
    Date
    From: Rafael J. Wysocki <rjw@sisk.pl>

    Remove the unnecessary field phys_start from struct nvs_page and
    rework the code in nvs.c to reflect that change.

    Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
    ---
    drivers/acpi/nvs.c | 45 ++++++++++++++++++++++++++++-----------------
    1 file changed, 28 insertions(+), 17 deletions(-)

    Index: linux-2.6/drivers/acpi/nvs.c
    ===================================================================
    --- linux-2.6.orig/drivers/acpi/nvs.c
    +++ linux-2.6/drivers/acpi/nvs.c
    @@ -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;
    }


    \
     
     \ /
      Last update: 2011-01-20 12:41    [W:0.022 / U:125.984 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site