Skip to content

Commit a204dbc

Browse files
committed
Merge branch 'acpi-hotplug'
* acpi-hotplug: ACPI: Do not use CONFIG_ACPI_HOTPLUG_MEMORY_MODULE ACPI / cpufreq: Add ACPI processor device IDs to acpi-cpufreq Memory hotplug: Move alternative function definitions to header ACPI / processor: Fix potential NULL pointer dereference in acpi_processor_add() Memory hotplug / ACPI: Simplify memory removal ACPI / scan: Add second pass of companion offlining to hot-remove code Driver core / MM: Drop offline_memory_block() ACPI / processor: Pass processor object handle to acpi_bind_one() ACPI: Drop removal_type field from struct acpi_device Driver core / memory: Simplify __memory_block_change_state() ACPI / processor: Initialize per_cpu(processors, pr->id) properly CPU: Fix sysfs cpu/online of offlined CPUs Driver core: Introduce offline/online callbacks for memory blocks ACPI / memhotplug: Bind removable memory blocks to ACPI device nodes ACPI / processor: Use common hotplug infrastructure ACPI / hotplug: Use device offline/online for graceful hot-removal Driver core: Use generic offline/online for CPU offline/online Driver core: Add offline/online device operations
2 parents 45e0037 + 08f502c commit a204dbc

20 files changed

Lines changed: 1118 additions & 928 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
What: /sys/devices/.../online
2+
Date: April 2013
3+
Contact: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
4+
Description:
5+
The /sys/devices/.../online attribute is only present for
6+
devices whose bus types provide .online() and .offline()
7+
callbacks. The number read from it (0 or 1) reflects the value
8+
of the device's 'offline' field. If that number is 1 and '0'
9+
(or 'n', or 'N') is written to this file, the device bus type's
10+
.offline() callback is executed for the device and (if
11+
successful) its 'offline' field is updated accordingly. In
12+
turn, if that number is 0 and '1' (or 'y', or 'Y') is written to
13+
this file, the device bus type's .online() callback is executed
14+
for the device and (if successful) its 'offline' field is
15+
updated as appropriate.
16+
17+
After a successful execution of the bus type's .offline()
18+
callback the device cannot be used for any purpose until either
19+
it is removed (i.e. device_del() is called for it), or its bus
20+
type's .online() is exeucted successfully.

‎Documentation/ABI/testing/sysfs-firmware-acpi‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ Description:
4444
or 0 (unset). Attempts to write any other values to it will
4545
cause -EINVAL to be returned.
4646

47+
What: /sys/firmware/acpi/hotplug/force_remove
48+
Date: May 2013
49+
Contact: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
50+
Description:
51+
The number in this file (0 or 1) determines whether (1) or not
52+
(0) the ACPI subsystem will allow devices to be hot-removed even
53+
if they cannot be put offline gracefully (from the kernel's
54+
viewpoint). That number can be changed by writing a boolean
55+
value to this file.
56+
4757
What: /sys/firmware/acpi/interrupts/
4858
Date: February 2008
4959
Contact: Len Brown <lenb@kernel.org>

‎drivers/acpi/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ acpi-$(CONFIG_ACPI_SLEEP) += proc.o
3434
acpi-y += bus.o glue.o
3535
acpi-y += scan.o
3636
acpi-y += resource.o
37+
acpi-y += acpi_processor.o
3738
acpi-y += processor_core.o
3839
acpi-y += ec.o
3940
acpi-$(CONFIG_ACPI_DOCK) += dock.o

‎drivers/acpi/acpi_memhotplug.c‎

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929

3030
#include <linux/acpi.h>
31+
#include <linux/memory.h>
3132
#include <linux/memory_hotplug.h>
3233

3334
#include "internal.h"
@@ -166,13 +167,50 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
166167
return 0;
167168
}
168169

170+
static unsigned long acpi_meminfo_start_pfn(struct acpi_memory_info *info)
171+
{
172+
return PFN_DOWN(info->start_addr);
173+
}
174+
175+
static unsigned long acpi_meminfo_end_pfn(struct acpi_memory_info *info)
176+
{
177+
return PFN_UP(info->start_addr + info->length-1);
178+
}
179+
180+
static int acpi_bind_memblk(struct memory_block *mem, void *arg)
181+
{
182+
return acpi_bind_one(&mem->dev, (acpi_handle)arg);
183+
}
184+
185+
static 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+
193+
static int acpi_unbind_memblk(struct memory_block *mem, void *arg)
194+
{
195+
acpi_unbind_one(&mem->dev);
196+
return 0;
197+
}
198+
199+
static 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+
169206
static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
170207
{
208+
acpi_handle handle = mem_device->device->handle;
171209
int result, num_enabled = 0;
172210
struct acpi_memory_info *info;
173211
int node;
174212

175-
node = acpi_get_node(mem_device->device->handle);
213+
node = acpi_get_node(handle);
176214
/*
177215
* Tell the VM there is more memory here...
178216
* 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)
203241
if (result && result != -EEXIST)
204242
continue;
205243

244+
result = acpi_bind_memory_blocks(info, handle);
245+
if (result) {
246+
acpi_unbind_memory_blocks(info, handle);
247+
return -ENODEV;
248+
}
249+
206250
info->enabled = 1;
207251

208252
/*
@@ -227,28 +271,24 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
227271
return 0;
228272
}
229273

230-
static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
274+
static void acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
231275
{
232-
int result = 0, nid;
276+
acpi_handle handle = mem_device->device->handle;
233277
struct acpi_memory_info *info, *n;
234-
235-
nid = acpi_get_node(mem_device->device->handle);
278+
int nid = acpi_get_node(handle);
236279

237280
list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
238281
if (!info->enabled)
239282
continue;
240283

241284
if (nid < 0)
242285
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;
246286

287+
acpi_unbind_memory_blocks(info, handle);
288+
remove_memory(nid, info->start_addr, info->length);
247289
list_del(&info->list);
248290
kfree(info);
249291
}
250-
251-
return result;
252292
}
253293

254294
static 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,
300340
if (result) {
301341
dev_err(&device->dev, "acpi_memory_enable_device() error\n");
302342
acpi_memory_device_free(mem_device);
303-
return -ENODEV;
343+
return result;
304344
}
305345

306346
dev_dbg(&device->dev, "Memory device configured by ACPI\n");

0 commit comments

Comments
 (0)