Lines Matching +full:memory +full:- +full:region
1 // SPDX-License-Identifier: GPL-2.0-only
3 * nvs.c - Routines for saving and restoring ACPI NVS memory region
5 * Copyright (C) 2008-2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
40 struct nvs_region *region; in acpi_nvs_register() local
42 region = kmalloc(sizeof(*region), GFP_KERNEL); in acpi_nvs_register()
43 if (!region) in acpi_nvs_register()
44 return -ENOMEM; in acpi_nvs_register()
45 region->phys_start = start; in acpi_nvs_register()
46 region->size = size; in acpi_nvs_register()
47 list_add_tail(®ion->node, &nvs_region_list); in acpi_nvs_register()
56 struct nvs_region *region; in acpi_nvs_for_each_region() local
58 list_for_each_entry(region, &nvs_region_list, node) { in acpi_nvs_for_each_region()
59 rc = func(region->phys_start, region->size, data); in acpi_nvs_for_each_region()
70 * Platforms, like ACPI, may want us to save some memory used by them during
71 * suspend and to restore the contents of this memory during the subsequent
87 * suspend_nvs_register - register platform NVS memory region to save
88 * @start: Physical address of the region.
89 * @size: Size of the region.
91 * The NVS region need not be page-aligned (both ends) and we arrange
92 * things so that the data from page-aligned addresses in this region will
99 pr_info("Registering ACPI NVS region [mem %#010lx-%#010lx] (%ld bytes)\n", in suspend_nvs_register()
100 start, start + size - 1, size); in suspend_nvs_register()
109 list_add_tail(&entry->node, &nvs_list); in suspend_nvs_register()
110 entry->phys_start = start; in suspend_nvs_register()
111 nr_bytes = PAGE_SIZE - (start & ~PAGE_MASK); in suspend_nvs_register()
112 entry->size = (size < nr_bytes) ? size : nr_bytes; in suspend_nvs_register()
114 start += entry->size; in suspend_nvs_register()
115 size -= entry->size; in suspend_nvs_register()
121 list_del(&entry->node); in suspend_nvs_register()
124 return -ENOMEM; in suspend_nvs_register()
128 * suspend_nvs_free - free data pages allocated for saving NVS regions
135 if (entry->data) { in suspend_nvs_free()
136 free_page((unsigned long)entry->data); in suspend_nvs_free()
137 entry->data = NULL; in suspend_nvs_free()
138 if (entry->kaddr) { in suspend_nvs_free()
139 if (entry->unmap) { in suspend_nvs_free()
140 iounmap(entry->kaddr); in suspend_nvs_free()
141 entry->unmap = false; in suspend_nvs_free()
143 acpi_os_unmap_iomem(entry->kaddr, in suspend_nvs_free()
144 entry->size); in suspend_nvs_free()
146 entry->kaddr = NULL; in suspend_nvs_free()
152 * suspend_nvs_alloc - allocate memory necessary for saving NVS regions
159 entry->data = (void *)__get_free_page(GFP_KERNEL); in suspend_nvs_alloc()
160 if (!entry->data) { in suspend_nvs_alloc()
162 return -ENOMEM; in suspend_nvs_alloc()
169 * suspend_nvs_save - save NVS memory regions
175 pr_info("Saving platform NVS memory\n"); in suspend_nvs_save()
178 if (entry->data) { in suspend_nvs_save()
179 unsigned long phys = entry->phys_start; in suspend_nvs_save()
180 unsigned int size = entry->size; in suspend_nvs_save()
182 entry->kaddr = acpi_os_get_iomem(phys, size); in suspend_nvs_save()
183 if (!entry->kaddr) { in suspend_nvs_save()
184 entry->kaddr = acpi_os_ioremap(phys, size); in suspend_nvs_save()
185 entry->unmap = !!entry->kaddr; in suspend_nvs_save()
187 if (!entry->kaddr) { in suspend_nvs_save()
189 return -ENOMEM; in suspend_nvs_save()
191 memcpy(entry->data, entry->kaddr, entry->size); in suspend_nvs_save()
198 * suspend_nvs_restore - restore NVS memory regions
201 * cannot iounmap the virtual addresses used to access the NVS region.
207 pr_info("Restoring platform NVS memory\n"); in suspend_nvs_restore()
210 if (entry->data) in suspend_nvs_restore()
211 memcpy(entry->kaddr, entry->data, entry->size); in suspend_nvs_restore()