diff options
| author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-06-28 06:58:05 -0400 |
|---|---|---|
| committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-06-28 06:58:05 -0400 |
| commit | a204dbc61b7f4cb1a7e2cb3ad057b135164782da (patch) | |
| tree | f82151c04a30f49c3dee8926d184575ad2e7b1e2 | |
| parent | 45e00374db944b1c12987b501bcaa279b3e36d93 (diff) | |
| parent | 08f502c1c343031f0d126bd00e87dede38269d12 (diff) | |
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
| -rw-r--r-- | Documentation/ABI/testing/sysfs-devices-online | 20 | ||||
| -rw-r--r-- | Documentation/ABI/testing/sysfs-firmware-acpi | 10 | ||||
| -rw-r--r-- | drivers/acpi/Makefile | 1 | ||||
| -rw-r--r-- | drivers/acpi/acpi_memhotplug.c | 62 | ||||
| -rw-r--r-- | drivers/acpi/acpi_processor.c | 494 | ||||
| -rw-r--r-- | drivers/acpi/glue.c | 6 | ||||
| -rw-r--r-- | drivers/acpi/internal.h | 5 | ||||
| -rw-r--r-- | drivers/acpi/processor_driver.c | 812 | ||||
| -rw-r--r-- | drivers/acpi/scan.c | 120 | ||||
| -rw-r--r-- | drivers/acpi/sysfs.c | 31 | ||||
| -rw-r--r-- | drivers/base/core.c | 130 | ||||
| -rw-r--r-- | drivers/base/cpu.c | 101 | ||||
| -rw-r--r-- | drivers/base/memory.c | 114 | ||||
| -rw-r--r-- | drivers/cpufreq/acpi-cpufreq.c | 7 | ||||
| -rw-r--r-- | include/acpi/acpi_bus.h | 9 | ||||
| -rw-r--r-- | include/acpi/processor.h | 5 | ||||
| -rw-r--r-- | include/linux/acpi.h | 3 | ||||
| -rw-r--r-- | include/linux/device.h | 21 | ||||
| -rw-r--r-- | include/linux/memory_hotplug.h | 14 | ||||
| -rw-r--r-- | mm/memory_hotplug.c | 81 |
20 files changed, 1118 insertions, 928 deletions
diff --git a/Documentation/ABI/testing/sysfs-devices-online b/Documentation/ABI/testing/sysfs-devices-online new file mode 100644 index 000000000000..f990026c0740 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-devices-online | |||
| @@ -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. | ||
diff --git a/Documentation/ABI/testing/sysfs-firmware-acpi b/Documentation/ABI/testing/sysfs-firmware-acpi index ce9bee98b43b..b4436cca97a8 100644 --- a/Documentation/ABI/testing/sysfs-firmware-acpi +++ b/Documentation/ABI/testing/sysfs-firmware-acpi | |||
| @@ -44,6 +44,16 @@ Description: | |||
| 44 | or 0 (unset). Attempts to write any other values to it will | 44 | or 0 (unset). Attempts to write any other values to it will |
| 45 | cause -EINVAL to be returned. | 45 | cause -EINVAL to be returned. |
| 46 | 46 | ||
| 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 | |||
| 47 | What: /sys/firmware/acpi/interrupts/ | 57 | What: /sys/firmware/acpi/interrupts/ |
| 48 | Date: February 2008 | 58 | Date: February 2008 |
| 49 | Contact: Len Brown <lenb@kernel.org> | 59 | Contact: Len Brown <lenb@kernel.org> |
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 536562c626a2..d07771bc3d8c 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile | |||
| @@ -34,6 +34,7 @@ acpi-$(CONFIG_ACPI_SLEEP) += proc.o | |||
| 34 | acpi-y += bus.o glue.o | 34 | acpi-y += bus.o glue.o |
| 35 | acpi-y += scan.o | 35 | acpi-y += scan.o |
| 36 | acpi-y += resource.o | 36 | acpi-y += resource.o |
| 37 | acpi-y += acpi_processor.o | ||
| 37 | acpi-y += processor_core.o | 38 | acpi-y += processor_core.o |
| 38 | acpi-y += ec.o | 39 | acpi-y += ec.o |
| 39 | acpi-$(CONFIG_ACPI_DOCK) += dock.o | 40 | acpi-$(CONFIG_ACPI_DOCK) += dock.o |
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 | ||
| 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 | |||
| 169 | static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) | 206 | static 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 | ||
| 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) |
| 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 | ||
| 254 | static void acpi_memory_device_free(struct acpi_memory_device *mem_device) | 294 | 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, | |||
| 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"); |
diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c new file mode 100644 index 000000000000..e9b01e35ac37 --- /dev/null +++ b/drivers/acpi/acpi_processor.c | |||
| @@ -0,0 +1,494 @@ | |||
| 1 | /* | ||
| 2 | * acpi_processor.c - ACPI processor enumeration support | ||
| 3 | * | ||
| 4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | ||
| 5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | ||
| 6 | * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de> | ||
| 7 | * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> | ||
| 8 | * Copyright (C) 2013, Intel Corporation | ||
| 9 | * Rafael J. Wysocki <rafael.j.wysocki@intel.com> | ||
| 10 | * | ||
| 11 | * This program is free software; you can redistribute it and/or modify it | ||
| 12 | * under the terms of the GNU General Public License version 2 as published | ||
| 13 | * by the Free Software Foundation. | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include <linux/acpi.h> | ||
| 17 | #include <linux/device.h> | ||
| 18 | #include <linux/kernel.h> | ||
| 19 | #include <linux/module.h> | ||
| 20 | #include <linux/pci.h> | ||
| 21 | |||
| 22 | #include <acpi/processor.h> | ||
| 23 | |||
| 24 | #include <asm/cpu.h> | ||
| 25 | |||
| 26 | #include "internal.h" | ||
| 27 | |||
| 28 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT | ||
| 29 | |||
| 30 | ACPI_MODULE_NAME("processor"); | ||
| 31 | |||
| 32 | DEFINE_PER_CPU(struct acpi_processor *, processors); | ||
| 33 | EXPORT_PER_CPU_SYMBOL(processors); | ||
| 34 | |||
| 35 | /* -------------------------------------------------------------------------- | ||
| 36 | Errata Handling | ||
| 37 | -------------------------------------------------------------------------- */ | ||
| 38 | |||
| 39 | struct acpi_processor_errata errata __read_mostly; | ||
| 40 | EXPORT_SYMBOL_GPL(errata); | ||
| 41 | |||
| 42 | static int acpi_processor_errata_piix4(struct pci_dev *dev) | ||
| 43 | { | ||
| 44 | u8 value1 = 0; | ||
| 45 | u8 value2 = 0; | ||
| 46 | |||
| 47 | |||
| 48 | if (!dev) | ||
| 49 | return -EINVAL; | ||
| 50 | |||
| 51 | /* | ||
| 52 | * Note that 'dev' references the PIIX4 ACPI Controller. | ||
| 53 | */ | ||
| 54 | |||
| 55 | switch (dev->revision) { | ||
| 56 | case 0: | ||
| 57 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n")); | ||
| 58 | break; | ||
| 59 | case 1: | ||
| 60 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n")); | ||
| 61 | break; | ||
| 62 | case 2: | ||
| 63 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n")); | ||
| 64 | break; | ||
| 65 | case 3: | ||
| 66 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n")); | ||
| 67 | break; | ||
| 68 | default: | ||
| 69 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n")); | ||
| 70 | break; | ||
| 71 | } | ||
| 72 | |||
| 73 | switch (dev->revision) { | ||
| 74 | |||
| 75 | case 0: /* PIIX4 A-step */ | ||
| 76 | case 1: /* PIIX4 B-step */ | ||
| 77 | /* | ||
| 78 | * See specification changes #13 ("Manual Throttle Duty Cycle") | ||
| 79 | * and #14 ("Enabling and Disabling Manual Throttle"), plus | ||
| 80 | * erratum #5 ("STPCLK# Deassertion Time") from the January | ||
| 81 | * 2002 PIIX4 specification update. Applies to only older | ||
| 82 | * PIIX4 models. | ||
| 83 | */ | ||
| 84 | errata.piix4.throttle = 1; | ||
| 85 | |||
| 86 | case 2: /* PIIX4E */ | ||
| 87 | case 3: /* PIIX4M */ | ||
| 88 | /* | ||
| 89 | * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA | ||
| 90 | * Livelock") from the January 2002 PIIX4 specification update. | ||
| 91 | * Applies to all PIIX4 models. | ||
| 92 | */ | ||
| 93 | |||
| 94 | /* | ||
| 95 | * BM-IDE | ||
| 96 | * ------ | ||
| 97 | * Find the PIIX4 IDE Controller and get the Bus Master IDE | ||
| 98 | * Status register address. We'll use this later to read | ||
| 99 | * each IDE controller's DMA status to make sure we catch all | ||
| 100 | * DMA activity. | ||
| 101 | */ | ||
| 102 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
| 103 | PCI_DEVICE_ID_INTEL_82371AB, | ||
| 104 | PCI_ANY_ID, PCI_ANY_ID, NULL); | ||
| 105 | if (dev) { | ||
| 106 | errata.piix4.bmisx = pci_resource_start(dev, 4); | ||
| 107 | pci_dev_put(dev); | ||
| 108 | } | ||
| 109 | |||
| 110 | /* | ||
| 111 | * Type-F DMA | ||
| 112 | * ---------- | ||
| 113 | * Find the PIIX4 ISA Controller and read the Motherboard | ||
| 114 | * DMA controller's status to see if Type-F (Fast) DMA mode | ||
| 115 | * is enabled (bit 7) on either channel. Note that we'll | ||
| 116 | * disable C3 support if this is enabled, as some legacy | ||
| 117 | * devices won't operate well if fast DMA is disabled. | ||
| 118 | */ | ||
| 119 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
| 120 | PCI_DEVICE_ID_INTEL_82371AB_0, | ||
| 121 | PCI_ANY_ID, PCI_ANY_ID, NULL); | ||
| 122 | if (dev) { | ||
| 123 | pci_read_config_byte(dev, 0x76, &value1); | ||
| 124 | pci_read_config_byte(dev, 0x77, &value2); | ||
| 125 | if ((value1 & 0x80) || (value2 & 0x80)) | ||
| 126 | errata.piix4.fdma = 1; | ||
| 127 | pci_dev_put(dev); | ||
| 128 | } | ||
| 129 | |||
| 130 | break; | ||
| 131 | } | ||
| 132 | |||
| 133 | if (errata.piix4.bmisx) | ||
| 134 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 135 | "Bus master activity detection (BM-IDE) erratum enabled\n")); | ||
| 136 | if (errata.piix4.fdma) | ||
| 137 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 138 | "Type-F DMA livelock erratum (C3 disabled)\n")); | ||
| 139 | |||
| 140 | return 0; | ||
| 141 | } | ||
| 142 | |||
| 143 | static int acpi_processor_errata(struct acpi_processor *pr) | ||
| 144 | { | ||
| 145 | int result = 0; | ||
| 146 | struct pci_dev *dev = NULL; | ||
| 147 | |||
| 148 | |||
| 149 | if (!pr) | ||
| 150 | return -EINVAL; | ||
| 151 | |||
| 152 | /* | ||
| 153 | * PIIX4 | ||
| 154 | */ | ||
| 155 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
| 156 | PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID, | ||
| 157 | PCI_ANY_ID, NULL); | ||
| 158 | if (dev) { | ||
| 159 | result = acpi_processor_errata_piix4(dev); | ||
| 160 | pci_dev_put(dev); | ||
| 161 | } | ||
| 162 | |||
| 163 | return result; | ||
| 164 | } | ||
| 165 | |||
| 166 | /* -------------------------------------------------------------------------- | ||
| 167 | Initialization | ||
| 168 | -------------------------------------------------------------------------- */ | ||
| 169 | |||
| 170 | #ifdef CONFIG_ACPI_HOTPLUG_CPU | ||
| 171 | static int acpi_processor_hotadd_init(struct acpi_processor *pr) | ||
| 172 | { | ||
| 173 | unsigned long long sta; | ||
| 174 | acpi_status status; | ||
| 175 | int ret; | ||
| 176 | |||
| 177 | status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta); | ||
| 178 | if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT)) | ||
| 179 | return -ENODEV; | ||
| 180 | |||
| 181 | ret = acpi_map_lsapic(pr->handle, &pr->id); | ||
| 182 | if (ret) | ||
| 183 | return ret; | ||
| 184 | |||
| 185 | ret = arch_register_cpu(pr->id); | ||
| 186 | if (ret) { | ||
| 187 | acpi_unmap_lsapic(pr->id); | ||
| 188 | return ret; | ||
| 189 | } | ||
| 190 | |||
| 191 | /* | ||
| 192 | * CPU got hot-added, but cpu_data is not initialized yet. Set a flag | ||
| 193 | * to delay cpu_idle/throttling initialization and do it when the CPU | ||
| 194 | * gets online for the first time. | ||
| 195 | */ | ||
| 196 | pr_info("CPU%d has been hot-added\n", pr->id); | ||
| 197 | pr->flags.need_hotplug_init = 1; | ||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | #else | ||
| 201 | static inline int acpi_processor_hotadd_init(struct acpi_processor *pr) | ||
| 202 | { | ||
| 203 | return -ENODEV; | ||
| 204 | } | ||
| 205 | #endif /* CONFIG_ACPI_HOTPLUG_CPU */ | ||
| 206 | |||
| 207 | static int acpi_processor_get_info(struct acpi_device *device) | ||
| 208 | { | ||
| 209 | union acpi_object object = { 0 }; | ||
| 210 | struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; | ||
| 211 | struct acpi_processor *pr = acpi_driver_data(device); | ||
| 212 | int cpu_index, device_declaration = 0; | ||
| 213 | acpi_status status = AE_OK; | ||
| 214 | static int cpu0_initialized; | ||
| 215 | |||
| 216 | if (num_online_cpus() > 1) | ||
| 217 | errata.smp = TRUE; | ||
| 218 | |||
| 219 | acpi_processor_errata(pr); | ||
| 220 | |||
| 221 | /* | ||
| 222 | * Check to see if we have bus mastering arbitration control. This | ||
| 223 | * is required for proper C3 usage (to maintain cache coherency). | ||
| 224 | */ | ||
| 225 | if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) { | ||
| 226 | pr->flags.bm_control = 1; | ||
| 227 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 228 | "Bus mastering arbitration control present\n")); | ||
| 229 | } else | ||
| 230 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 231 | "No bus mastering arbitration control\n")); | ||
| 232 | |||
| 233 | if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) { | ||
| 234 | /* Declared with "Processor" statement; match ProcessorID */ | ||
| 235 | status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer); | ||
| 236 | if (ACPI_FAILURE(status)) { | ||
| 237 | dev_err(&device->dev, | ||
| 238 | "Failed to evaluate processor object (0x%x)\n", | ||
| 239 | status); | ||
| 240 | return -ENODEV; | ||
| 241 | } | ||
| 242 | |||
| 243 | /* | ||
| 244 | * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP. | ||
| 245 | * >>> 'acpi_get_processor_id(acpi_id, &id)' in | ||
| 246 | * arch/xxx/acpi.c | ||
| 247 | */ | ||
| 248 | pr->acpi_id = object.processor.proc_id; | ||
| 249 | } else { | ||
| 250 | /* | ||
| 251 | * Declared with "Device" statement; match _UID. | ||
| 252 | * Note that we don't handle string _UIDs yet. | ||
| 253 | */ | ||
| 254 | unsigned long long value; | ||
| 255 | status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID, | ||
| 256 | NULL, &value); | ||
| 257 | if (ACPI_FAILURE(status)) { | ||
| 258 | dev_err(&device->dev, | ||
| 259 | "Failed to evaluate processor _UID (0x%x)\n", | ||
| 260 | status); | ||
| 261 | return -ENODEV; | ||
| 262 | } | ||
| 263 | device_declaration = 1; | ||
| 264 | pr->acpi_id = value; | ||
| 265 | } | ||
| 266 | cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id); | ||
| 267 | |||
| 268 | /* Handle UP system running SMP kernel, with no LAPIC in MADT */ | ||
| 269 | if (!cpu0_initialized && (cpu_index == -1) && | ||
| 270 | (num_online_cpus() == 1)) { | ||
| 271 | cpu_index = 0; | ||
| 272 | } | ||
| 273 | |||
| 274 | cpu0_initialized = 1; | ||
| 275 | |||
| 276 | pr->id = cpu_index; | ||
| 277 | |||
| 278 | /* | ||
| 279 | * Extra Processor objects may be enumerated on MP systems with | ||
| 280 | * less than the max # of CPUs. They should be ignored _iff | ||
| 281 | * they are physically not present. | ||
| 282 | */ | ||
| 283 | if (pr->id == -1) { | ||
| 284 | int ret = acpi_processor_hotadd_init(pr); | ||
| 285 | if (ret) | ||
| 286 | return ret; | ||
| 287 | } | ||
| 288 | /* | ||
| 289 | * On some boxes several processors use the same processor bus id. | ||
| 290 | * But they are located in different scope. For example: | ||
| 291 | * \_SB.SCK0.CPU0 | ||
| 292 | * \_SB.SCK1.CPU0 | ||
| 293 | * Rename the processor device bus id. And the new bus id will be | ||
| 294 | * generated as the following format: | ||
| 295 | * CPU+CPU ID. | ||
| 296 | */ | ||
| 297 | sprintf(acpi_device_bid(device), "CPU%X", pr->id); | ||
| 298 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id, | ||
| 299 | pr->acpi_id)); | ||
| 300 | |||
| 301 | if (!object.processor.pblk_address) | ||
| 302 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n")); | ||
| 303 | else if (object.processor.pblk_length != 6) | ||
| 304 | dev_err(&device->dev, "Invalid PBLK length [%d]\n", | ||
| 305 | object.processor.pblk_length); | ||
| 306 | else { | ||
| 307 | pr->throttling.address = object.processor.pblk_address; | ||
| 308 | pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset; | ||
| 309 | pr->throttling.duty_width = acpi_gbl_FADT.duty_width; | ||
| 310 | |||
| 311 | pr->pblk = object.processor.pblk_address; | ||
| 312 | |||
| 313 | /* | ||
| 314 | * We don't care about error returns - we just try to mark | ||
| 315 | * these reserved so that nobody else is confused into thinking | ||
| 316 | * that this region might be unused.. | ||
| 317 | * | ||
| 318 | * (In particular, allocating the IO range for Cardbus) | ||
| 319 | */ | ||
| 320 | request_region(pr->throttling.address, 6, "ACPI CPU throttle"); | ||
| 321 | } | ||
| 322 | |||
| 323 | /* | ||
| 324 | * If ACPI describes a slot number for this CPU, we can use it to | ||
| 325 | * ensure we get the right value in the "physical id" field | ||
| 326 | * of /proc/cpuinfo | ||
| 327 | */ | ||
| 328 | status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer); | ||
| 329 | if (ACPI_SUCCESS(status)) | ||
| 330 | arch_fix_phys_package_id(pr->id, object.integer.value); | ||
| 331 | |||
| 332 | return 0; | ||
| 333 | } | ||
| 334 | |||
| 335 | /* | ||
| 336 | * Do not put anything in here which needs the core to be online. | ||
| 337 | * For example MSR access or setting up things which check for cpuinfo_x86 | ||
| 338 | * (cpu_data(cpu)) values, like CPU feature flags, family, model, etc. | ||
| 339 | * Such things have to be put in and set up by the processor driver's .probe(). | ||
| 340 | */ | ||
| 341 | static DEFINE_PER_CPU(void *, processor_device_array); | ||
| 342 | |||
| 343 | static int __cpuinit acpi_processor_add(struct acpi_device *device, | ||
| 344 | const struct acpi_device_id *id) | ||
| 345 | { | ||
| 346 | struct acpi_processor *pr; | ||
| 347 | struct device *dev; | ||
| 348 | int result = 0; | ||
| 349 | |||
| 350 | pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); | ||
| 351 | if (!pr) | ||
| 352 | return -ENOMEM; | ||
| 353 | |||
| 354 | if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) { | ||
| 355 | result = -ENOMEM; | ||
| 356 | goto err_free_pr; | ||
| 357 | } | ||
| 358 | |||
| 359 | pr->handle = device->handle; | ||
| 360 | strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME); | ||
| 361 | strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS); | ||
| 362 | device->driver_data = pr; | ||
| 363 | |||
| 364 | result = acpi_processor_get_info(device); | ||
| 365 | if (result) /* Processor is not physically present or unavailable */ | ||
| 366 | return 0; | ||
| 367 | |||
| 368 | #ifdef CONFIG_SMP | ||
| 369 | if (pr->id >= setup_max_cpus && pr->id != 0) | ||
| 370 | return 0; | ||
| 371 | #endif | ||
| 372 | |||
| 373 | BUG_ON(pr->id >= nr_cpu_ids); | ||
| 374 | |||
| 375 | /* | ||
| 376 | * Buggy BIOS check. | ||
| 377 | * ACPI id of processors can be reported wrongly by the BIOS. | ||
| 378 | * Don't trust it blindly | ||
| 379 | */ | ||
| 380 | if (per_cpu(processor_device_array, pr->id) != NULL && | ||
| 381 | per_cpu(processor_device_array, pr->id) != device) { | ||
| 382 | dev_warn(&device->dev, | ||
| 383 | "BIOS reported wrong ACPI id %d for the processor\n", | ||
| 384 | pr->id); | ||
| 385 | /* Give up, but do not abort the namespace scan. */ | ||
| 386 | goto err; | ||
| 387 | } | ||
| 388 | /* | ||
| 389 | * processor_device_array is not cleared on errors to allow buggy BIOS | ||
| 390 | * checks. | ||
| 391 | */ | ||
| 392 | per_cpu(processor_device_array, pr->id) = device; | ||
| 393 | per_cpu(processors, pr->id) = pr; | ||
| 394 | |||
| 395 | dev = get_cpu_device(pr->id); | ||
| 396 | if (!dev) { | ||
| 397 | result = -ENODEV; | ||
| 398 | goto err; | ||
| 399 | } | ||
| 400 | |||
| 401 | result = acpi_bind_one(dev, pr->handle); | ||
| 402 | if (result) | ||
| 403 | goto err; | ||
| 404 | |||
| 405 | pr->dev = dev; | ||
| 406 | dev->offline = pr->flags.need_hotplug_init; | ||
| 407 | |||
| 408 | /* Trigger the processor driver's .probe() if present. */ | ||
| 409 | if (device_attach(dev) >= 0) | ||
| 410 | return 1; | ||
| 411 | |||
| 412 | dev_err(dev, "Processor driver could not be attached\n"); | ||
| 413 | acpi_unbind_one(dev); | ||
| 414 | |||
| 415 | err: | ||
| 416 | free_cpumask_var(pr->throttling.shared_cpu_map); | ||
| 417 | device->driver_data = NULL; | ||
| 418 | per_cpu(processors, pr->id) = NULL; | ||
| 419 | err_free_pr: | ||
| 420 | kfree(pr); | ||
| 421 | return result; | ||
| 422 | } | ||
| 423 | |||
| 424 | #ifdef CONFIG_ACPI_HOTPLUG_CPU | ||
| 425 | /* -------------------------------------------------------------------------- | ||
| 426 | Removal | ||
| 427 | -------------------------------------------------------------------------- */ | ||
| 428 | |||
| 429 | static void acpi_processor_remove(struct acpi_device *device) | ||
| 430 | { | ||
| 431 | struct acpi_processor *pr; | ||
| 432 | |||
| 433 | if (!device || !acpi_driver_data(device)) | ||
| 434 | return; | ||
| 435 | |||
| 436 | pr = acpi_driver_data(device); | ||
| 437 | if (pr->id >= nr_cpu_ids) | ||
| 438 | goto out; | ||
| 439 | |||
| 440 | /* | ||
| 441 | * The only reason why we ever get here is CPU hot-removal. The CPU is | ||
| 442 | * already offline and the ACPI device removal locking prevents it from | ||
| 443 | * being put back online at this point. | ||
| 444 | * | ||
| 445 | * Unbind the driver from the processor device and detach it from the | ||
| 446 | * ACPI companion object. | ||
| 447 | */ | ||
| 448 | device_release_driver(pr->dev); | ||
| 449 | acpi_unbind_one(pr->dev); | ||
| 450 | |||
| 451 | /* Clean up. */ | ||
| 452 | per_cpu(processor_device_array, pr->id) = NULL; | ||
| 453 | per_cpu(processors, pr->id) = NULL; | ||
| 454 | try_offline_node(cpu_to_node(pr->id)); | ||
| 455 | |||
| 456 | /* Remove the CPU. */ | ||
| 457 | get_online_cpus(); | ||
| 458 | arch_unregister_cpu(pr->id); | ||
| 459 | acpi_unmap_lsapic(pr->id); | ||
| 460 | put_online_cpus(); | ||
| 461 | |||
| 462 | out: | ||
| 463 | free_cpumask_var(pr->throttling.shared_cpu_map); | ||
| 464 | kfree(pr); | ||
| 465 | } | ||
| 466 | #endif /* CONFIG_ACPI_HOTPLUG_CPU */ | ||
| 467 | |||
| 468 | /* | ||
| 469 | * The following ACPI IDs are known to be suitable for representing as | ||
| 470 | * processor devices. | ||
| 471 | */ | ||
| 472 | static const struct acpi_device_id processor_device_ids[] = { | ||
| 473 | |||
| 474 | { ACPI_PROCESSOR_OBJECT_HID, }, | ||
| 475 | { ACPI_PROCESSOR_DEVICE_HID, }, | ||
| 476 | |||
| 477 | { } | ||
| 478 | }; | ||
| 479 | |||
| 480 | static struct acpi_scan_handler __refdata processor_handler = { | ||
| 481 | .ids = processor_device_ids, | ||
| 482 | .attach = acpi_processor_add, | ||
| 483 | #ifdef CONFIG_ACPI_HOTPLUG_CPU | ||
| 484 | .detach = acpi_processor_remove, | ||
| 485 | #endif | ||
| 486 | .hotplug = { | ||
| 487 | .enabled = true, | ||
| 488 | }, | ||
| 489 | }; | ||
| 490 | |||
| 491 | void __init acpi_processor_init(void) | ||
| 492 | { | ||
| 493 | acpi_scan_add_handler_with_hotplug(&processor_handler, "processor"); | ||
| 494 | } | ||
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index 40a84cc6740c..9783f400d857 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c | |||
| @@ -105,7 +105,7 @@ acpi_handle acpi_get_child(acpi_handle parent, u64 address) | |||
| 105 | } | 105 | } |
| 106 | EXPORT_SYMBOL(acpi_get_child); | 106 | EXPORT_SYMBOL(acpi_get_child); |
| 107 | 107 | ||
| 108 | static int acpi_bind_one(struct device *dev, acpi_handle handle) | 108 | int acpi_bind_one(struct device *dev, acpi_handle handle) |
| 109 | { | 109 | { |
| 110 | struct acpi_device *acpi_dev; | 110 | struct acpi_device *acpi_dev; |
| 111 | acpi_status status; | 111 | acpi_status status; |
| @@ -188,8 +188,9 @@ static int acpi_bind_one(struct device *dev, acpi_handle handle) | |||
| 188 | kfree(physical_node); | 188 | kfree(physical_node); |
| 189 | goto err; | 189 | goto err; |
| 190 | } | 190 | } |
| 191 | EXPORT_SYMBOL_GPL(acpi_bind_one); | ||
| 191 | 192 | ||
| 192 | static int acpi_unbind_one(struct device *dev) | 193 | int acpi_unbind_one(struct device *dev) |
| 193 | { | 194 | { |
| 194 | struct acpi_device_physical_node *entry; | 195 | struct acpi_device_physical_node *entry; |
| 195 | struct acpi_device *acpi_dev; | 196 | struct acpi_device *acpi_dev; |
| @@ -238,6 +239,7 @@ err: | |||
| 238 | dev_err(dev, "Oops, 'acpi_handle' corrupt\n"); | 239 | dev_err(dev, "Oops, 'acpi_handle' corrupt\n"); |
| 239 | return -EINVAL; | 240 | return -EINVAL; |
| 240 | } | 241 | } |
| 242 | EXPORT_SYMBOL_GPL(acpi_unbind_one); | ||
| 241 | 243 | ||
| 242 | static int acpi_platform_notify(struct device *dev) | 244 | static int acpi_platform_notify(struct device *dev) |
| 243 | { | 245 | { |
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index c610a76d92c4..520073ba36b4 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h | |||
| @@ -33,6 +33,7 @@ static inline void acpi_pci_slot_init(void) { } | |||
| 33 | void acpi_pci_root_init(void); | 33 | void acpi_pci_root_init(void); |
| 34 | void acpi_pci_link_init(void); | 34 | void acpi_pci_link_init(void); |
| 35 | void acpi_pci_root_hp_init(void); | 35 | void acpi_pci_root_hp_init(void); |
| 36 | void acpi_processor_init(void); | ||
| 36 | void acpi_platform_init(void); | 37 | void acpi_platform_init(void); |
| 37 | int acpi_sysfs_init(void); | 38 | int acpi_sysfs_init(void); |
| 38 | #ifdef CONFIG_ACPI_CONTAINER | 39 | #ifdef CONFIG_ACPI_CONTAINER |
| @@ -51,6 +52,8 @@ void acpi_memory_hotplug_init(void); | |||
| 51 | static inline void acpi_memory_hotplug_init(void) {} | 52 | static inline void acpi_memory_hotplug_init(void) {} |
| 52 | #endif | 53 | #endif |
| 53 | 54 | ||
| 55 | extern bool acpi_force_hot_remove; | ||
| 56 | |||
| 54 | void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug, | 57 | void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug, |
| 55 | const char *name); | 58 | const char *name); |
| 56 | int acpi_scan_add_handler_with_hotplug(struct acpi_scan_handler *handler, | 59 | int acpi_scan_add_handler_with_hotplug(struct acpi_scan_handler *handler, |
| @@ -81,6 +84,8 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, | |||
| 81 | int type, unsigned long long sta); | 84 | int type, unsigned long long sta); |
| 82 | void acpi_device_add_finalize(struct acpi_device *device); | 85 | void acpi_device_add_finalize(struct acpi_device *device); |
| 83 | void acpi_free_pnp_ids(struct acpi_device_pnp *pnp); | 86 | void acpi_free_pnp_ids(struct acpi_device_pnp *pnp); |
| 87 | int acpi_bind_one(struct device *dev, acpi_handle handle); | ||
| 88 | int acpi_unbind_one(struct device *dev); | ||
| 84 | 89 | ||
| 85 | /* -------------------------------------------------------------------------- | 90 | /* -------------------------------------------------------------------------- |
| 86 | Power Resource | 91 | Power Resource |
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c index c266cdc11784..d93963f1e8f4 100644 --- a/drivers/acpi/processor_driver.c +++ b/drivers/acpi/processor_driver.c | |||
| @@ -1,11 +1,13 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * acpi_processor.c - ACPI Processor Driver ($Revision: 71 $) | 2 | * processor_driver.c - ACPI Processor Driver |
| 3 | * | 3 | * |
| 4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | 4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
| 5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | 5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
| 6 | * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de> | 6 | * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de> |
| 7 | * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> | 7 | * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> |
| 8 | * - Added processor hotplug support | 8 | * - Added processor hotplug support |
| 9 | * Copyright (C) 2013, Intel Corporation | ||
| 10 | * Rafael J. Wysocki <rafael.j.wysocki@intel.com> | ||
| 9 | * | 11 | * |
| 10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 12 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11 | * | 13 | * |
| @@ -24,52 +26,29 @@ | |||
| 24 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | 26 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 25 | * | 27 | * |
| 26 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 28 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 27 | * TBD: | ||
| 28 | * 1. Make # power states dynamic. | ||
| 29 | * 2. Support duty_cycle values that span bit 4. | ||
| 30 | * 3. Optimize by having scheduler determine business instead of | ||
| 31 | * having us try to calculate it here. | ||
| 32 | * 4. Need C1 timing -- must modify kernel (IRQ handler) to get this. | ||
| 33 | */ | 29 | */ |
| 34 | 30 | ||
| 35 | #include <linux/kernel.h> | 31 | #include <linux/kernel.h> |
| 36 | #include <linux/module.h> | 32 | #include <linux/module.h> |
| 37 | #include <linux/init.h> | 33 | #include <linux/init.h> |
| 38 | #include <linux/types.h> | ||
| 39 | #include <linux/pci.h> | ||
| 40 | #include <linux/pm.h> | ||
| 41 | #include <linux/cpufreq.h> | 34 | #include <linux/cpufreq.h> |
| 42 | #include <linux/cpu.h> | 35 | #include <linux/cpu.h> |
| 43 | #include <linux/dmi.h> | ||
| 44 | #include <linux/moduleparam.h> | ||
| 45 | #include <linux/cpuidle.h> | 36 | #include <linux/cpuidle.h> |
| 46 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
| 47 | #include <linux/acpi.h> | 38 | #include <linux/acpi.h> |
| 48 | #include <linux/memory_hotplug.h> | 39 | |
| 49 | |||
| 50 | #include <asm/io.h> | ||
| 51 | #include <asm/cpu.h> | ||
| 52 | #include <asm/delay.h> | ||
| 53 | #include <asm/uaccess.h> | ||
| 54 | #include <asm/processor.h> | ||
| 55 | #include <asm/smp.h> | ||
| 56 | #include <asm/acpi.h> | ||
| 57 | |||
| 58 | #include <acpi/acpi_bus.h> | ||
| 59 | #include <acpi/acpi_drivers.h> | ||
| 60 | #include <acpi/processor.h> | 40 | #include <acpi/processor.h> |
| 61 | 41 | ||
| 42 | #include "internal.h" | ||
| 43 | |||
| 62 | #define PREFIX "ACPI: " | 44 | #define PREFIX "ACPI: " |
| 63 | 45 | ||
| 64 | #define ACPI_PROCESSOR_CLASS "processor" | ||
| 65 | #define ACPI_PROCESSOR_DEVICE_NAME "Processor" | ||
| 66 | #define ACPI_PROCESSOR_FILE_INFO "info" | 46 | #define ACPI_PROCESSOR_FILE_INFO "info" |
| 67 | #define ACPI_PROCESSOR_FILE_THROTTLING "throttling" | 47 | #define ACPI_PROCESSOR_FILE_THROTTLING "throttling" |
| 68 | #define ACPI_PROCESSOR_FILE_LIMIT "limit" | 48 | #define ACPI_PROCESSOR_FILE_LIMIT "limit" |
| 69 | #define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80 | 49 | #define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80 |
| 70 | #define ACPI_PROCESSOR_NOTIFY_POWER 0x81 | 50 | #define ACPI_PROCESSOR_NOTIFY_POWER 0x81 |
| 71 | #define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82 | 51 | #define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82 |
| 72 | #define ACPI_PROCESSOR_DEVICE_HID "ACPI0007" | ||
| 73 | 52 | ||
| 74 | #define ACPI_PROCESSOR_LIMIT_USER 0 | 53 | #define ACPI_PROCESSOR_LIMIT_USER 0 |
| 75 | #define ACPI_PROCESSOR_LIMIT_THERMAL 1 | 54 | #define ACPI_PROCESSOR_LIMIT_THERMAL 1 |
| @@ -81,12 +60,8 @@ MODULE_AUTHOR("Paul Diefenbaugh"); | |||
| 81 | MODULE_DESCRIPTION("ACPI Processor Driver"); | 60 | MODULE_DESCRIPTION("ACPI Processor Driver"); |
| 82 | MODULE_LICENSE("GPL"); | 61 | MODULE_LICENSE("GPL"); |
| 83 | 62 | ||
| 84 | static int acpi_processor_add(struct acpi_device *device); | 63 | static int acpi_processor_start(struct device *dev); |
| 85 | static int acpi_processor_remove(struct acpi_device *device); | 64 | static int acpi_processor_stop(struct device *dev); |
| 86 | static void acpi_processor_notify(struct acpi_device *device, u32 event); | ||
| 87 | static acpi_status acpi_processor_hotadd_init(struct acpi_processor *pr); | ||
| 88 | static int acpi_processor_handle_eject(struct acpi_processor *pr); | ||
| 89 | static int acpi_processor_start(struct acpi_processor *pr); | ||
| 90 | 65 | ||
| 91 | static const struct acpi_device_id processor_device_ids[] = { | 66 | static const struct acpi_device_id processor_device_ids[] = { |
| 92 | {ACPI_PROCESSOR_OBJECT_HID, 0}, | 67 | {ACPI_PROCESSOR_OBJECT_HID, 0}, |
| @@ -95,295 +70,24 @@ static const struct acpi_device_id processor_device_ids[] = { | |||
| 95 | }; | 70 | }; |
| 96 | MODULE_DEVICE_TABLE(acpi, processor_device_ids); | 71 | MODULE_DEVICE_TABLE(acpi, processor_device_ids); |
| 97 | 72 | ||
| 98 | static struct acpi_driver acpi_processor_driver = { | 73 | static struct device_driver acpi_processor_driver = { |
| 99 | .name = "processor", | 74 | .name = "processor", |
| 100 | .class = ACPI_PROCESSOR_CLASS, | 75 | .bus = &cpu_subsys, |
| 101 | .ids = processor_device_ids, | 76 | .acpi_match_table = processor_device_ids, |
| 102 | .ops = { | 77 | .probe = acpi_processor_start, |
| 103 | .add = acpi_processor_add, | 78 | .remove = acpi_processor_stop, |
| 104 | .remove = acpi_processor_remove, | ||
| 105 | .notify = acpi_processor_notify, | ||
| 106 | }, | ||
| 107 | }; | 79 | }; |
| 108 | 80 | ||
| 109 | #define INSTALL_NOTIFY_HANDLER 1 | 81 | static void acpi_processor_notify(acpi_handle handle, u32 event, void *data) |
| 110 | #define UNINSTALL_NOTIFY_HANDLER 2 | ||
| 111 | |||
| 112 | DEFINE_PER_CPU(struct acpi_processor *, processors); | ||
| 113 | EXPORT_PER_CPU_SYMBOL(processors); | ||
| 114 | |||
| 115 | struct acpi_processor_errata errata __read_mostly; | ||
| 116 | |||
| 117 | /* -------------------------------------------------------------------------- | ||
| 118 | Errata Handling | ||
| 119 | -------------------------------------------------------------------------- */ | ||
| 120 | |||
| 121 | static int acpi_processor_errata_piix4(struct pci_dev *dev) | ||
| 122 | { | 82 | { |
| 123 | u8 value1 = 0; | 83 | struct acpi_device *device = data; |
| 124 | u8 value2 = 0; | ||
| 125 | |||
| 126 | |||
| 127 | if (!dev) | ||
| 128 | return -EINVAL; | ||
| 129 | |||
| 130 | /* | ||
| 131 | * Note that 'dev' references the PIIX4 ACPI Controller. | ||
| 132 | */ | ||
| 133 | |||
| 134 | switch (dev->revision) { | ||
| 135 | case 0: | ||
| 136 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n")); | ||
| 137 | break; | ||
| 138 | case 1: | ||
| 139 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n")); | ||
| 140 | break; | ||
| 141 | case 2: | ||
| 142 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n")); | ||
| 143 | break; | ||
| 144 | case 3: | ||
| 145 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n")); | ||
| 146 | break; | ||
| 147 | default: | ||
| 148 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n")); | ||
| 149 | break; | ||
| 150 | } | ||
| 151 | |||
| 152 | switch (dev->revision) { | ||
| 153 | |||
| 154 | case 0: /* PIIX4 A-step */ | ||
| 155 | case 1: /* PIIX4 B-step */ | ||
| 156 | /* | ||
| 157 | * See specification changes #13 ("Manual Throttle Duty Cycle") | ||
| 158 | * and #14 ("Enabling and Disabling Manual Throttle"), plus | ||
| 159 | * erratum #5 ("STPCLK# Deassertion Time") from the January | ||
| 160 | * 2002 PIIX4 specification update. Applies to only older | ||
| 161 | * PIIX4 models. | ||
| 162 | */ | ||
| 163 | errata.piix4.throttle = 1; | ||
| 164 | |||
| 165 | case 2: /* PIIX4E */ | ||
| 166 | case 3: /* PIIX4M */ | ||
| 167 | /* | ||
| 168 | * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA | ||
| 169 | * Livelock") from the January 2002 PIIX4 specification update. | ||
| 170 | * Applies to all PIIX4 models. | ||
| 171 | */ | ||
| 172 | |||
| 173 | /* | ||
| 174 | * BM-IDE | ||
| 175 | * ------ | ||
| 176 | * Find the PIIX4 IDE Controller and get the Bus Master IDE | ||
| 177 | * Status register address. We'll use this later to read | ||
| 178 | * each IDE controller's DMA status to make sure we catch all | ||
| 179 | * DMA activity. | ||
| 180 | */ | ||
| 181 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
| 182 | PCI_DEVICE_ID_INTEL_82371AB, | ||
| 183 | PCI_ANY_ID, PCI_ANY_ID, NULL); | ||
| 184 | if (dev) { | ||
| 185 | errata.piix4.bmisx = pci_resource_start(dev, 4); | ||
| 186 | pci_dev_put(dev); | ||
| 187 | } | ||
| 188 | |||
| 189 | /* | ||
| 190 | * Type-F DMA | ||
| 191 | * ---------- | ||
| 192 | * Find the PIIX4 ISA Controller and read the Motherboard | ||
| 193 | * DMA controller's status to see if Type-F (Fast) DMA mode | ||
| 194 | * is enabled (bit 7) on either channel. Note that we'll | ||
| 195 | * disable C3 support if this is enabled, as some legacy | ||
| 196 | * devices won't operate well if fast DMA is disabled. | ||
| 197 | */ | ||
| 198 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
| 199 | PCI_DEVICE_ID_INTEL_82371AB_0, | ||
| 200 | PCI_ANY_ID, PCI_ANY_ID, NULL); | ||
| 201 | if (dev) { | ||
| 202 | pci_read_config_byte(dev, 0x76, &value1); | ||
| 203 | pci_read_config_byte(dev, 0x77, &value2); | ||
| 204 | if ((value1 & 0x80) || (value2 & 0x80)) | ||
| 205 | errata.piix4.fdma = 1; | ||
| 206 | pci_dev_put(dev); | ||
| 207 | } | ||
| 208 | |||
| 209 | break; | ||
| 210 | } | ||
| 211 | |||
| 212 | if (errata.piix4.bmisx) | ||
| 213 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 214 | "Bus master activity detection (BM-IDE) erratum enabled\n")); | ||
| 215 | if (errata.piix4.fdma) | ||
| 216 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 217 | "Type-F DMA livelock erratum (C3 disabled)\n")); | ||
| 218 | |||
| 219 | return 0; | ||
| 220 | } | ||
| 221 | |||
| 222 | static int acpi_processor_errata(struct acpi_processor *pr) | ||
| 223 | { | ||
| 224 | int result = 0; | ||
| 225 | struct pci_dev *dev = NULL; | ||
| 226 | |||
| 227 | |||
| 228 | if (!pr) | ||
| 229 | return -EINVAL; | ||
| 230 | |||
| 231 | /* | ||
| 232 | * PIIX4 | ||
| 233 | */ | ||
| 234 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
| 235 | PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID, | ||
| 236 | PCI_ANY_ID, NULL); | ||
| 237 | if (dev) { | ||
| 238 | result = acpi_processor_errata_piix4(dev); | ||
| 239 | pci_dev_put(dev); | ||
| 240 | } | ||
| 241 | |||
| 242 | return result; | ||
| 243 | } | ||
| 244 | |||
| 245 | /* -------------------------------------------------------------------------- | ||
| 246 | Driver Interface | ||
| 247 | -------------------------------------------------------------------------- */ | ||
| 248 | |||
| 249 | static int acpi_processor_get_info(struct acpi_device *device) | ||
| 250 | { | ||
| 251 | acpi_status status = 0; | ||
| 252 | union acpi_object object = { 0 }; | ||
| 253 | struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; | ||
| 254 | struct acpi_processor *pr; | 84 | struct acpi_processor *pr; |
| 255 | int cpu_index, device_declaration = 0; | ||
| 256 | static int cpu0_initialized; | ||
| 257 | |||
| 258 | pr = acpi_driver_data(device); | ||
| 259 | if (!pr) | ||
| 260 | return -EINVAL; | ||
| 261 | |||
| 262 | if (num_online_cpus() > 1) | ||
| 263 | errata.smp = TRUE; | ||
| 264 | |||
| 265 | acpi_processor_errata(pr); | ||
| 266 | |||
| 267 | /* | ||
| 268 | * Check to see if we have bus mastering arbitration control. This | ||
| 269 | * is required for proper C3 usage (to maintain cache coherency). | ||
| 270 | */ | ||
| 271 | if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) { | ||
| 272 | pr->flags.bm_control = 1; | ||
| 273 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 274 | "Bus mastering arbitration control present\n")); | ||
| 275 | } else | ||
| 276 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 277 | "No bus mastering arbitration control\n")); | ||
| 278 | |||
| 279 | if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) { | ||
| 280 | /* Declared with "Processor" statement; match ProcessorID */ | ||
| 281 | status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer); | ||
| 282 | if (ACPI_FAILURE(status)) { | ||
| 283 | dev_err(&device->dev, | ||
| 284 | "Failed to evaluate processor object (0x%x)\n", | ||
| 285 | status); | ||
| 286 | return -ENODEV; | ||
| 287 | } | ||
| 288 | |||
| 289 | /* | ||
| 290 | * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP. | ||
| 291 | * >>> 'acpi_get_processor_id(acpi_id, &id)' in | ||
| 292 | * arch/xxx/acpi.c | ||
| 293 | */ | ||
| 294 | pr->acpi_id = object.processor.proc_id; | ||
| 295 | } else { | ||
| 296 | /* | ||
| 297 | * Declared with "Device" statement; match _UID. | ||
| 298 | * Note that we don't handle string _UIDs yet. | ||
| 299 | */ | ||
| 300 | unsigned long long value; | ||
| 301 | status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID, | ||
| 302 | NULL, &value); | ||
| 303 | if (ACPI_FAILURE(status)) { | ||
| 304 | dev_err(&device->dev, | ||
| 305 | "Failed to evaluate processor _UID (0x%x)\n", | ||
| 306 | status); | ||
| 307 | return -ENODEV; | ||
| 308 | } | ||
| 309 | device_declaration = 1; | ||
| 310 | pr->acpi_id = value; | ||
| 311 | } | ||
| 312 | cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id); | ||
| 313 | |||
| 314 | /* Handle UP system running SMP kernel, with no LAPIC in MADT */ | ||
| 315 | if (!cpu0_initialized && (cpu_index == -1) && | ||
| 316 | (num_online_cpus() == 1)) { | ||
| 317 | cpu_index = 0; | ||
| 318 | } | ||
| 319 | |||
| 320 | cpu0_initialized = 1; | ||
| 321 | |||
| 322 | pr->id = cpu_index; | ||
| 323 | |||
| 324 | /* | ||
| 325 | * Extra Processor objects may be enumerated on MP systems with | ||
| 326 | * less than the max # of CPUs. They should be ignored _iff | ||
| 327 | * they are physically not present. | ||
| 328 | */ | ||
| 329 | if (pr->id == -1) { | ||
| 330 | if (ACPI_FAILURE(acpi_processor_hotadd_init(pr))) | ||
| 331 | return -ENODEV; | ||
| 332 | } | ||
| 333 | /* | ||
| 334 | * On some boxes several processors use the same processor bus id. | ||
| 335 | * But they are located in different scope. For example: | ||
| 336 | * \_SB.SCK0.CPU0 | ||
| 337 | * \_SB.SCK1.CPU0 | ||
| 338 | * Rename the processor device bus id. And the new bus id will be | ||
| 339 | * generated as the following format: | ||
| 340 | * CPU+CPU ID. | ||
| 341 | */ | ||
| 342 | sprintf(acpi_device_bid(device), "CPU%X", pr->id); | ||
| 343 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id, | ||
| 344 | pr->acpi_id)); | ||
| 345 | |||
| 346 | if (!object.processor.pblk_address) | ||
| 347 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n")); | ||
| 348 | else if (object.processor.pblk_length != 6) | ||
| 349 | dev_err(&device->dev, "Invalid PBLK length [%d]\n", | ||
| 350 | object.processor.pblk_length); | ||
| 351 | else { | ||
| 352 | pr->throttling.address = object.processor.pblk_address; | ||
| 353 | pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset; | ||
| 354 | pr->throttling.duty_width = acpi_gbl_FADT.duty_width; | ||
| 355 | |||
| 356 | pr->pblk = object.processor.pblk_address; | ||
| 357 | |||
| 358 | /* | ||
| 359 | * We don't care about error returns - we just try to mark | ||
| 360 | * these reserved so that nobody else is confused into thinking | ||
| 361 | * that this region might be unused.. | ||
| 362 | * | ||
| 363 | * (In particular, allocating the IO range for Cardbus) | ||
| 364 | */ | ||
| 365 | request_region(pr->throttling.address, 6, "ACPI CPU throttle"); | ||
| 366 | } | ||
| 367 | |||
| 368 | /* | ||
| 369 | * If ACPI describes a slot number for this CPU, we can use it | ||
| 370 | * ensure we get the right value in the "physical id" field | ||
| 371 | * of /proc/cpuinfo | ||
| 372 | */ | ||
| 373 | status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer); | ||
| 374 | if (ACPI_SUCCESS(status)) | ||
| 375 | arch_fix_phys_package_id(pr->id, object.integer.value); | ||
| 376 | |||
| 377 | return 0; | ||
| 378 | } | ||
| 379 | |||
| 380 | static DEFINE_PER_CPU(void *, processor_device_array); | ||
| 381 | |||
| 382 | static void acpi_processor_notify(struct acpi_device *device, u32 event) | ||
| 383 | { | ||
| 384 | struct acpi_processor *pr = acpi_driver_data(device); | ||
| 385 | int saved; | 85 | int saved; |
| 386 | 86 | ||
| 87 | if (device->handle != handle) | ||
| 88 | return; | ||
| 89 | |||
| 90 | pr = acpi_driver_data(device); | ||
| 387 | if (!pr) | 91 | if (!pr) |
| 388 | return; | 92 | return; |
| 389 | 93 | ||
| @@ -420,55 +124,62 @@ static void acpi_processor_notify(struct acpi_device *device, u32 event) | |||
| 420 | return; | 124 | return; |
| 421 | } | 125 | } |
| 422 | 126 | ||
| 423 | static int acpi_cpu_soft_notify(struct notifier_block *nfb, | 127 | static __cpuinit int __acpi_processor_start(struct acpi_device *device); |
| 424 | unsigned long action, void *hcpu) | 128 | |
| 129 | static int __cpuinit acpi_cpu_soft_notify(struct notifier_block *nfb, | ||
| 130 | unsigned long action, void *hcpu) | ||
| 425 | { | 131 | { |
| 426 | unsigned int cpu = (unsigned long)hcpu; | 132 | unsigned int cpu = (unsigned long)hcpu; |
| 427 | struct acpi_processor *pr = per_cpu(processors, cpu); | 133 | struct acpi_processor *pr = per_cpu(processors, cpu); |
| 134 | struct acpi_device *device; | ||
| 135 | |||
| 136 | if (!pr || acpi_bus_get_device(pr->handle, &device)) | ||
| 137 | return NOTIFY_DONE; | ||
| 428 | 138 | ||
| 429 | if (action == CPU_ONLINE && pr) { | 139 | if (action == CPU_ONLINE) { |
| 430 | /* CPU got physically hotplugged and onlined the first time: | 140 | /* |
| 431 | * Initialize missing things | 141 | * CPU got physically hotplugged and onlined for the first time: |
| 142 | * Initialize missing things. | ||
| 432 | */ | 143 | */ |
| 433 | if (pr->flags.need_hotplug_init) { | 144 | if (pr->flags.need_hotplug_init) { |
| 145 | int ret; | ||
| 146 | |||
| 434 | pr_info("Will online and init hotplugged CPU: %d\n", | 147 | pr_info("Will online and init hotplugged CPU: %d\n", |
| 435 | pr->id); | 148 | pr->id); |
| 436 | WARN(acpi_processor_start(pr), "Failed to start CPU:" | ||
| 437 | " %d\n", pr->id); | ||
| 438 | pr->flags.need_hotplug_init = 0; | 149 | pr->flags.need_hotplug_init = 0; |
| 439 | /* Normal CPU soft online event */ | 150 | ret = __acpi_processor_start(device); |
| 151 | WARN(ret, "Failed to start CPU: %d\n", pr->id); | ||
| 440 | } else { | 152 | } else { |
| 153 | /* Normal CPU soft online event. */ | ||
| 441 | acpi_processor_ppc_has_changed(pr, 0); | 154 | acpi_processor_ppc_has_changed(pr, 0); |
| 442 | acpi_processor_hotplug(pr); | 155 | acpi_processor_hotplug(pr); |
| 443 | acpi_processor_reevaluate_tstate(pr, action); | 156 | acpi_processor_reevaluate_tstate(pr, action); |
| 444 | acpi_processor_tstate_has_changed(pr); | 157 | acpi_processor_tstate_has_changed(pr); |
| 445 | } | 158 | } |
| 446 | } | 159 | } else if (action == CPU_DEAD) { |
| 447 | if (action == CPU_DEAD && pr) { | 160 | /* Invalidate flag.throttling after the CPU is offline. */ |
| 448 | /* invalidate the flag.throttling after one CPU is offline */ | ||
| 449 | acpi_processor_reevaluate_tstate(pr, action); | 161 | acpi_processor_reevaluate_tstate(pr, action); |
| 450 | } | 162 | } |
| 451 | return NOTIFY_OK; | 163 | return NOTIFY_OK; |
| 452 | } | 164 | } |
| 453 | 165 | ||
| 454 | static struct notifier_block acpi_cpu_notifier = | 166 | static struct notifier_block __refdata acpi_cpu_notifier = |
| 455 | { | 167 | { |
| 456 | .notifier_call = acpi_cpu_soft_notify, | 168 | .notifier_call = acpi_cpu_soft_notify, |
| 457 | }; | 169 | }; |
| 458 | 170 | ||
| 459 | /* | 171 | static __cpuinit int __acpi_processor_start(struct acpi_device *device) |
| 460 | * acpi_processor_start() is called by the cpu_hotplug_notifier func: | ||
| 461 | * acpi_cpu_soft_notify(). Getting it __cpuinit{data} is difficult, the | ||
| 462 | * root cause seem to be that acpi_processor_uninstall_hotplug_notify() | ||
| 463 | * is in the module_exit (__exit) func. Allowing acpi_processor_start() | ||
| 464 | * to not be in __cpuinit section, but being called from __cpuinit funcs | ||
| 465 | * via __ref looks like the right thing to do here. | ||
| 466 | */ | ||
| 467 | static __ref int acpi_processor_start(struct acpi_processor *pr) | ||
| 468 | { | 172 | { |
| 469 | struct acpi_device *device = per_cpu(processor_device_array, pr->id); | 173 | struct acpi_processor *pr = acpi_driver_data(device); |
| 174 | acpi_status status; | ||
| 470 | int result = 0; | 175 | int result = 0; |
| 471 | 176 | ||
| 177 | if (!pr) | ||
| 178 | return -ENODEV; | ||
| 179 | |||
| 180 | if (pr->flags.need_hotplug_init) | ||
| 181 | return 0; | ||
| 182 | |||
| 472 | #ifdef CONFIG_CPU_FREQ | 183 | #ifdef CONFIG_CPU_FREQ |
| 473 | acpi_processor_ppc_has_changed(pr, 0); | 184 | acpi_processor_ppc_has_changed(pr, 0); |
| 474 | acpi_processor_load_module(pr); | 185 | acpi_processor_load_module(pr); |
| @@ -506,462 +217,95 @@ static __ref int acpi_processor_start(struct acpi_processor *pr) | |||
| 506 | goto err_remove_sysfs_thermal; | 217 | goto err_remove_sysfs_thermal; |
| 507 | } | 218 | } |
| 508 | 219 | ||
| 509 | return 0; | 220 | status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, |
| 221 | acpi_processor_notify, device); | ||
| 222 | if (ACPI_SUCCESS(status)) | ||
| 223 | return 0; | ||
| 510 | 224 | ||
| 511 | err_remove_sysfs_thermal: | 225 | sysfs_remove_link(&pr->cdev->device.kobj, "device"); |
| 226 | err_remove_sysfs_thermal: | ||
| 512 | sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); | 227 | sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); |
| 513 | err_thermal_unregister: | 228 | err_thermal_unregister: |
| 514 | thermal_cooling_device_unregister(pr->cdev); | 229 | thermal_cooling_device_unregister(pr->cdev); |
| 515 | err_power_exit: | 230 | err_power_exit: |
| 516 | acpi_processor_power_exit(pr); | 231 | acpi_processor_power_exit(pr); |
| 517 | |||
| 518 | return result; | 232 | return result; |
| 519 | } | 233 | } |
| 520 | 234 | ||
| 521 | /* | 235 | static int __cpuinit acpi_processor_start(struct device *dev) |
| 522 | * Do not put anything in here which needs the core to be online. | ||
| 523 | * For example MSR access or setting up things which check for cpuinfo_x86 | ||
| 524 | * (cpu_data(cpu)) values, like CPU feature flags, family, model, etc. | ||
| 525 | * Such things have to be put in and set up above in acpi_processor_start() | ||
| 526 | */ | ||
| 527 | static int __cpuinit acpi_processor_add(struct acpi_device *device) | ||
| 528 | { | 236 | { |
| 529 | struct acpi_processor *pr = NULL; | 237 | struct acpi_device *device; |
| 530 | int result = 0; | ||
| 531 | struct device *dev; | ||
| 532 | |||
| 533 | pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); | ||
| 534 | if (!pr) | ||
| 535 | return -ENOMEM; | ||
| 536 | |||
| 537 | if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) { | ||
| 538 | result = -ENOMEM; | ||
| 539 | goto err_free_pr; | ||
| 540 | } | ||
| 541 | |||
| 542 | pr->handle = device->handle; | ||
| 543 | strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME); | ||
| 544 | strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS); | ||
| 545 | device->driver_data = pr; | ||
| 546 | |||
| 547 | result = acpi_processor_get_info(device); | ||
| 548 | if (result) { | ||
| 549 | /* Processor is physically not present */ | ||
| 550 | return 0; | ||
| 551 | } | ||
| 552 | |||
| 553 | #ifdef CONFIG_SMP | ||
| 554 | if (pr->id >= setup_max_cpus && pr->id != 0) | ||
| 555 | return 0; | ||
| 556 | #endif | ||
| 557 | |||
| 558 | BUG_ON(pr->id >= nr_cpu_ids); | ||
| 559 | |||
| 560 | /* | ||
| 561 | * Buggy BIOS check | ||
| 562 | * ACPI id of processors can be reported wrongly by the BIOS. | ||
| 563 | * Don't trust it blindly | ||
| 564 | */ | ||
| 565 | if (per_cpu(processor_device_array, pr->id) != NULL && | ||
| 566 | per_cpu(processor_device_array, pr->id) != device) { | ||
| 567 | dev_warn(&device->dev, | ||
| 568 | "BIOS reported wrong ACPI id %d for the processor\n", | ||
| 569 | pr->id); | ||
| 570 | result = -ENODEV; | ||
| 571 | goto err_free_cpumask; | ||
| 572 | } | ||
| 573 | per_cpu(processor_device_array, pr->id) = device; | ||
| 574 | |||
| 575 | per_cpu(processors, pr->id) = pr; | ||
| 576 | |||
| 577 | dev = get_cpu_device(pr->id); | ||
| 578 | if (sysfs_create_link(&device->dev.kobj, &dev->kobj, "sysdev")) { | ||
| 579 | result = -EFAULT; | ||
| 580 | goto err_clear_processor; | ||
| 581 | } | ||
| 582 | 238 | ||
| 583 | /* | 239 | if (acpi_bus_get_device(ACPI_HANDLE(dev), &device)) |
| 584 | * Do not start hotplugged CPUs now, but when they | 240 | return -ENODEV; |
| 585 | * are onlined the first time | ||
| 586 | */ | ||
| 587 | if (pr->flags.need_hotplug_init) | ||
| 588 | return 0; | ||
| 589 | |||
| 590 | result = acpi_processor_start(pr); | ||
| 591 | if (result) | ||
| 592 | goto err_remove_sysfs; | ||
| 593 | |||
| 594 | return 0; | ||
| 595 | 241 | ||
| 596 | err_remove_sysfs: | 242 | return __acpi_processor_start(device); |
| 597 | sysfs_remove_link(&device->dev.kobj, "sysdev"); | ||
| 598 | err_clear_processor: | ||
| 599 | /* | ||
| 600 | * processor_device_array is not cleared to allow checks for buggy BIOS | ||
| 601 | */ | ||
| 602 | per_cpu(processors, pr->id) = NULL; | ||
| 603 | err_free_cpumask: | ||
| 604 | free_cpumask_var(pr->throttling.shared_cpu_map); | ||
| 605 | err_free_pr: | ||
| 606 | kfree(pr); | ||
| 607 | return result; | ||
| 608 | } | 243 | } |
| 609 | 244 | ||
| 610 | static int acpi_processor_remove(struct acpi_device *device) | 245 | static int acpi_processor_stop(struct device *dev) |
| 611 | { | 246 | { |
| 612 | struct acpi_processor *pr = NULL; | 247 | struct acpi_device *device; |
| 248 | struct acpi_processor *pr; | ||
| 613 | 249 | ||
| 250 | if (acpi_bus_get_device(ACPI_HANDLE(dev), &device)) | ||
| 251 | return 0; | ||
| 614 | 252 | ||
| 615 | if (!device || !acpi_driver_data(device)) | 253 | acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, |
| 616 | return -EINVAL; | 254 | acpi_processor_notify); |
| 617 | 255 | ||
| 618 | pr = acpi_driver_data(device); | 256 | pr = acpi_driver_data(device); |
| 619 | 257 | if (!pr) | |
| 620 | if (pr->id >= nr_cpu_ids) | 258 | return 0; |
| 621 | goto free; | ||
| 622 | |||
| 623 | if (device->removal_type == ACPI_BUS_REMOVAL_EJECT) { | ||
| 624 | if (acpi_processor_handle_eject(pr)) | ||
| 625 | return -EINVAL; | ||
| 626 | } | ||
| 627 | 259 | ||
| 628 | acpi_processor_power_exit(pr); | 260 | acpi_processor_power_exit(pr); |
| 629 | 261 | ||
| 630 | sysfs_remove_link(&device->dev.kobj, "sysdev"); | ||
| 631 | |||
| 632 | if (pr->cdev) { | 262 | if (pr->cdev) { |
| 633 | sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); | 263 | sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); |
| 634 | sysfs_remove_link(&pr->cdev->device.kobj, "device"); | 264 | sysfs_remove_link(&pr->cdev->device.kobj, "device"); |
| 635 | thermal_cooling_device_unregister(pr->cdev); | 265 | thermal_cooling_device_unregister(pr->cdev); |
| 636 | pr->cdev = NULL; | 266 | pr->cdev = NULL; |
| 637 | } | 267 | } |
| 638 | |||
| 639 | per_cpu(processors, pr->id) = NULL; | ||
| 640 | per_cpu(processor_device_array, pr->id) = NULL; | ||
| 641 | try_offline_node(cpu_to_node(pr->id)); | ||
| 642 | |||
| 643 | free: | ||
| 644 | free_cpumask_var(pr->throttling.shared_cpu_map); | ||
| 645 | kfree(pr); | ||
| 646 | |||
| 647 | return 0; | 268 | return 0; |
| 648 | } | 269 | } |
| 649 | 270 | ||
| 650 | #ifdef CONFIG_ACPI_HOTPLUG_CPU | ||
| 651 | /**************************************************************************** | ||
| 652 | * Acpi processor hotplug support * | ||
| 653 | ****************************************************************************/ | ||
| 654 | |||
| 655 | static int is_processor_present(acpi_handle handle) | ||
| 656 | { | ||
| 657 | acpi_status status; | ||
| 658 | unsigned long long sta = 0; | ||
| 659 | |||
| 660 | |||
| 661 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); | ||
| 662 | |||
| 663 | if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT)) | ||
| 664 | return 1; | ||
| 665 | |||
| 666 | /* | ||
| 667 | * _STA is mandatory for a processor that supports hot plug | ||
| 668 | */ | ||
| 669 | if (status == AE_NOT_FOUND) | ||
| 670 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 671 | "Processor does not support hot plug\n")); | ||
| 672 | else | ||
| 673 | ACPI_EXCEPTION((AE_INFO, status, | ||
| 674 | "Processor Device is not present")); | ||
| 675 | return 0; | ||
| 676 | } | ||
| 677 | |||
| 678 | static void acpi_processor_hotplug_notify(acpi_handle handle, | ||
| 679 | u32 event, void *data) | ||
| 680 | { | ||
| 681 | struct acpi_device *device = NULL; | ||
| 682 | struct acpi_eject_event *ej_event = NULL; | ||
| 683 | u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; /* default */ | ||
| 684 | acpi_status status; | ||
| 685 | int result; | ||
| 686 | |||
| 687 | acpi_scan_lock_acquire(); | ||
| 688 | |||
| 689 | switch (event) { | ||
| 690 | case ACPI_NOTIFY_BUS_CHECK: | ||
| 691 | case ACPI_NOTIFY_DEVICE_CHECK: | ||
| 692 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 693 | "Processor driver received %s event\n", | ||
| 694 | (event == ACPI_NOTIFY_BUS_CHECK) ? | ||
| 695 | "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK")); | ||
| 696 | |||
| 697 | if (!is_processor_present(handle)) | ||
| 698 | break; | ||
| 699 | |||
| 700 | if (!acpi_bus_get_device(handle, &device)) | ||
| 701 | break; | ||
| 702 | |||
| 703 | result = acpi_bus_scan(handle); | ||
| 704 | if (result) { | ||
| 705 | acpi_handle_err(handle, "Unable to add the device\n"); | ||
| 706 | break; | ||
| 707 | } | ||
| 708 | result = acpi_bus_get_device(handle, &device); | ||
| 709 | if (result) { | ||
| 710 | acpi_handle_err(handle, "Missing device object\n"); | ||
| 711 | break; | ||
| 712 | } | ||
| 713 | ost_code = ACPI_OST_SC_SUCCESS; | ||
| 714 | break; | ||
| 715 | |||
| 716 | case ACPI_NOTIFY_EJECT_REQUEST: | ||
| 717 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 718 | "received ACPI_NOTIFY_EJECT_REQUEST\n")); | ||
| 719 | |||
| 720 | if (acpi_bus_get_device(handle, &device)) { | ||
| 721 | acpi_handle_err(handle, | ||
| 722 | "Device don't exist, dropping EJECT\n"); | ||
| 723 | break; | ||
| 724 | } | ||
| 725 | if (!acpi_driver_data(device)) { | ||
| 726 | acpi_handle_err(handle, | ||
| 727 | "Driver data is NULL, dropping EJECT\n"); | ||
| 728 | break; | ||
| 729 | } | ||
| 730 | |||
| 731 | ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL); | ||
| 732 | if (!ej_event) { | ||
| 733 | acpi_handle_err(handle, "No memory, dropping EJECT\n"); | ||
| 734 | break; | ||
| 735 | } | ||
| 736 | |||
| 737 | get_device(&device->dev); | ||
| 738 | ej_event->device = device; | ||
| 739 | ej_event->event = ACPI_NOTIFY_EJECT_REQUEST; | ||
| 740 | /* The eject is carried out asynchronously. */ | ||
| 741 | status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device, | ||
| 742 | ej_event); | ||
| 743 | if (ACPI_FAILURE(status)) { | ||
| 744 | put_device(&device->dev); | ||
| 745 | kfree(ej_event); | ||
| 746 | break; | ||
| 747 | } | ||
| 748 | goto out; | ||
| 749 | |||
| 750 | default: | ||
| 751 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
| 752 | "Unsupported event [0x%x]\n", event)); | ||
| 753 | |||
| 754 | /* non-hotplug event; possibly handled by other handler */ | ||
| 755 | goto out; | ||
| 756 | } | ||
| 757 | |||
| 758 | /* Inform firmware that the hotplug operation has completed */ | ||
| 759 | (void) acpi_evaluate_hotplug_ost(handle, event, ost_code, NULL); | ||
| 760 | |||
| 761 | out: | ||
| 762 | acpi_scan_lock_release(); | ||
| 763 | } | ||
| 764 | |||
| 765 | static acpi_status is_processor_device(acpi_handle handle) | ||
| 766 | { | ||
| 767 | struct acpi_device_info *info; | ||
| 768 | char *hid; | ||
| 769 | acpi_status status; | ||
| 770 | |||
| 771 | status = acpi_get_object_info(handle, &info); | ||
| 772 | if (ACPI_FAILURE(status)) | ||
| 773 | return status; | ||
| 774 | |||
| 775 | if (info->type == ACPI_TYPE_PROCESSOR) { | ||
| 776 | kfree(info); | ||
| 777 | return AE_OK; /* found a processor object */ | ||
| 778 | } | ||
| 779 | |||
| 780 | if (!(info->valid & ACPI_VALID_HID)) { | ||
| 781 | kfree(info); | ||
| 782 | return AE_ERROR; | ||
| 783 | } | ||
| 784 | |||
| 785 | hid = info->hardware_id.string; | ||
| 786 | if ((hid == NULL) || strcmp(hid, ACPI_PROCESSOR_DEVICE_HID)) { | ||
| 787 | kfree(info); | ||
| 788 | return AE_ERROR; | ||
| 789 | } | ||
| 790 | |||
| 791 | kfree(info); | ||
| 792 | return AE_OK; /* found a processor device object */ | ||
| 793 | } | ||
| 794 | |||
| 795 | static acpi_status | ||
| 796 | processor_walk_namespace_cb(acpi_handle handle, | ||
| 797 | u32 lvl, void *context, void **rv) | ||
| 798 | { | ||
| 799 | acpi_status status; | ||
| 800 | int *action = context; | ||
| 801 | |||
| 802 | status = is_processor_device(handle); | ||
| 803 | if (ACPI_FAILURE(status)) | ||
| 804 | return AE_OK; /* not a processor; continue to walk */ | ||
| 805 | |||
| 806 | switch (*action) { | ||
| 807 | case INSTALL_NOTIFY_HANDLER: | ||
| 808 | acpi_install_notify_handler(handle, | ||
| 809 | ACPI_SYSTEM_NOTIFY, | ||
| 810 | acpi_processor_hotplug_notify, | ||
| 811 | NULL); | ||
| 812 | break; | ||
| 813 | case UNINSTALL_NOTIFY_HANDLER: | ||
| 814 | acpi_remove_notify_handler(handle, | ||
| 815 | ACPI_SYSTEM_NOTIFY, | ||
| 816 | acpi_processor_hotplug_notify); | ||
| 817 | break; | ||
| 818 | default: | ||
| 819 | break; | ||
| 820 | } | ||
| 821 | |||
| 822 | /* found a processor; skip walking underneath */ | ||
| 823 | return AE_CTRL_DEPTH; | ||
| 824 | } | ||
| 825 | |||
| 826 | static acpi_status acpi_processor_hotadd_init(struct acpi_processor *pr) | ||
| 827 | { | ||
| 828 | acpi_handle handle = pr->handle; | ||
| 829 | |||
| 830 | if (!is_processor_present(handle)) { | ||
| 831 | return AE_ERROR; | ||
| 832 | } | ||
| 833 | |||
| 834 | if (acpi_map_lsapic(handle, &pr->id)) | ||
| 835 | return AE_ERROR; | ||
| 836 | |||
| 837 | if (arch_register_cpu(pr->id)) { | ||
| 838 | acpi_unmap_lsapic(pr->id); | ||
| 839 | return AE_ERROR; | ||
| 840 | } | ||
| 841 | |||
| 842 | /* CPU got hot-plugged, but cpu_data is not initialized yet | ||
| 843 | * Set flag to delay cpu_idle/throttling initialization | ||
| 844 | * in: | ||
| 845 | * acpi_processor_add() | ||
| 846 | * acpi_processor_get_info() | ||
| 847 | * and do it when the CPU gets online the first time | ||
| 848 | * TBD: Cleanup above functions and try to do this more elegant. | ||
| 849 | */ | ||
| 850 | pr_info("CPU %d got hotplugged\n", pr->id); | ||
| 851 | pr->flags.need_hotplug_init = 1; | ||
| 852 | |||
| 853 | return AE_OK; | ||
| 854 | } | ||
| 855 | |||
| 856 | static int acpi_processor_handle_eject(struct acpi_processor *pr) | ||
| 857 | { | ||
| 858 | if (cpu_online(pr->id)) | ||
| 859 | cpu_down(pr->id); | ||
| 860 | |||
| 861 | get_online_cpus(); | ||
| 862 | /* | ||
| 863 | * The cpu might become online again at this point. So we check whether | ||
| 864 | * the cpu has been onlined or not. If the cpu became online, it means | ||
| 865 | * that someone wants to use the cpu. So acpi_processor_handle_eject() | ||
| 866 | * returns -EAGAIN. | ||
| 867 | */ | ||
| 868 | if (unlikely(cpu_online(pr->id))) { | ||
| 869 | put_online_cpus(); | ||
| 870 | pr_warn("Failed to remove CPU %d, because other task " | ||
| 871 | "brought the CPU back online\n", pr->id); | ||
| 872 | return -EAGAIN; | ||
| 873 | } | ||
| 874 | arch_unregister_cpu(pr->id); | ||
| 875 | acpi_unmap_lsapic(pr->id); | ||
| 876 | put_online_cpus(); | ||
| 877 | return (0); | ||
| 878 | } | ||
| 879 | #else | ||
| 880 | static acpi_status acpi_processor_hotadd_init(struct acpi_processor *pr) | ||
| 881 | { | ||
| 882 | return AE_ERROR; | ||
| 883 | } | ||
| 884 | static int acpi_processor_handle_eject(struct acpi_processor *pr) | ||
| 885 | { | ||
| 886 | return (-EINVAL); | ||
| 887 | } | ||
| 888 | #endif | ||
| 889 | |||
| 890 | static | ||
| 891 | void acpi_processor_install_hotplug_notify(void) | ||
| 892 | { | ||
| 893 | #ifdef CONFIG_ACPI_HOTPLUG_CPU | ||
| 894 | int action = INSTALL_NOTIFY_HANDLER; | ||
| 895 | acpi_walk_namespace(ACPI_TYPE_ANY, | ||
| 896 | ACPI_ROOT_OBJECT, | ||
| 897 | ACPI_UINT32_MAX, | ||
| 898 | processor_walk_namespace_cb, NULL, &action, NULL); | ||
| 899 | #endif | ||
| 900 | register_hotcpu_notifier(&acpi_cpu_notifier); | ||
| 901 | } | ||
| 902 | |||
| 903 | static | ||
| 904 | void acpi_processor_uninstall_hotplug_notify(void) | ||
| 905 | { | ||
| 906 | #ifdef CONFIG_ACPI_HOTPLUG_CPU | ||
| 907 | int action = UNINSTALL_NOTIFY_HANDLER; | ||
| 908 | acpi_walk_namespace(ACPI_TYPE_ANY, | ||
| 909 | ACPI_ROOT_OBJECT, | ||
| 910 | ACPI_UINT32_MAX, | ||
| 911 | processor_walk_namespace_cb, NULL, &action, NULL); | ||
| 912 | #endif | ||
| 913 | unregister_hotcpu_notifier(&acpi_cpu_notifier); | ||
| 914 | } | ||
| 915 | |||
| 916 | /* | 271 | /* |
| 917 | * We keep the driver loaded even when ACPI is not running. | 272 | * We keep the driver loaded even when ACPI is not running. |
| 918 | * This is needed for the powernow-k8 driver, that works even without | 273 | * This is needed for the powernow-k8 driver, that works even without |
| 919 | * ACPI, but needs symbols from this driver | 274 | * ACPI, but needs symbols from this driver |
| 920 | */ | 275 | */ |
| 921 | 276 | ||
| 922 | static int __init acpi_processor_init(void) | 277 | static int __init acpi_processor_driver_init(void) |
| 923 | { | 278 | { |
| 924 | int result = 0; | 279 | int result = 0; |
| 925 | 280 | ||
| 926 | if (acpi_disabled) | 281 | if (acpi_disabled) |
| 927 | return 0; | 282 | return 0; |
| 928 | 283 | ||
| 929 | result = acpi_bus_register_driver(&acpi_processor_driver); | 284 | result = driver_register(&acpi_processor_driver); |
| 930 | if (result < 0) | 285 | if (result < 0) |
| 931 | return result; | 286 | return result; |
| 932 | 287 | ||
| 933 | acpi_processor_syscore_init(); | 288 | acpi_processor_syscore_init(); |
| 934 | 289 | register_hotcpu_notifier(&acpi_cpu_notifier); | |
| 935 | acpi_processor_install_hotplug_notify(); | ||
| 936 | |||
| 937 | acpi_thermal_cpufreq_init(); | 290 | acpi_thermal_cpufreq_init(); |
| 938 | |||
| 939 | acpi_processor_ppc_init(); | 291 | acpi_processor_ppc_init(); |
| 940 | |||
| 941 | acpi_processor_throttling_init(); | 292 | acpi_processor_throttling_init(); |
| 942 | |||
| 943 | return 0; | 293 | return 0; |
| 944 | } | 294 | } |
| 945 | 295 | ||
| 946 | static void __exit acpi_processor_exit(void) | 296 | static void __exit acpi_processor_driver_exit(void) |
| 947 | { | 297 | { |
| 948 | if (acpi_disabled) | 298 | if (acpi_disabled) |
| 949 | return; | 299 | return; |
| 950 | 300 | ||
| 951 | acpi_processor_ppc_exit(); | 301 | acpi_processor_ppc_exit(); |
| 952 | |||
| 953 | acpi_thermal_cpufreq_exit(); | 302 | acpi_thermal_cpufreq_exit(); |
| 954 | 303 | unregister_hotcpu_notifier(&acpi_cpu_notifier); | |
| 955 | acpi_processor_uninstall_hotplug_notify(); | ||
| 956 | |||
| 957 | acpi_processor_syscore_exit(); | 304 | acpi_processor_syscore_exit(); |
| 958 | 305 | driver_unregister(&acpi_processor_driver); | |
| 959 | acpi_bus_unregister_driver(&acpi_processor_driver); | ||
| 960 | |||
| 961 | return; | ||
| 962 | } | 306 | } |
| 963 | 307 | ||
| 964 | module_init(acpi_processor_init); | 308 | module_init(acpi_processor_driver_init); |
| 965 | module_exit(acpi_processor_exit); | 309 | module_exit(acpi_processor_driver_exit); |
| 966 | 310 | ||
| 967 | MODULE_ALIAS("processor"); | 311 | MODULE_ALIAS("processor"); |
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 27da63061e11..db118b1ad3e8 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
| @@ -27,6 +27,12 @@ extern struct acpi_device *acpi_root; | |||
| 27 | 27 | ||
| 28 | #define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent) | 28 | #define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent) |
| 29 | 29 | ||
| 30 | /* | ||
| 31 | * If set, devices will be hot-removed even if they cannot be put offline | ||
| 32 | * gracefully (from the kernel's standpoint). | ||
| 33 | */ | ||
| 34 | bool acpi_force_hot_remove; | ||
| 35 | |||
| 30 | static const char *dummy_hid = "device"; | 36 | static const char *dummy_hid = "device"; |
| 31 | 37 | ||
| 32 | static LIST_HEAD(acpi_device_list); | 38 | static LIST_HEAD(acpi_device_list); |
| @@ -120,12 +126,78 @@ acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, cha | |||
| 120 | } | 126 | } |
| 121 | static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL); | 127 | static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL); |
| 122 | 128 | ||
| 129 | static acpi_status acpi_bus_offline_companions(acpi_handle handle, u32 lvl, | ||
| 130 | void *data, void **ret_p) | ||
| 131 | { | ||
| 132 | struct acpi_device *device = NULL; | ||
| 133 | struct acpi_device_physical_node *pn; | ||
| 134 | bool second_pass = (bool)data; | ||
| 135 | acpi_status status = AE_OK; | ||
| 136 | |||
| 137 | if (acpi_bus_get_device(handle, &device)) | ||
| 138 | return AE_OK; | ||
| 139 | |||
| 140 | mutex_lock(&device->physical_node_lock); | ||
| 141 | |||
| 142 | list_for_each_entry(pn, &device->physical_node_list, node) { | ||
| 143 | int ret; | ||
| 144 | |||
| 145 | if (second_pass) { | ||
| 146 | /* Skip devices offlined by the first pass. */ | ||
| 147 | if (pn->put_online) | ||
| 148 | continue; | ||
| 149 | } else { | ||
| 150 | pn->put_online = false; | ||
| 151 | } | ||
| 152 | ret = device_offline(pn->dev); | ||
| 153 | if (acpi_force_hot_remove) | ||
| 154 | continue; | ||
| 155 | |||
| 156 | if (ret >= 0) { | ||
| 157 | pn->put_online = !ret; | ||
| 158 | } else { | ||
| 159 | *ret_p = pn->dev; | ||
| 160 | if (second_pass) { | ||
| 161 | status = AE_ERROR; | ||
| 162 | break; | ||
| 163 | } | ||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | mutex_unlock(&device->physical_node_lock); | ||
| 168 | |||
| 169 | return status; | ||
| 170 | } | ||
| 171 | |||
| 172 | static acpi_status acpi_bus_online_companions(acpi_handle handle, u32 lvl, | ||
| 173 | void *data, void **ret_p) | ||
| 174 | { | ||
| 175 | struct acpi_device *device = NULL; | ||
| 176 | struct acpi_device_physical_node *pn; | ||
| 177 | |||
| 178 | if (acpi_bus_get_device(handle, &device)) | ||
| 179 | return AE_OK; | ||
| 180 | |||
| 181 | mutex_lock(&device->physical_node_lock); | ||
| 182 | |||
| 183 | list_for_each_entry(pn, &device->physical_node_list, node) | ||
| 184 | if (pn->put_online) { | ||
| 185 | device_online(pn->dev); | ||
| 186 | pn->put_online = false; | ||
| 187 | } | ||
| 188 | |||
| 189 | mutex_unlock(&device->physical_node_lock); | ||
| 190 | |||
| 191 | return AE_OK; | ||
| 192 | } | ||
| 193 | |||
| 123 | static int acpi_scan_hot_remove(struct acpi_device *device) | 194 | static int acpi_scan_hot_remove(struct acpi_device *device) |
| 124 | { | 195 | { |
| 125 | acpi_handle handle = device->handle; | 196 | acpi_handle handle = device->handle; |
| 126 | acpi_handle not_used; | 197 | acpi_handle not_used; |
| 127 | struct acpi_object_list arg_list; | 198 | struct acpi_object_list arg_list; |
| 128 | union acpi_object arg; | 199 | union acpi_object arg; |
| 200 | struct device *errdev; | ||
| 129 | acpi_status status; | 201 | acpi_status status; |
| 130 | unsigned long long sta; | 202 | unsigned long long sta; |
| 131 | 203 | ||
| @@ -136,10 +208,53 @@ static int acpi_scan_hot_remove(struct acpi_device *device) | |||
| 136 | return -EINVAL; | 208 | return -EINVAL; |
| 137 | } | 209 | } |
| 138 | 210 | ||
| 211 | lock_device_hotplug(); | ||
| 212 | |||
| 213 | /* | ||
| 214 | * Carry out two passes here and ignore errors in the first pass, | ||
| 215 | * because if the devices in question are memory blocks and | ||
| 216 | * CONFIG_MEMCG is set, one of the blocks may hold data structures | ||
| 217 | * that the other blocks depend on, but it is not known in advance which | ||
| 218 | * block holds them. | ||
| 219 | * | ||
| 220 | * If the first pass is successful, the second one isn't needed, though. | ||
| 221 | */ | ||
| 222 | errdev = NULL; | ||
| 223 | acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, | ||
| 224 | NULL, acpi_bus_offline_companions, | ||
| 225 | (void *)false, (void **)&errdev); | ||
| 226 | acpi_bus_offline_companions(handle, 0, (void *)false, (void **)&errdev); | ||
| 227 | if (errdev) { | ||
| 228 | errdev = NULL; | ||
| 229 | acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, | ||
| 230 | NULL, acpi_bus_offline_companions, | ||
| 231 | (void *)true , (void **)&errdev); | ||
| 232 | if (!errdev || acpi_force_hot_remove) | ||
| 233 | acpi_bus_offline_companions(handle, 0, (void *)true, | ||
| 234 | (void **)&errdev); | ||
| 235 | |||
| 236 | if (errdev && !acpi_force_hot_remove) { | ||
| 237 | dev_warn(errdev, "Offline failed.\n"); | ||
| 238 | acpi_bus_online_companions(handle, 0, NULL, NULL); | ||
| 239 | acpi_walk_namespace(ACPI_TYPE_ANY, handle, | ||
| 240 | ACPI_UINT32_MAX, | ||
| 241 | acpi_bus_online_companions, NULL, | ||
| 242 | NULL, NULL); | ||
| 243 | |||
| 244 | unlock_device_hotplug(); | ||
| 245 | |||
| 246 | put_device(&device->dev); | ||
| 247 | return -EBUSY; | ||
| 248 | } | ||
| 249 | } | ||
| 250 | |||
| 139 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 251 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 140 | "Hot-removing device %s...\n", dev_name(&device->dev))); | 252 | "Hot-removing device %s...\n", dev_name(&device->dev))); |
| 141 | 253 | ||
| 142 | acpi_bus_trim(device); | 254 | acpi_bus_trim(device); |
| 255 | |||
| 256 | unlock_device_hotplug(); | ||
| 257 | |||
| 143 | /* Device node has been unregistered. */ | 258 | /* Device node has been unregistered. */ |
| 144 | put_device(&device->dev); | 259 | put_device(&device->dev); |
| 145 | device = NULL; | 260 | device = NULL; |
| @@ -236,6 +351,7 @@ static void acpi_scan_bus_device_check(acpi_handle handle, u32 ost_source) | |||
| 236 | int error; | 351 | int error; |
| 237 | 352 | ||
| 238 | mutex_lock(&acpi_scan_lock); | 353 | mutex_lock(&acpi_scan_lock); |
| 354 | lock_device_hotplug(); | ||
| 239 | 355 | ||
| 240 | acpi_bus_get_device(handle, &device); | 356 | acpi_bus_get_device(handle, &device); |
| 241 | if (device) { | 357 | if (device) { |
| @@ -259,6 +375,7 @@ static void acpi_scan_bus_device_check(acpi_handle handle, u32 ost_source) | |||
| 259 | kobject_uevent(&device->dev.kobj, KOBJ_ONLINE); | 375 | kobject_uevent(&device->dev.kobj, KOBJ_ONLINE); |
| 260 | 376 | ||
| 261 | out: | 377 | out: |
| 378 | unlock_device_hotplug(); | ||
| 262 | acpi_evaluate_hotplug_ost(handle, ost_source, ost_code, NULL); | 379 | acpi_evaluate_hotplug_ost(handle, ost_source, ost_code, NULL); |
| 263 | mutex_unlock(&acpi_scan_lock); | 380 | mutex_unlock(&acpi_scan_lock); |
| 264 | } | 381 | } |
| @@ -952,7 +1069,6 @@ int acpi_device_add(struct acpi_device *device, | |||
| 952 | printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n", | 1069 | printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n", |
| 953 | dev_name(&device->dev)); | 1070 | dev_name(&device->dev)); |
| 954 | 1071 | ||
| 955 | device->removal_type = ACPI_BUS_REMOVAL_NORMAL; | ||
| 956 | return 0; | 1072 | return 0; |
| 957 | 1073 | ||
| 958 | err: | 1074 | err: |
| @@ -1939,7 +2055,6 @@ static acpi_status acpi_bus_device_detach(acpi_handle handle, u32 lvl_not_used, | |||
| 1939 | if (!acpi_bus_get_device(handle, &device)) { | 2055 | if (!acpi_bus_get_device(handle, &device)) { |
| 1940 | struct acpi_scan_handler *dev_handler = device->handler; | 2056 | struct acpi_scan_handler *dev_handler = device->handler; |
| 1941 | 2057 | ||
| 1942 | device->removal_type = ACPI_BUS_REMOVAL_EJECT; | ||
| 1943 | if (dev_handler) { | 2058 | if (dev_handler) { |
| 1944 | if (dev_handler->detach) | 2059 | if (dev_handler->detach) |
| 1945 | dev_handler->detach(device); | 2060 | dev_handler->detach(device); |
| @@ -2038,6 +2153,7 @@ int __init acpi_scan_init(void) | |||
| 2038 | 2153 | ||
| 2039 | acpi_pci_root_init(); | 2154 | acpi_pci_root_init(); |
| 2040 | acpi_pci_link_init(); | 2155 | acpi_pci_link_init(); |
| 2156 | acpi_processor_init(); | ||
| 2041 | acpi_platform_init(); | 2157 | acpi_platform_init(); |
| 2042 | acpi_lpss_init(); | 2158 | acpi_lpss_init(); |
| 2043 | acpi_container_init(); | 2159 | acpi_container_init(); |
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c index fcae5fa2e1b3..5c5d1624fa2c 100644 --- a/drivers/acpi/sysfs.c +++ b/drivers/acpi/sysfs.c | |||
| @@ -780,6 +780,33 @@ void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug, | |||
| 780 | pr_err(PREFIX "Unable to add hotplug profile '%s'\n", name); | 780 | pr_err(PREFIX "Unable to add hotplug profile '%s'\n", name); |
| 781 | } | 781 | } |
| 782 | 782 | ||
| 783 | static ssize_t force_remove_show(struct kobject *kobj, | ||
| 784 | struct kobj_attribute *attr, char *buf) | ||
| 785 | { | ||
| 786 | return sprintf(buf, "%d\n", !!acpi_force_hot_remove); | ||
| 787 | } | ||
| 788 | |||
| 789 | static ssize_t force_remove_store(struct kobject *kobj, | ||
| 790 | struct kobj_attribute *attr, | ||
| 791 | const char *buf, size_t size) | ||
| 792 | { | ||
| 793 | bool val; | ||
| 794 | int ret; | ||
| 795 | |||
| 796 | ret = strtobool(buf, &val); | ||
| 797 | if (ret < 0) | ||
| 798 | return ret; | ||
| 799 | |||
| 800 | lock_device_hotplug(); | ||
| 801 | acpi_force_hot_remove = val; | ||
| 802 | unlock_device_hotplug(); | ||
| 803 | return size; | ||
| 804 | } | ||
| 805 | |||
| 806 | static const struct kobj_attribute force_remove_attr = | ||
| 807 | __ATTR(force_remove, S_IRUGO | S_IWUSR, force_remove_show, | ||
| 808 | force_remove_store); | ||
| 809 | |||
| 783 | int __init acpi_sysfs_init(void) | 810 | int __init acpi_sysfs_init(void) |
| 784 | { | 811 | { |
| 785 | int result; | 812 | int result; |
| @@ -789,6 +816,10 @@ int __init acpi_sysfs_init(void) | |||
| 789 | return result; | 816 | return result; |
| 790 | 817 | ||
| 791 | hotplug_kobj = kobject_create_and_add("hotplug", acpi_kobj); | 818 | hotplug_kobj = kobject_create_and_add("hotplug", acpi_kobj); |
| 819 | result = sysfs_create_file(hotplug_kobj, &force_remove_attr.attr); | ||
| 820 | if (result) | ||
| 821 | return result; | ||
| 822 | |||
| 792 | result = sysfs_create_file(acpi_kobj, &pm_profile_attr.attr); | 823 | result = sysfs_create_file(acpi_kobj, &pm_profile_attr.attr); |
| 793 | return result; | 824 | return result; |
| 794 | } | 825 | } |
diff --git a/drivers/base/core.c b/drivers/base/core.c index 2499cefdcdf2..2166f34b7d84 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
| @@ -403,6 +403,36 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, | |||
| 403 | static struct device_attribute uevent_attr = | 403 | static struct device_attribute uevent_attr = |
| 404 | __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent); | 404 | __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent); |
| 405 | 405 | ||
| 406 | static ssize_t show_online(struct device *dev, struct device_attribute *attr, | ||
| 407 | char *buf) | ||
| 408 | { | ||
| 409 | bool val; | ||
| 410 | |||
| 411 | lock_device_hotplug(); | ||
| 412 | val = !dev->offline; | ||
| 413 | unlock_device_hotplug(); | ||
| 414 | return sprintf(buf, "%u\n", val); | ||
| 415 | } | ||
| 416 | |||
| 417 | static ssize_t store_online(struct device *dev, struct device_attribute *attr, | ||
| 418 | const char *buf, size_t count) | ||
| 419 | { | ||
| 420 | bool val; | ||
| 421 | int ret; | ||
| 422 | |||
| 423 | ret = strtobool(buf, &val); | ||
| 424 | if (ret < 0) | ||
| 425 | return ret; | ||
| 426 | |||
| 427 | lock_device_hotplug(); | ||
| 428 | ret = val ? device_online(dev) : device_offline(dev); | ||
| 429 | unlock_device_hotplug(); | ||
| 430 | return ret < 0 ? ret : count; | ||
| 431 | } | ||
| 432 | |||
| 433 | static struct device_attribute online_attr = | ||
| 434 | __ATTR(online, S_IRUGO | S_IWUSR, show_online, store_online); | ||
| 435 | |||
| 406 | static int device_add_attributes(struct device *dev, | 436 | static int device_add_attributes(struct device *dev, |
| 407 | struct device_attribute *attrs) | 437 | struct device_attribute *attrs) |
| 408 | { | 438 | { |
| @@ -516,6 +546,12 @@ static int device_add_attrs(struct device *dev) | |||
| 516 | if (error) | 546 | if (error) |
| 517 | goto err_remove_type_groups; | 547 | goto err_remove_type_groups; |
| 518 | 548 | ||
| 549 | if (device_supports_offline(dev) && !dev->offline_disabled) { | ||
| 550 | error = device_create_file(dev, &online_attr); | ||
| 551 | if (error) | ||
| 552 | goto err_remove_type_groups; | ||
| 553 | } | ||
| 554 | |||
| 519 | return 0; | 555 | return 0; |
| 520 | 556 | ||
| 521 | err_remove_type_groups: | 557 | err_remove_type_groups: |
| @@ -536,6 +572,7 @@ static void device_remove_attrs(struct device *dev) | |||
| 536 | struct class *class = dev->class; | 572 | struct class *class = dev->class; |
| 537 | const struct device_type *type = dev->type; | 573 | const struct device_type *type = dev->type; |
| 538 | 574 | ||
| 575 | device_remove_file(dev, &online_attr); | ||
| 539 | device_remove_groups(dev, dev->groups); | 576 | device_remove_groups(dev, dev->groups); |
| 540 | 577 | ||
| 541 | if (type) | 578 | if (type) |
| @@ -1433,6 +1470,99 @@ EXPORT_SYMBOL_GPL(put_device); | |||
| 1433 | EXPORT_SYMBOL_GPL(device_create_file); | 1470 | EXPORT_SYMBOL_GPL(device_create_file); |
| 1434 | EXPORT_SYMBOL_GPL(device_remove_file); | 1471 | EXPORT_SYMBOL_GPL(device_remove_file); |
| 1435 | 1472 | ||
| 1473 | static DEFINE_MUTEX(device_hotplug_lock); | ||
| 1474 | |||
| 1475 | void lock_device_hotplug(void) | ||
| 1476 | { | ||
| 1477 | mutex_lock(&device_hotplug_lock); | ||
| 1478 | } | ||
| 1479 | |||
| 1480 | void unlock_device_hotplug(void) | ||
| 1481 | { | ||
| 1482 | mutex_unlock(&device_hotplug_lock); | ||
| 1483 | } | ||
| 1484 | |||
| 1485 | static int device_check_offline(struct device *dev, void *not_used) | ||
| 1486 | { | ||
| 1487 | int ret; | ||
| 1488 | |||
| 1489 | ret = device_for_each_child(dev, NULL, device_check_offline); | ||
| 1490 | if (ret) | ||
| 1491 | return ret; | ||
| 1492 | |||
| 1493 | return device_supports_offline(dev) && !dev->offline ? -EBUSY : 0; | ||
| 1494 | } | ||
| 1495 | |||
| 1496 | /** | ||
| 1497 | * device_offline - Prepare the device for hot-removal. | ||
| 1498 | * @dev: Device to be put offline. | ||
| 1499 | * | ||
| 1500 | * Execute the device bus type's .offline() callback, if present, to prepare | ||
| 1501 | * the device for a subsequent hot-removal. If that succeeds, the device must | ||
| 1502 | * not be used until either it is removed or its bus type's .online() callback | ||
| 1503 | * is executed. | ||
| 1504 | * | ||
| 1505 | * Call under device_hotplug_lock. | ||
| 1506 | */ | ||
| 1507 | int device_offline(struct device *dev) | ||
| 1508 | { | ||
| 1509 | int ret; | ||
| 1510 | |||
| 1511 | if (dev->offline_disabled) | ||
| 1512 | return -EPERM; | ||
| 1513 | |||
| 1514 | ret = device_for_each_child(dev, NULL, device_check_offline); | ||
| 1515 | if (ret) | ||
| 1516 | return ret; | ||
| 1517 | |||
| 1518 | device_lock(dev); | ||
| 1519 | if (device_supports_offline(dev)) { | ||
| 1520 | if (dev->offline) { | ||
| 1521 | ret = 1; | ||
| 1522 | } else { | ||
| 1523 | ret = dev->bus->offline(dev); | ||
| 1524 | if (!ret) { | ||
| 1525 | kobject_uevent(&dev->kobj, KOBJ_OFFLINE); | ||
| 1526 | dev->offline = true; | ||
| 1527 | } | ||
| 1528 | } | ||
| 1529 | } | ||
| 1530 | device_unlock(dev); | ||
| 1531 | |||
| 1532 | return ret; | ||
| 1533 | } | ||
| 1534 | |||
| 1535 | /** | ||
| 1536 | * device_online - Put the device back online after successful device_offline(). | ||
| 1537 | * @dev: Device to be put back online. | ||
| 1538 | * | ||
| 1539 | * If device_offline() has been successfully executed for @dev, but the device | ||
| 1540 | * has not been removed subsequently, execute its bus type's .online() callback | ||
| 1541 | * to indicate that the device can be used again. | ||
| 1542 | * | ||
| 1543 | * Call under device_hotplug_lock. | ||
| 1544 | */ | ||
| 1545 | int device_online(struct device *dev) | ||
| 1546 | { | ||
| 1547 | int ret = 0; | ||
| 1548 | |||
| 1549 | device_lock(dev); | ||
| 1550 | if (device_supports_offline(dev)) { | ||
| 1551 | if (dev->offline) { | ||
| 1552 | ret = dev->bus->online(dev); | ||
| 1553 | if (!ret) { | ||
| 1554 | kobject_uevent(&dev->kobj, KOBJ_ONLINE); | ||
| 1555 | dev->offline = false; | ||
| 1556 | } | ||
| 1557 | } else { | ||
| 1558 | ret = 1; | ||
| 1559 | } | ||
| 1560 | } | ||
| 1561 | device_unlock(dev); | ||
| 1562 | |||
| 1563 | return ret; | ||
| 1564 | } | ||
| 1565 | |||
| 1436 | struct root_device { | 1566 | struct root_device { |
| 1437 | struct device dev; | 1567 | struct device dev; |
| 1438 | struct module *owner; | 1568 | struct module *owner; |
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 3d48fc887ef4..1d110dc6f0c1 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c | |||
| @@ -13,17 +13,21 @@ | |||
| 13 | #include <linux/gfp.h> | 13 | #include <linux/gfp.h> |
| 14 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
| 15 | #include <linux/percpu.h> | 15 | #include <linux/percpu.h> |
| 16 | #include <linux/acpi.h> | ||
| 16 | 17 | ||
| 17 | #include "base.h" | 18 | #include "base.h" |
| 18 | 19 | ||
| 19 | struct bus_type cpu_subsys = { | ||
| 20 | .name = "cpu", | ||
| 21 | .dev_name = "cpu", | ||
| 22 | }; | ||
| 23 | EXPORT_SYMBOL_GPL(cpu_subsys); | ||
| 24 | |||
| 25 | static DEFINE_PER_CPU(struct device *, cpu_sys_devices); | 20 | static DEFINE_PER_CPU(struct device *, cpu_sys_devices); |
| 26 | 21 | ||
| 22 | static int cpu_subsys_match(struct device *dev, struct device_driver *drv) | ||
| 23 | { | ||
| 24 | /* ACPI style match is the only one that may succeed. */ | ||
| 25 | if (acpi_driver_match_device(dev, drv)) | ||
| 26 | return 1; | ||
| 27 | |||
| 28 | return 0; | ||
| 29 | } | ||
| 30 | |||
| 27 | #ifdef CONFIG_HOTPLUG_CPU | 31 | #ifdef CONFIG_HOTPLUG_CPU |
| 28 | static void change_cpu_under_node(struct cpu *cpu, | 32 | static void change_cpu_under_node(struct cpu *cpu, |
| 29 | unsigned int from_nid, unsigned int to_nid) | 33 | unsigned int from_nid, unsigned int to_nid) |
| @@ -34,69 +38,45 @@ static void change_cpu_under_node(struct cpu *cpu, | |||
| 34 | cpu->node_id = to_nid; | 38 | cpu->node_id = to_nid; |
| 35 | } | 39 | } |
| 36 | 40 | ||
| 37 | static ssize_t show_online(struct device *dev, | 41 | static int __ref cpu_subsys_online(struct device *dev) |
| 38 | struct device_attribute *attr, | ||
| 39 | char *buf) | ||
| 40 | { | 42 | { |
| 41 | struct cpu *cpu = container_of(dev, struct cpu, dev); | 43 | struct cpu *cpu = container_of(dev, struct cpu, dev); |
| 44 | int cpuid = dev->id; | ||
| 45 | int from_nid, to_nid; | ||
| 46 | int ret; | ||
| 42 | 47 | ||
| 43 | return sprintf(buf, "%u\n", !!cpu_online(cpu->dev.id)); | 48 | cpu_hotplug_driver_lock(); |
| 49 | |||
| 50 | from_nid = cpu_to_node(cpuid); | ||
| 51 | ret = cpu_up(cpuid); | ||
| 52 | /* | ||
| 53 | * When hot adding memory to memoryless node and enabling a cpu | ||
| 54 | * on the node, node number of the cpu may internally change. | ||
| 55 | */ | ||
| 56 | to_nid = cpu_to_node(cpuid); | ||
| 57 | if (from_nid != to_nid) | ||
| 58 | change_cpu_under_node(cpu, from_nid, to_nid); | ||
| 59 | |||
| 60 | cpu_hotplug_driver_unlock(); | ||
| 61 | return ret; | ||
| 44 | } | 62 | } |
| 45 | 63 | ||
| 46 | static ssize_t __ref store_online(struct device *dev, | 64 | static int cpu_subsys_offline(struct device *dev) |
| 47 | struct device_attribute *attr, | ||
| 48 | const char *buf, size_t count) | ||
| 49 | { | 65 | { |
| 50 | struct cpu *cpu = container_of(dev, struct cpu, dev); | 66 | int ret; |
| 51 | int cpuid = cpu->dev.id; | ||
| 52 | int from_nid, to_nid; | ||
| 53 | ssize_t ret; | ||
| 54 | 67 | ||
| 55 | cpu_hotplug_driver_lock(); | 68 | cpu_hotplug_driver_lock(); |
| 56 | switch (buf[0]) { | 69 | ret = cpu_down(dev->id); |
| 57 | case '0': | ||
| 58 | ret = cpu_down(cpuid); | ||
| 59 | if (!ret) | ||
| 60 | kobject_uevent(&dev->kobj, KOBJ_OFFLINE); | ||
| 61 | break; | ||
| 62 | case '1': | ||
| 63 | from_nid = cpu_to_node(cpuid); | ||
| 64 | ret = cpu_up(cpuid); | ||
| 65 | |||
| 66 | /* | ||
| 67 | * When hot adding memory to memoryless node and enabling a cpu | ||
| 68 | * on the node, node number of the cpu may internally change. | ||
| 69 | */ | ||
| 70 | to_nid = cpu_to_node(cpuid); | ||
| 71 | if (from_nid != to_nid) | ||
| 72 | change_cpu_under_node(cpu, from_nid, to_nid); | ||
| 73 | |||
| 74 | if (!ret) | ||
| 75 | kobject_uevent(&dev->kobj, KOBJ_ONLINE); | ||
| 76 | break; | ||
| 77 | default: | ||
| 78 | ret = -EINVAL; | ||
| 79 | } | ||
| 80 | cpu_hotplug_driver_unlock(); | 70 | cpu_hotplug_driver_unlock(); |
| 81 | |||
| 82 | if (ret >= 0) | ||
| 83 | ret = count; | ||
| 84 | return ret; | 71 | return ret; |
| 85 | } | 72 | } |
| 86 | static DEVICE_ATTR(online, 0644, show_online, store_online); | ||
| 87 | 73 | ||
| 88 | static void __cpuinit register_cpu_control(struct cpu *cpu) | ||
| 89 | { | ||
| 90 | device_create_file(&cpu->dev, &dev_attr_online); | ||
| 91 | } | ||
| 92 | void unregister_cpu(struct cpu *cpu) | 74 | void unregister_cpu(struct cpu *cpu) |
| 93 | { | 75 | { |
| 94 | int logical_cpu = cpu->dev.id; | 76 | int logical_cpu = cpu->dev.id; |
| 95 | 77 | ||
| 96 | unregister_cpu_under_node(logical_cpu, cpu_to_node(logical_cpu)); | 78 | unregister_cpu_under_node(logical_cpu, cpu_to_node(logical_cpu)); |
| 97 | 79 | ||
| 98 | device_remove_file(&cpu->dev, &dev_attr_online); | ||
| 99 | |||
| 100 | device_unregister(&cpu->dev); | 80 | device_unregister(&cpu->dev); |
| 101 | per_cpu(cpu_sys_devices, logical_cpu) = NULL; | 81 | per_cpu(cpu_sys_devices, logical_cpu) = NULL; |
| 102 | return; | 82 | return; |
| @@ -123,12 +103,19 @@ static DEVICE_ATTR(probe, S_IWUSR, NULL, cpu_probe_store); | |||
| 123 | static DEVICE_ATTR(release, S_IWUSR, NULL, cpu_release_store); | 103 | static DEVICE_ATTR(release, S_IWUSR, NULL, cpu_release_store); |
| 124 | #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ | 104 | #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ |
| 125 | 105 | ||
| 126 | #else /* ... !CONFIG_HOTPLUG_CPU */ | ||
| 127 | static inline void register_cpu_control(struct cpu *cpu) | ||
| 128 | { | ||
| 129 | } | ||
| 130 | #endif /* CONFIG_HOTPLUG_CPU */ | 106 | #endif /* CONFIG_HOTPLUG_CPU */ |
| 131 | 107 | ||
| 108 | struct bus_type cpu_subsys = { | ||
| 109 | .name = "cpu", | ||
| 110 | .dev_name = "cpu", | ||
| 111 | .match = cpu_subsys_match, | ||
| 112 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 113 | .online = cpu_subsys_online, | ||
| 114 | .offline = cpu_subsys_offline, | ||
| 115 | #endif | ||
| 116 | }; | ||
| 117 | EXPORT_SYMBOL_GPL(cpu_subsys); | ||
| 118 | |||
| 132 | #ifdef CONFIG_KEXEC | 119 | #ifdef CONFIG_KEXEC |
| 133 | #include <linux/kexec.h> | 120 | #include <linux/kexec.h> |
| 134 | 121 | ||
| @@ -277,12 +264,12 @@ int __cpuinit register_cpu(struct cpu *cpu, int num) | |||
| 277 | cpu->dev.id = num; | 264 | cpu->dev.id = num; |
| 278 | cpu->dev.bus = &cpu_subsys; | 265 | cpu->dev.bus = &cpu_subsys; |
| 279 | cpu->dev.release = cpu_device_release; | 266 | cpu->dev.release = cpu_device_release; |
| 267 | cpu->dev.offline_disabled = !cpu->hotpluggable; | ||
| 268 | cpu->dev.offline = !cpu_online(num); | ||
| 280 | #ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE | 269 | #ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE |
| 281 | cpu->dev.bus->uevent = arch_cpu_uevent; | 270 | cpu->dev.bus->uevent = arch_cpu_uevent; |
| 282 | #endif | 271 | #endif |
| 283 | error = device_register(&cpu->dev); | 272 | error = device_register(&cpu->dev); |
| 284 | if (!error && cpu->hotpluggable) | ||
| 285 | register_cpu_control(cpu); | ||
| 286 | if (!error) | 273 | if (!error) |
| 287 | per_cpu(cpu_sys_devices, num) = &cpu->dev; | 274 | per_cpu(cpu_sys_devices, num) = &cpu->dev; |
| 288 | if (!error) | 275 | if (!error) |
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 14f8a6954da0..4ebf97f99fae 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
| @@ -37,9 +37,14 @@ static inline int base_memory_block_id(int section_nr) | |||
| 37 | return section_nr / sections_per_block; | 37 | return section_nr / sections_per_block; |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | static int memory_subsys_online(struct device *dev); | ||
| 41 | static int memory_subsys_offline(struct device *dev); | ||
| 42 | |||
| 40 | static struct bus_type memory_subsys = { | 43 | static struct bus_type memory_subsys = { |
| 41 | .name = MEMORY_CLASS_NAME, | 44 | .name = MEMORY_CLASS_NAME, |
| 42 | .dev_name = MEMORY_CLASS_NAME, | 45 | .dev_name = MEMORY_CLASS_NAME, |
| 46 | .online = memory_subsys_online, | ||
| 47 | .offline = memory_subsys_offline, | ||
| 43 | }; | 48 | }; |
| 44 | 49 | ||
| 45 | static BLOCKING_NOTIFIER_HEAD(memory_chain); | 50 | static BLOCKING_NOTIFIER_HEAD(memory_chain); |
| @@ -88,6 +93,7 @@ int register_memory(struct memory_block *memory) | |||
| 88 | memory->dev.bus = &memory_subsys; | 93 | memory->dev.bus = &memory_subsys; |
| 89 | memory->dev.id = memory->start_section_nr / sections_per_block; | 94 | memory->dev.id = memory->start_section_nr / sections_per_block; |
| 90 | memory->dev.release = memory_block_release; | 95 | memory->dev.release = memory_block_release; |
| 96 | memory->dev.offline = memory->state == MEM_OFFLINE; | ||
| 91 | 97 | ||
| 92 | error = device_register(&memory->dev); | 98 | error = device_register(&memory->dev); |
| 93 | return error; | 99 | return error; |
| @@ -278,33 +284,64 @@ static int __memory_block_change_state(struct memory_block *mem, | |||
| 278 | { | 284 | { |
| 279 | int ret = 0; | 285 | int ret = 0; |
| 280 | 286 | ||
| 281 | if (mem->state != from_state_req) { | 287 | if (mem->state != from_state_req) |
| 282 | ret = -EINVAL; | 288 | return -EINVAL; |
| 283 | goto out; | ||
| 284 | } | ||
| 285 | 289 | ||
| 286 | if (to_state == MEM_OFFLINE) | 290 | if (to_state == MEM_OFFLINE) |
| 287 | mem->state = MEM_GOING_OFFLINE; | 291 | mem->state = MEM_GOING_OFFLINE; |
| 288 | 292 | ||
| 289 | ret = memory_block_action(mem->start_section_nr, to_state, online_type); | 293 | ret = memory_block_action(mem->start_section_nr, to_state, online_type); |
| 294 | mem->state = ret ? from_state_req : to_state; | ||
| 295 | return ret; | ||
| 296 | } | ||
| 290 | 297 | ||
| 291 | if (ret) { | 298 | static int memory_subsys_online(struct device *dev) |
| 292 | mem->state = from_state_req; | 299 | { |
| 293 | goto out; | 300 | struct memory_block *mem = container_of(dev, struct memory_block, dev); |
| 294 | } | 301 | int ret; |
| 295 | 302 | ||
| 296 | mem->state = to_state; | 303 | mutex_lock(&mem->state_mutex); |
| 297 | switch (mem->state) { | 304 | |
| 298 | case MEM_OFFLINE: | 305 | ret = mem->state == MEM_ONLINE ? 0 : |
| 299 | kobject_uevent(&mem->dev.kobj, KOBJ_OFFLINE); | 306 | __memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE, |
| 300 | break; | 307 | ONLINE_KEEP); |
| 301 | case MEM_ONLINE: | 308 | |
| 302 | kobject_uevent(&mem->dev.kobj, KOBJ_ONLINE); | 309 | mutex_unlock(&mem->state_mutex); |
| 303 | break; | 310 | return ret; |
| 304 | default: | 311 | } |
| 305 | break; | 312 | |
| 313 | static int memory_subsys_offline(struct device *dev) | ||
| 314 | { | ||
| 315 | struct memory_block *mem = container_of(dev, struct memory_block, dev); | ||
| 316 | int ret; | ||
| 317 | |||
| 318 | mutex_lock(&mem->state_mutex); | ||
| 319 | |||
| 320 | ret = mem->state == MEM_OFFLINE ? 0 : | ||
| 321 | __memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE, -1); | ||
| 322 | |||
| 323 | mutex_unlock(&mem->state_mutex); | ||
| 324 | return ret; | ||
| 325 | } | ||
| 326 | |||
| 327 | static int __memory_block_change_state_uevent(struct memory_block *mem, | ||
| 328 | unsigned long to_state, unsigned long from_state_req, | ||
| 329 | int online_type) | ||
| 330 | { | ||
| 331 | int ret = __memory_block_change_state(mem, to_state, from_state_req, | ||
| 332 | online_type); | ||
| 333 | if (!ret) { | ||
| 334 | switch (mem->state) { | ||
| 335 | case MEM_OFFLINE: | ||
| 336 | kobject_uevent(&mem->dev.kobj, KOBJ_OFFLINE); | ||
| 337 | break; | ||
| 338 | case MEM_ONLINE: | ||
| 339 | kobject_uevent(&mem->dev.kobj, KOBJ_ONLINE); | ||
| 340 | break; | ||
| 341 | default: | ||
| 342 | break; | ||
| 343 | } | ||
| 306 | } | 344 | } |
| 307 | out: | ||
| 308 | return ret; | 345 | return ret; |
| 309 | } | 346 | } |
| 310 | 347 | ||
| @@ -315,8 +352,8 @@ static int memory_block_change_state(struct memory_block *mem, | |||
| 315 | int ret; | 352 | int ret; |
| 316 | 353 | ||
| 317 | mutex_lock(&mem->state_mutex); | 354 | mutex_lock(&mem->state_mutex); |
| 318 | ret = __memory_block_change_state(mem, to_state, from_state_req, | 355 | ret = __memory_block_change_state_uevent(mem, to_state, from_state_req, |
| 319 | online_type); | 356 | online_type); |
| 320 | mutex_unlock(&mem->state_mutex); | 357 | mutex_unlock(&mem->state_mutex); |
| 321 | 358 | ||
| 322 | return ret; | 359 | return ret; |
| @@ -326,22 +363,34 @@ store_mem_state(struct device *dev, | |||
| 326 | struct device_attribute *attr, const char *buf, size_t count) | 363 | struct device_attribute *attr, const char *buf, size_t count) |
| 327 | { | 364 | { |
| 328 | struct memory_block *mem; | 365 | struct memory_block *mem; |
| 366 | bool offline; | ||
| 329 | int ret = -EINVAL; | 367 | int ret = -EINVAL; |
| 330 | 368 | ||
| 331 | mem = container_of(dev, struct memory_block, dev); | 369 | mem = container_of(dev, struct memory_block, dev); |
| 332 | 370 | ||
| 333 | if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) | 371 | lock_device_hotplug(); |
| 372 | |||
| 373 | if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) { | ||
| 374 | offline = false; | ||
| 334 | ret = memory_block_change_state(mem, MEM_ONLINE, | 375 | ret = memory_block_change_state(mem, MEM_ONLINE, |
| 335 | MEM_OFFLINE, ONLINE_KERNEL); | 376 | MEM_OFFLINE, ONLINE_KERNEL); |
| 336 | else if (!strncmp(buf, "online_movable", min_t(int, count, 14))) | 377 | } else if (!strncmp(buf, "online_movable", min_t(int, count, 14))) { |
| 378 | offline = false; | ||
| 337 | ret = memory_block_change_state(mem, MEM_ONLINE, | 379 | ret = memory_block_change_state(mem, MEM_ONLINE, |
| 338 | MEM_OFFLINE, ONLINE_MOVABLE); | 380 | MEM_OFFLINE, ONLINE_MOVABLE); |
| 339 | else if (!strncmp(buf, "online", min_t(int, count, 6))) | 381 | } else if (!strncmp(buf, "online", min_t(int, count, 6))) { |
| 382 | offline = false; | ||
| 340 | ret = memory_block_change_state(mem, MEM_ONLINE, | 383 | ret = memory_block_change_state(mem, MEM_ONLINE, |
| 341 | MEM_OFFLINE, ONLINE_KEEP); | 384 | MEM_OFFLINE, ONLINE_KEEP); |
| 342 | else if(!strncmp(buf, "offline", min_t(int, count, 7))) | 385 | } else if(!strncmp(buf, "offline", min_t(int, count, 7))) { |
| 386 | offline = true; | ||
| 343 | ret = memory_block_change_state(mem, MEM_OFFLINE, | 387 | ret = memory_block_change_state(mem, MEM_OFFLINE, |
| 344 | MEM_ONLINE, -1); | 388 | MEM_ONLINE, -1); |
| 389 | } | ||
| 390 | if (!ret) | ||
| 391 | dev->offline = offline; | ||
| 392 | |||
| 393 | unlock_device_hotplug(); | ||
| 345 | 394 | ||
| 346 | if (ret) | 395 | if (ret) |
| 347 | return ret; | 396 | return ret; |
| @@ -679,21 +728,6 @@ int unregister_memory_section(struct mem_section *section) | |||
| 679 | } | 728 | } |
| 680 | #endif /* CONFIG_MEMORY_HOTREMOVE */ | 729 | #endif /* CONFIG_MEMORY_HOTREMOVE */ |
| 681 | 730 | ||
| 682 | /* | ||
| 683 | * offline one memory block. If the memory block has been offlined, do nothing. | ||
| 684 | */ | ||
| 685 | int offline_memory_block(struct memory_block *mem) | ||
| 686 | { | ||
| 687 | int ret = 0; | ||
| 688 | |||
| 689 | mutex_lock(&mem->state_mutex); | ||
| 690 | if (mem->state != MEM_OFFLINE) | ||
| 691 | ret = __memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE, -1); | ||
| 692 | mutex_unlock(&mem->state_mutex); | ||
| 693 | |||
| 694 | return ret; | ||
| 695 | } | ||
| 696 | |||
| 697 | /* return true if the memory block is offlined, otherwise, return false */ | 731 | /* return true if the memory block is offlined, otherwise, return false */ |
| 698 | bool is_memblock_offlined(struct memory_block *mem) | 732 | bool is_memblock_offlined(struct memory_block *mem) |
| 699 | { | 733 | { |
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c index edc089e9d0c4..b8efacf01d69 100644 --- a/drivers/cpufreq/acpi-cpufreq.c +++ b/drivers/cpufreq/acpi-cpufreq.c | |||
| @@ -1034,4 +1034,11 @@ static const struct x86_cpu_id acpi_cpufreq_ids[] = { | |||
| 1034 | }; | 1034 | }; |
| 1035 | MODULE_DEVICE_TABLE(x86cpu, acpi_cpufreq_ids); | 1035 | MODULE_DEVICE_TABLE(x86cpu, acpi_cpufreq_ids); |
| 1036 | 1036 | ||
| 1037 | static const struct acpi_device_id processor_device_ids[] = { | ||
| 1038 | {ACPI_PROCESSOR_OBJECT_HID, }, | ||
| 1039 | {ACPI_PROCESSOR_DEVICE_HID, }, | ||
| 1040 | {}, | ||
| 1041 | }; | ||
| 1042 | MODULE_DEVICE_TABLE(acpi, processor_device_ids); | ||
| 1043 | |||
| 1037 | MODULE_ALIAS("acpi"); | 1044 | MODULE_ALIAS("acpi"); |
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index c13c919ab99e..cf0817a555e4 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h | |||
| @@ -63,13 +63,6 @@ acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld | |||
| 63 | #define ACPI_BUS_FILE_ROOT "acpi" | 63 | #define ACPI_BUS_FILE_ROOT "acpi" |
| 64 | extern struct proc_dir_entry *acpi_root_dir; | 64 | extern struct proc_dir_entry *acpi_root_dir; |
| 65 | 65 | ||
| 66 | enum acpi_bus_removal_type { | ||
| 67 | ACPI_BUS_REMOVAL_NORMAL = 0, | ||
| 68 | ACPI_BUS_REMOVAL_EJECT, | ||
| 69 | ACPI_BUS_REMOVAL_SUPRISE, | ||
| 70 | ACPI_BUS_REMOVAL_TYPE_COUNT | ||
| 71 | }; | ||
| 72 | |||
| 73 | enum acpi_bus_device_type { | 66 | enum acpi_bus_device_type { |
| 74 | ACPI_BUS_TYPE_DEVICE = 0, | 67 | ACPI_BUS_TYPE_DEVICE = 0, |
| 75 | ACPI_BUS_TYPE_POWER, | 68 | ACPI_BUS_TYPE_POWER, |
| @@ -286,6 +279,7 @@ struct acpi_device_physical_node { | |||
| 286 | u8 node_id; | 279 | u8 node_id; |
| 287 | struct list_head node; | 280 | struct list_head node; |
| 288 | struct device *dev; | 281 | struct device *dev; |
| 282 | bool put_online:1; | ||
| 289 | }; | 283 | }; |
| 290 | 284 | ||
| 291 | /* set maximum of physical nodes to 32 for expansibility */ | 285 | /* set maximum of physical nodes to 32 for expansibility */ |
| @@ -310,7 +304,6 @@ struct acpi_device { | |||
| 310 | struct acpi_driver *driver; | 304 | struct acpi_driver *driver; |
| 311 | void *driver_data; | 305 | void *driver_data; |
| 312 | struct device dev; | 306 | struct device dev; |
| 313 | enum acpi_bus_removal_type removal_type; /* indicate for different removal type */ | ||
| 314 | u8 physical_node_count; | 307 | u8 physical_node_count; |
| 315 | struct list_head physical_node_list; | 308 | struct list_head physical_node_list; |
| 316 | struct mutex physical_node_lock; | 309 | struct mutex physical_node_lock; |
diff --git a/include/acpi/processor.h b/include/acpi/processor.h index ea69367fdd3b..66096d06925e 100644 --- a/include/acpi/processor.h +++ b/include/acpi/processor.h | |||
| @@ -6,6 +6,10 @@ | |||
| 6 | #include <linux/thermal.h> | 6 | #include <linux/thermal.h> |
| 7 | #include <asm/acpi.h> | 7 | #include <asm/acpi.h> |
| 8 | 8 | ||
| 9 | #define ACPI_PROCESSOR_CLASS "processor" | ||
| 10 | #define ACPI_PROCESSOR_DEVICE_NAME "Processor" | ||
| 11 | #define ACPI_PROCESSOR_DEVICE_HID "ACPI0007" | ||
| 12 | |||
| 9 | #define ACPI_PROCESSOR_BUSY_METRIC 10 | 13 | #define ACPI_PROCESSOR_BUSY_METRIC 10 |
| 10 | 14 | ||
| 11 | #define ACPI_PROCESSOR_MAX_POWER 8 | 15 | #define ACPI_PROCESSOR_MAX_POWER 8 |
| @@ -207,6 +211,7 @@ struct acpi_processor { | |||
| 207 | struct acpi_processor_throttling throttling; | 211 | struct acpi_processor_throttling throttling; |
| 208 | struct acpi_processor_limit limit; | 212 | struct acpi_processor_limit limit; |
| 209 | struct thermal_cooling_device *cdev; | 213 | struct thermal_cooling_device *cdev; |
| 214 | struct device *dev; /* Processor device. */ | ||
| 210 | }; | 215 | }; |
| 211 | 216 | ||
| 212 | struct acpi_processor_errata { | 217 | struct acpi_processor_errata { |
diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 17b5b5967641..353ba256f368 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h | |||
| @@ -352,8 +352,7 @@ extern acpi_status acpi_pci_osc_control_set(acpi_handle handle, | |||
| 352 | 352 | ||
| 353 | /* Enable _OST when all relevant hotplug operations are enabled */ | 353 | /* Enable _OST when all relevant hotplug operations are enabled */ |
| 354 | #if defined(CONFIG_ACPI_HOTPLUG_CPU) && \ | 354 | #if defined(CONFIG_ACPI_HOTPLUG_CPU) && \ |
| 355 | (defined(CONFIG_ACPI_HOTPLUG_MEMORY) || \ | 355 | defined(CONFIG_ACPI_HOTPLUG_MEMORY) && \ |
| 356 | defined(CONFIG_ACPI_HOTPLUG_MEMORY_MODULE)) && \ | ||
| 357 | defined(CONFIG_ACPI_CONTAINER) | 356 | defined(CONFIG_ACPI_CONTAINER) |
| 358 | #define ACPI_HOTPLUG_OST | 357 | #define ACPI_HOTPLUG_OST |
| 359 | #endif | 358 | #endif |
diff --git a/include/linux/device.h b/include/linux/device.h index c0a126125325..eeb33315514c 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
| @@ -71,6 +71,10 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); | |||
| 71 | * the specific driver's probe to initial the matched device. | 71 | * the specific driver's probe to initial the matched device. |
| 72 | * @remove: Called when a device removed from this bus. | 72 | * @remove: Called when a device removed from this bus. |
| 73 | * @shutdown: Called at shut-down time to quiesce the device. | 73 | * @shutdown: Called at shut-down time to quiesce the device. |
| 74 | * | ||
| 75 | * @online: Called to put the device back online (after offlining it). | ||
| 76 | * @offline: Called to put the device offline for hot-removal. May fail. | ||
| 77 | * | ||
| 74 | * @suspend: Called when a device on this bus wants to go to sleep mode. | 78 | * @suspend: Called when a device on this bus wants to go to sleep mode. |
| 75 | * @resume: Called to bring a device on this bus out of sleep mode. | 79 | * @resume: Called to bring a device on this bus out of sleep mode. |
| 76 | * @pm: Power management operations of this bus, callback the specific | 80 | * @pm: Power management operations of this bus, callback the specific |
| @@ -104,6 +108,9 @@ struct bus_type { | |||
| 104 | int (*remove)(struct device *dev); | 108 | int (*remove)(struct device *dev); |
| 105 | void (*shutdown)(struct device *dev); | 109 | void (*shutdown)(struct device *dev); |
| 106 | 110 | ||
| 111 | int (*online)(struct device *dev); | ||
| 112 | int (*offline)(struct device *dev); | ||
| 113 | |||
| 107 | int (*suspend)(struct device *dev, pm_message_t state); | 114 | int (*suspend)(struct device *dev, pm_message_t state); |
| 108 | int (*resume)(struct device *dev); | 115 | int (*resume)(struct device *dev); |
| 109 | 116 | ||
| @@ -648,6 +655,8 @@ struct acpi_dev_node { | |||
| 648 | * @release: Callback to free the device after all references have | 655 | * @release: Callback to free the device after all references have |
| 649 | * gone away. This should be set by the allocator of the | 656 | * gone away. This should be set by the allocator of the |
| 650 | * device (i.e. the bus driver that discovered the device). | 657 | * device (i.e. the bus driver that discovered the device). |
| 658 | * @offline_disabled: If set, the device is permanently online. | ||
| 659 | * @offline: Set after successful invocation of bus type's .offline(). | ||
| 651 | * | 660 | * |
| 652 | * At the lowest level, every device in a Linux system is represented by an | 661 | * At the lowest level, every device in a Linux system is represented by an |
| 653 | * instance of struct device. The device structure contains the information | 662 | * instance of struct device. The device structure contains the information |
| @@ -720,6 +729,9 @@ struct device { | |||
| 720 | 729 | ||
| 721 | void (*release)(struct device *dev); | 730 | void (*release)(struct device *dev); |
| 722 | struct iommu_group *iommu_group; | 731 | struct iommu_group *iommu_group; |
| 732 | |||
| 733 | bool offline_disabled:1; | ||
| 734 | bool offline:1; | ||
| 723 | }; | 735 | }; |
| 724 | 736 | ||
| 725 | static inline struct device *kobj_to_dev(struct kobject *kobj) | 737 | static inline struct device *kobj_to_dev(struct kobject *kobj) |
| @@ -856,6 +868,15 @@ extern const char *device_get_devnode(struct device *dev, | |||
| 856 | extern void *dev_get_drvdata(const struct device *dev); | 868 | extern void *dev_get_drvdata(const struct device *dev); |
| 857 | extern int dev_set_drvdata(struct device *dev, void *data); | 869 | extern int dev_set_drvdata(struct device *dev, void *data); |
| 858 | 870 | ||
| 871 | static inline bool device_supports_offline(struct device *dev) | ||
| 872 | { | ||
| 873 | return dev->bus && dev->bus->offline && dev->bus->online; | ||
| 874 | } | ||
| 875 | |||
| 876 | extern void lock_device_hotplug(void); | ||
| 877 | extern void unlock_device_hotplug(void); | ||
| 878 | extern int device_offline(struct device *dev); | ||
| 879 | extern int device_online(struct device *dev); | ||
| 859 | /* | 880 | /* |
| 860 | * Root device objects for grouping under /sys/devices | 881 | * Root device objects for grouping under /sys/devices |
| 861 | */ | 882 | */ |
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 3e622c610925..dd38e62b84d2 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h | |||
| @@ -234,6 +234,8 @@ static inline void unlock_memory_hotplug(void) {} | |||
| 234 | 234 | ||
| 235 | extern int is_mem_section_removable(unsigned long pfn, unsigned long nr_pages); | 235 | extern int is_mem_section_removable(unsigned long pfn, unsigned long nr_pages); |
| 236 | extern void try_offline_node(int nid); | 236 | extern void try_offline_node(int nid); |
| 237 | extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); | ||
| 238 | extern void remove_memory(int nid, u64 start, u64 size); | ||
| 237 | 239 | ||
| 238 | #else | 240 | #else |
| 239 | static inline int is_mem_section_removable(unsigned long pfn, | 241 | static inline int is_mem_section_removable(unsigned long pfn, |
| @@ -243,15 +245,23 @@ static inline int is_mem_section_removable(unsigned long pfn, | |||
| 243 | } | 245 | } |
| 244 | 246 | ||
| 245 | static inline void try_offline_node(int nid) {} | 247 | static inline void try_offline_node(int nid) {} |
| 248 | |||
| 249 | static inline int offline_pages(unsigned long start_pfn, unsigned long nr_pages) | ||
| 250 | { | ||
| 251 | return -EINVAL; | ||
| 252 | } | ||
| 253 | |||
| 254 | static inline void remove_memory(int nid, u64 start, u64 size) {} | ||
| 246 | #endif /* CONFIG_MEMORY_HOTREMOVE */ | 255 | #endif /* CONFIG_MEMORY_HOTREMOVE */ |
| 247 | 256 | ||
| 257 | extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, | ||
| 258 | void *arg, int (*func)(struct memory_block *, void *)); | ||
| 248 | extern int mem_online_node(int nid); | 259 | extern int mem_online_node(int nid); |
| 249 | extern int add_memory(int nid, u64 start, u64 size); | 260 | extern int add_memory(int nid, u64 start, u64 size); |
| 250 | extern int arch_add_memory(int nid, u64 start, u64 size); | 261 | extern int arch_add_memory(int nid, u64 start, u64 size); |
| 251 | extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); | 262 | extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); |
| 252 | extern int offline_memory_block(struct memory_block *mem); | ||
| 253 | extern bool is_memblock_offlined(struct memory_block *mem); | 263 | extern bool is_memblock_offlined(struct memory_block *mem); |
| 254 | extern int remove_memory(int nid, u64 start, u64 size); | 264 | extern void remove_memory(int nid, u64 start, u64 size); |
| 255 | extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, | 265 | extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, |
| 256 | int nr_pages); | 266 | int nr_pages); |
| 257 | extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); | 267 | extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); |
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 1ad92b46753e..081b4d654ed6 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c | |||
| @@ -1621,6 +1621,7 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages) | |||
| 1621 | { | 1621 | { |
| 1622 | return __offline_pages(start_pfn, start_pfn + nr_pages, 120 * HZ); | 1622 | return __offline_pages(start_pfn, start_pfn + nr_pages, 120 * HZ); |
| 1623 | } | 1623 | } |
| 1624 | #endif /* CONFIG_MEMORY_HOTREMOVE */ | ||
| 1624 | 1625 | ||
| 1625 | /** | 1626 | /** |
| 1626 | * walk_memory_range - walks through all mem sections in [start_pfn, end_pfn) | 1627 | * walk_memory_range - walks through all mem sections in [start_pfn, end_pfn) |
| @@ -1634,7 +1635,7 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages) | |||
| 1634 | * | 1635 | * |
| 1635 | * Returns the return value of func. | 1636 | * Returns the return value of func. |
| 1636 | */ | 1637 | */ |
| 1637 | static int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, | 1638 | int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, |
| 1638 | void *arg, int (*func)(struct memory_block *, void *)) | 1639 | void *arg, int (*func)(struct memory_block *, void *)) |
| 1639 | { | 1640 | { |
| 1640 | struct memory_block *mem = NULL; | 1641 | struct memory_block *mem = NULL; |
| @@ -1671,24 +1672,7 @@ static int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, | |||
| 1671 | return 0; | 1672 | return 0; |
| 1672 | } | 1673 | } |
| 1673 | 1674 | ||
| 1674 | /** | 1675 | #ifdef CONFIG_MEMORY_HOTREMOVE |
| 1675 | * offline_memory_block_cb - callback function for offlining memory block | ||
| 1676 | * @mem: the memory block to be offlined | ||
| 1677 | * @arg: buffer to hold error msg | ||
| 1678 | * | ||
| 1679 | * Always return 0, and put the error msg in arg if any. | ||
| 1680 | */ | ||
| 1681 | static int offline_memory_block_cb(struct memory_block *mem, void *arg) | ||
| 1682 | { | ||
| 1683 | int *ret = arg; | ||
| 1684 | int error = offline_memory_block(mem); | ||
| 1685 | |||
| 1686 | if (error != 0 && *ret == 0) | ||
| 1687 | *ret = error; | ||
| 1688 | |||
| 1689 | return 0; | ||
| 1690 | } | ||
| 1691 | |||
| 1692 | static int is_memblock_offlined_cb(struct memory_block *mem, void *arg) | 1676 | static int is_memblock_offlined_cb(struct memory_block *mem, void *arg) |
| 1693 | { | 1677 | { |
| 1694 | int ret = !is_memblock_offlined(mem); | 1678 | int ret = !is_memblock_offlined(mem); |
| @@ -1814,54 +1798,22 @@ void try_offline_node(int nid) | |||
| 1814 | } | 1798 | } |
| 1815 | EXPORT_SYMBOL(try_offline_node); | 1799 | EXPORT_SYMBOL(try_offline_node); |
| 1816 | 1800 | ||
| 1817 | int __ref remove_memory(int nid, u64 start, u64 size) | 1801 | void __ref remove_memory(int nid, u64 start, u64 size) |
| 1818 | { | 1802 | { |
| 1819 | unsigned long start_pfn, end_pfn; | 1803 | int ret; |
| 1820 | int ret = 0; | ||
| 1821 | int retry = 1; | ||
| 1822 | |||
| 1823 | start_pfn = PFN_DOWN(start); | ||
| 1824 | end_pfn = PFN_UP(start + size - 1); | ||
| 1825 | |||
| 1826 | /* | ||
| 1827 | * When CONFIG_MEMCG is on, one memory block may be used by other | ||
| 1828 | * blocks to store page cgroup when onlining pages. But we don't know | ||
| 1829 | * in what order pages are onlined. So we iterate twice to offline | ||
| 1830 | * memory: | ||
| 1831 | * 1st iterate: offline every non primary memory block. | ||
| 1832 | * 2nd iterate: offline primary (i.e. first added) memory block. | ||
| 1833 | */ | ||
| 1834 | repeat: | ||
| 1835 | walk_memory_range(start_pfn, end_pfn, &ret, | ||
| 1836 | offline_memory_block_cb); | ||
| 1837 | if (ret) { | ||
| 1838 | if (!retry) | ||
| 1839 | return ret; | ||
| 1840 | |||
| 1841 | retry = 0; | ||
| 1842 | ret = 0; | ||
| 1843 | goto repeat; | ||
| 1844 | } | ||
| 1845 | 1804 | ||
| 1846 | lock_memory_hotplug(); | 1805 | lock_memory_hotplug(); |
| 1847 | 1806 | ||
| 1848 | /* | 1807 | /* |
| 1849 | * we have offlined all memory blocks like this: | 1808 | * All memory blocks must be offlined before removing memory. Check |
| 1850 | * 1. lock memory hotplug | 1809 | * whether all memory blocks in question are offline and trigger a BUG() |
| 1851 | * 2. offline a memory block | 1810 | * if this is not the case. |
| 1852 | * 3. unlock memory hotplug | ||
| 1853 | * | ||
| 1854 | * repeat step1-3 to offline the memory block. All memory blocks | ||
| 1855 | * must be offlined before removing memory. But we don't hold the | ||
| 1856 | * lock in the whole operation. So we should check whether all | ||
| 1857 | * memory blocks are offlined. | ||
| 1858 | */ | 1811 | */ |
| 1859 | 1812 | ret = walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), NULL, | |
| 1860 | ret = walk_memory_range(start_pfn, end_pfn, NULL, | ||
| 1861 | is_memblock_offlined_cb); | 1813 | is_memblock_offlined_cb); |
| 1862 | if (ret) { | 1814 | if (ret) { |
| 1863 | unlock_memory_hotplug(); | 1815 | unlock_memory_hotplug(); |
| 1864 | return ret; | 1816 | BUG(); |
| 1865 | } | 1817 | } |
| 1866 | 1818 | ||
| 1867 | /* remove memmap entry */ | 1819 | /* remove memmap entry */ |
| @@ -1872,17 +1824,6 @@ repeat: | |||
| 1872 | try_offline_node(nid); | 1824 | try_offline_node(nid); |
| 1873 | 1825 | ||
| 1874 | unlock_memory_hotplug(); | 1826 | unlock_memory_hotplug(); |
| 1875 | |||
| 1876 | return 0; | ||
| 1877 | } | 1827 | } |
| 1878 | #else | ||
| 1879 | int offline_pages(unsigned long start_pfn, unsigned long nr_pages) | ||
| 1880 | { | ||
| 1881 | return -EINVAL; | ||
| 1882 | } | ||
| 1883 | int remove_memory(int nid, u64 start, u64 size) | ||
| 1884 | { | ||
| 1885 | return -EINVAL; | ||
| 1886 | } | ||
| 1887 | #endif /* CONFIG_MEMORY_HOTREMOVE */ | ||
| 1888 | EXPORT_SYMBOL_GPL(remove_memory); | 1828 | EXPORT_SYMBOL_GPL(remove_memory); |
| 1829 | #endif /* CONFIG_MEMORY_HOTREMOVE */ | ||
