aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-05-07 18:29:49 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-05-12 08:14:38 -0400
commite2ff39400d81233374e780b133496a2296643d7d (patch)
tree6f96f82ebc9474652a32e7fff8f8d9eb7184eb56 /drivers/acpi
parentac212b6980d8d5eda705864fc5a8ecddc6d6eacc (diff)
ACPI / memhotplug: Bind removable memory blocks to ACPI device nodes
During ACPI memory hotplug configuration bind memory blocks residing in modules removable through the standard ACPI mechanism to struct acpi_device objects associated with ACPI namespace objects representing those modules. Accordingly, unbind those memory blocks from the struct acpi_device objects when the memory modules in question are being removed. When "offline" operation for devices representing memory blocks is introduced, this will allow the ACPI core's device hot-remove code to use it to carry out remove_memory() for those memory blocks and check the results of that before it actually removes the modules holding them from the system. Since walk_memory_range() is used for accessing all memory blocks corresponding to a given ACPI namespace object, it is exported from memory_hotplug.c so that the code in acpi_memhotplug.c can use it. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Tested-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com> Reviewed-by: Toshi Kani <toshi.kani@hp.com>
Diffstat (limited to 'drivers/acpi')
-rw-r--r--drivers/acpi/acpi_memhotplug.c53
1 files changed, 50 insertions, 3 deletions
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index 5e6301e94920..5590db12028e 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 /*
@@ -229,10 +273,11 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
229 273
230static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device) 274static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
231{ 275{
276 acpi_handle handle = mem_device->device->handle;
232 int result = 0, nid; 277 int result = 0, nid;
233 struct acpi_memory_info *info, *n; 278 struct acpi_memory_info *info, *n;
234 279
235 nid = acpi_get_node(mem_device->device->handle); 280 nid = acpi_get_node(handle);
236 281
237 list_for_each_entry_safe(info, n, &mem_device->res_list, list) { 282 list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
238 if (!info->enabled) 283 if (!info->enabled)
@@ -240,6 +285,8 @@ static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
240 285
241 if (nid < 0) 286 if (nid < 0)
242 nid = memory_add_physaddr_to_nid(info->start_addr); 287 nid = memory_add_physaddr_to_nid(info->start_addr);
288
289 acpi_unbind_memory_blocks(info, handle);
243 result = remove_memory(nid, info->start_addr, info->length); 290 result = remove_memory(nid, info->start_addr, info->length);
244 if (result) 291 if (result)
245 return result; 292 return result;
@@ -300,7 +347,7 @@ static int acpi_memory_device_add(struct acpi_device *device,
300 if (result) { 347 if (result) {
301 dev_err(&device->dev, "acpi_memory_enable_device() error\n"); 348 dev_err(&device->dev, "acpi_memory_enable_device() error\n");
302 acpi_memory_device_free(mem_device); 349 acpi_memory_device_free(mem_device);
303 return -ENODEV; 350 return result;
304 } 351 }
305 352
306 dev_dbg(&device->dev, "Memory device configured by ACPI\n"); 353 dev_dbg(&device->dev, "Memory device configured by ACPI\n");