aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/acpi_memhotplug.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/acpi_memhotplug.c')
-rw-r--r--drivers/acpi/acpi_memhotplug.c62
1 files changed, 51 insertions, 11 deletions
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index 5e6301e94920..c711d1144044 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -28,6 +28,7 @@
28 */ 28 */
29 29
30#include <linux/acpi.h> 30#include <linux/acpi.h>
31#include <linux/memory.h>
31#include <linux/memory_hotplug.h> 32#include <linux/memory_hotplug.h>
32 33
33#include "internal.h" 34#include "internal.h"
@@ -166,13 +167,50 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
166 return 0; 167 return 0;
167} 168}
168 169
170static unsigned long acpi_meminfo_start_pfn(struct acpi_memory_info *info)
171{
172 return PFN_DOWN(info->start_addr);
173}
174
175static unsigned long acpi_meminfo_end_pfn(struct acpi_memory_info *info)
176{
177 return PFN_UP(info->start_addr + info->length-1);
178}
179
180static int acpi_bind_memblk(struct memory_block *mem, void *arg)
181{
182 return acpi_bind_one(&mem->dev, (acpi_handle)arg);
183}
184
185static int acpi_bind_memory_blocks(struct acpi_memory_info *info,
186 acpi_handle handle)
187{
188 return walk_memory_range(acpi_meminfo_start_pfn(info),
189 acpi_meminfo_end_pfn(info), (void *)handle,
190 acpi_bind_memblk);
191}
192
193static int acpi_unbind_memblk(struct memory_block *mem, void *arg)
194{
195 acpi_unbind_one(&mem->dev);
196 return 0;
197}
198
199static void acpi_unbind_memory_blocks(struct acpi_memory_info *info,
200 acpi_handle handle)
201{
202 walk_memory_range(acpi_meminfo_start_pfn(info),
203 acpi_meminfo_end_pfn(info), NULL, acpi_unbind_memblk);
204}
205
169static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) 206static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
170{ 207{
208 acpi_handle handle = mem_device->device->handle;
171 int result, num_enabled = 0; 209 int result, num_enabled = 0;
172 struct acpi_memory_info *info; 210 struct acpi_memory_info *info;
173 int node; 211 int node;
174 212
175 node = acpi_get_node(mem_device->device->handle); 213 node = acpi_get_node(handle);
176 /* 214 /*
177 * Tell the VM there is more memory here... 215 * Tell the VM there is more memory here...
178 * Note: Assume that this function returns zero on success 216 * Note: Assume that this function returns zero on success
@@ -203,6 +241,12 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
203 if (result && result != -EEXIST) 241 if (result && result != -EEXIST)
204 continue; 242 continue;
205 243
244 result = acpi_bind_memory_blocks(info, handle);
245 if (result) {
246 acpi_unbind_memory_blocks(info, handle);
247 return -ENODEV;
248 }
249
206 info->enabled = 1; 250 info->enabled = 1;
207 251
208 /* 252 /*
@@ -227,12 +271,11 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
227 return 0; 271 return 0;
228} 272}
229 273
230static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device) 274static void acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
231{ 275{
232 int result = 0, nid; 276 acpi_handle handle = mem_device->device->handle;
233 struct acpi_memory_info *info, *n; 277 struct acpi_memory_info *info, *n;
234 278 int nid = acpi_get_node(handle);
235 nid = acpi_get_node(mem_device->device->handle);
236 279
237 list_for_each_entry_safe(info, n, &mem_device->res_list, list) { 280 list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
238 if (!info->enabled) 281 if (!info->enabled)
@@ -240,15 +283,12 @@ static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
240 283
241 if (nid < 0) 284 if (nid < 0)
242 nid = memory_add_physaddr_to_nid(info->start_addr); 285 nid = memory_add_physaddr_to_nid(info->start_addr);
243 result = remove_memory(nid, info->start_addr, info->length);
244 if (result)
245 return result;
246 286
287 acpi_unbind_memory_blocks(info, handle);
288 remove_memory(nid, info->start_addr, info->length);
247 list_del(&info->list); 289 list_del(&info->list);
248 kfree(info); 290 kfree(info);
249 } 291 }
250
251 return result;
252} 292}
253 293
254static void acpi_memory_device_free(struct acpi_memory_device *mem_device) 294static void acpi_memory_device_free(struct acpi_memory_device *mem_device)
@@ -300,7 +340,7 @@ static int acpi_memory_device_add(struct acpi_device *device,
300 if (result) { 340 if (result) {
301 dev_err(&device->dev, "acpi_memory_enable_device() error\n"); 341 dev_err(&device->dev, "acpi_memory_enable_device() error\n");
302 acpi_memory_device_free(mem_device); 342 acpi_memory_device_free(mem_device);
303 return -ENODEV; 343 return result;
304 } 344 }
305 345
306 dev_dbg(&device->dev, "Memory device configured by ACPI\n"); 346 dev_dbg(&device->dev, "Memory device configured by ACPI\n");