blob: 50be27739fe8ea1249b0e2cffde82b5b075b45fb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * acpi_processor.c - ACPI Processor Driver ($Revision: 71 $)
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 * - Added processor hotplug support
9 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 *
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 */
34
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/init.h>
38#include <linux/types.h>
39#include <linux/pci.h>
40#include <linux/pm.h>
41#include <linux/cpufreq.h>
42#include <linux/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/dmi.h>
44#include <linux/moduleparam.h>
Len Brown4f86d3a2007-10-03 18:58:00 -040045#include <linux/cpuidle.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090046#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48#include <asm/io.h>
49#include <asm/system.h>
50#include <asm/cpu.h>
51#include <asm/delay.h>
52#include <asm/uaccess.h>
53#include <asm/processor.h>
54#include <asm/smp.h>
55#include <asm/acpi.h>
56
57#include <acpi/acpi_bus.h>
58#include <acpi/acpi_drivers.h>
59#include <acpi/processor.h>
60
Len Browna192a952009-07-28 16:45:54 -040061#define PREFIX "ACPI: "
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define ACPI_PROCESSOR_CLASS "processor"
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#define ACPI_PROCESSOR_DEVICE_NAME "Processor"
65#define ACPI_PROCESSOR_FILE_INFO "info"
66#define ACPI_PROCESSOR_FILE_THROTTLING "throttling"
67#define ACPI_PROCESSOR_FILE_LIMIT "limit"
68#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
69#define ACPI_PROCESSOR_NOTIFY_POWER 0x81
Luming Yu01854e62007-05-26 22:49:58 +080070#define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82
Toshi Kani9f324bd2012-03-19 13:08:02 -060071#define ACPI_PROCESSOR_DEVICE_HID "ACPI0007"
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73#define ACPI_PROCESSOR_LIMIT_USER 0
74#define ACPI_PROCESSOR_LIMIT_THERMAL 1
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#define _COMPONENT ACPI_PROCESSOR_COMPONENT
Alex Chiang0131aa32010-02-22 12:11:08 -070077ACPI_MODULE_NAME("processor_driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Len Brownf52fd662007-02-12 22:42:12 -050079MODULE_AUTHOR("Paul Diefenbaugh");
Len Brown7cda93e2007-02-12 23:50:02 -050080MODULE_DESCRIPTION("ACPI Processor Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070081MODULE_LICENSE("GPL");
82
Len Brown4be44fc2005-08-05 00:44:28 -040083static int acpi_processor_add(struct acpi_device *device);
Len Brown4be44fc2005-08-05 00:44:28 -040084static int acpi_processor_remove(struct acpi_device *device, int type);
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +000085static void acpi_processor_notify(struct acpi_device *device, u32 event);
Thomas Renninger3bd81a82012-01-17 22:40:07 +010086static acpi_status acpi_processor_hotadd_init(struct acpi_processor *pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static int acpi_processor_handle_eject(struct acpi_processor *pr);
Thomas Renninger99b72502012-01-19 18:18:43 +010088static int acpi_processor_start(struct acpi_processor *pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Thomas Renninger1ba90e32007-07-23 14:44:41 +020090static const struct acpi_device_id processor_device_ids[] = {
Myron Stowead93a762008-11-04 14:52:55 -070091 {ACPI_PROCESSOR_OBJECT_HID, 0},
Toshi Kani9f324bd2012-03-19 13:08:02 -060092 {ACPI_PROCESSOR_DEVICE_HID, 0},
Thomas Renninger1ba90e32007-07-23 14:44:41 +020093 {"", 0},
94};
95MODULE_DEVICE_TABLE(acpi, processor_device_ids);
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static struct acpi_driver acpi_processor_driver = {
Len Brownc2b67052007-02-12 23:33:40 -050098 .name = "processor",
Len Brown4be44fc2005-08-05 00:44:28 -040099 .class = ACPI_PROCESSOR_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200100 .ids = processor_device_ids,
Len Brown4be44fc2005-08-05 00:44:28 -0400101 .ops = {
102 .add = acpi_processor_add,
103 .remove = acpi_processor_remove,
Thomas Gleixnerb04e7bd2007-09-22 22:29:05 +0000104 .suspend = acpi_processor_suspend,
105 .resume = acpi_processor_resume,
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000106 .notify = acpi_processor_notify,
Len Brown4be44fc2005-08-05 00:44:28 -0400107 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108};
109
110#define INSTALL_NOTIFY_HANDLER 1
111#define UNINSTALL_NOTIFY_HANDLER 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Mike Travis706546d2008-06-09 16:22:23 -0700113DEFINE_PER_CPU(struct acpi_processor *, processors);
Naga Chumbalkar0f1d6832009-12-17 20:18:27 +0000114EXPORT_PER_CPU_SYMBOL(processors);
115
Andreas Mohr9f222712006-06-23 02:04:27 -0700116struct acpi_processor_errata errata __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118/* --------------------------------------------------------------------------
119 Errata Handling
120 -------------------------------------------------------------------------- */
121
Len Brown4be44fc2005-08-05 00:44:28 -0400122static int acpi_processor_errata_piix4(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Len Brown4be44fc2005-08-05 00:44:28 -0400124 u8 value1 = 0;
125 u8 value2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400129 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 /*
132 * Note that 'dev' references the PIIX4 ACPI Controller.
133 */
134
Auke Kok44c10132007-06-08 15:46:36 -0700135 switch (dev->revision) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 case 0:
137 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
138 break;
139 case 1:
140 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n"));
141 break;
142 case 2:
143 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n"));
144 break;
145 case 3:
146 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n"));
147 break;
148 default:
149 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n"));
150 break;
151 }
152
Auke Kok44c10132007-06-08 15:46:36 -0700153 switch (dev->revision) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 case 0: /* PIIX4 A-step */
156 case 1: /* PIIX4 B-step */
157 /*
158 * See specification changes #13 ("Manual Throttle Duty Cycle")
159 * and #14 ("Enabling and Disabling Manual Throttle"), plus
160 * erratum #5 ("STPCLK# Deassertion Time") from the January
161 * 2002 PIIX4 specification update. Applies to only older
162 * PIIX4 models.
163 */
164 errata.piix4.throttle = 1;
165
166 case 2: /* PIIX4E */
167 case 3: /* PIIX4M */
168 /*
169 * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
170 * Livelock") from the January 2002 PIIX4 specification update.
171 * Applies to all PIIX4 models.
172 */
173
174 /*
175 * BM-IDE
176 * ------
177 * Find the PIIX4 IDE Controller and get the Bus Master IDE
178 * Status register address. We'll use this later to read
179 * each IDE controller's DMA status to make sure we catch all
180 * DMA activity.
181 */
182 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
Len Brown4be44fc2005-08-05 00:44:28 -0400183 PCI_DEVICE_ID_INTEL_82371AB,
184 PCI_ANY_ID, PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 if (dev) {
186 errata.piix4.bmisx = pci_resource_start(dev, 4);
187 pci_dev_put(dev);
188 }
189
190 /*
191 * Type-F DMA
192 * ----------
193 * Find the PIIX4 ISA Controller and read the Motherboard
194 * DMA controller's status to see if Type-F (Fast) DMA mode
195 * is enabled (bit 7) on either channel. Note that we'll
196 * disable C3 support if this is enabled, as some legacy
197 * devices won't operate well if fast DMA is disabled.
198 */
199 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
Len Brown4be44fc2005-08-05 00:44:28 -0400200 PCI_DEVICE_ID_INTEL_82371AB_0,
201 PCI_ANY_ID, PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 if (dev) {
203 pci_read_config_byte(dev, 0x76, &value1);
204 pci_read_config_byte(dev, 0x77, &value2);
205 if ((value1 & 0x80) || (value2 & 0x80))
206 errata.piix4.fdma = 1;
207 pci_dev_put(dev);
208 }
209
210 break;
211 }
212
213 if (errata.piix4.bmisx)
214 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400215 "Bus master activity detection (BM-IDE) erratum enabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 if (errata.piix4.fdma)
217 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400218 "Type-F DMA livelock erratum (C3 disabled)\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Patrick Mocheld550d982006-06-27 00:41:40 -0400220 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
222
Adrian Bunk8713cbe2005-09-02 17:16:48 -0400223static int acpi_processor_errata(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Len Brown4be44fc2005-08-05 00:44:28 -0400225 int result = 0;
226 struct pci_dev *dev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400230 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 /*
233 * PIIX4
234 */
235 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
Len Brown4be44fc2005-08-05 00:44:28 -0400236 PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
237 PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 if (dev) {
239 result = acpi_processor_errata_piix4(dev);
240 pci_dev_put(dev);
241 }
242
Patrick Mocheld550d982006-06-27 00:41:40 -0400243 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246/* --------------------------------------------------------------------------
247 Driver Interface
248 -------------------------------------------------------------------------- */
249
Myron Stoweb26e9282008-11-04 14:53:00 -0700250static int acpi_processor_get_info(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Len Brown4be44fc2005-08-05 00:44:28 -0400252 acpi_status status = 0;
253 union acpi_object object = { 0 };
254 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
Myron Stoweb26e9282008-11-04 14:53:00 -0700255 struct acpi_processor *pr;
256 int cpu_index, device_declaration = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400257 static int cpu0_initialized;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Myron Stoweb26e9282008-11-04 14:53:00 -0700259 pr = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400261 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 if (num_online_cpus() > 1)
264 errata.smp = TRUE;
265
266 acpi_processor_errata(pr);
267
268 /*
269 * Check to see if we have bus mastering arbitration control. This
270 * is required for proper C3 usage (to maintain cache coherency).
271 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300272 if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 pr->flags.bm_control = 1;
274 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400275 "Bus mastering arbitration control present\n"));
276 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400278 "No bus mastering arbitration control\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Bjorn Helgaas6cc73b42009-04-27 16:33:41 -0600280 if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) {
281 /* Declared with "Processor" statement; match ProcessorID */
282 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
283 if (ACPI_FAILURE(status)) {
284 printk(KERN_ERR PREFIX "Evaluating processor object\n");
285 return -ENODEV;
286 }
287
288 /*
289 * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
290 * >>> 'acpi_get_processor_id(acpi_id, &id)' in
291 * arch/xxx/acpi.c
292 */
293 pr->acpi_id = object.processor.proc_id;
294 } else {
Myron Stoweb26e9282008-11-04 14:53:00 -0700295 /*
296 * Declared with "Device" statement; match _UID.
297 * Note that we don't handle string _UIDs yet.
298 */
Matthew Wilcox27663c52008-10-10 02:22:59 -0400299 unsigned long long value;
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300300 status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
301 NULL, &value);
302 if (ACPI_FAILURE(status)) {
Myron Stoweb26e9282008-11-04 14:53:00 -0700303 printk(KERN_ERR PREFIX
304 "Evaluating processor _UID [%#x]\n", status);
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300305 return -ENODEV;
306 }
Myron Stoweb26e9282008-11-04 14:53:00 -0700307 device_declaration = 1;
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300308 pr->acpi_id = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
Alex Chiang2e9d5e42010-02-22 12:11:19 -0700310 cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Len Brown4be44fc2005-08-05 00:44:28 -0400312 /* Handle UP system running SMP kernel, with no LAPIC in MADT */
Ashok Rajdf42baa2006-03-28 17:04:00 -0500313 if (!cpu0_initialized && (cpu_index == -1) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400314 (num_online_cpus() == 1)) {
315 cpu_index = 0;
316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Len Brown4be44fc2005-08-05 00:44:28 -0400318 cpu0_initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Len Brown4be44fc2005-08-05 00:44:28 -0400320 pr->id = cpu_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Len Brown4be44fc2005-08-05 00:44:28 -0400322 /*
323 * Extra Processor objects may be enumerated on MP systems with
324 * less than the max # of CPUs. They should be ignored _iff
325 * they are physically not present.
326 */
Alexey Starikovskiyf18c5a02007-02-02 19:48:23 +0300327 if (pr->id == -1) {
Thomas Renninger3bd81a82012-01-17 22:40:07 +0100328 if (ACPI_FAILURE(acpi_processor_hotadd_init(pr)))
Patrick Mocheld550d982006-06-27 00:41:40 -0400329 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400330 }
Zhao Yakui7a04b842009-06-24 11:46:44 +0800331 /*
332 * On some boxes several processors use the same processor bus id.
333 * But they are located in different scope. For example:
334 * \_SB.SCK0.CPU0
335 * \_SB.SCK1.CPU0
336 * Rename the processor device bus id. And the new bus id will be
337 * generated as the following format:
338 * CPU+CPU ID.
339 */
340 sprintf(acpi_device_bid(device), "CPU%X", pr->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
Len Brown4be44fc2005-08-05 00:44:28 -0400342 pr->acpi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 if (!object.processor.pblk_address)
345 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
346 else if (object.processor.pblk_length != 6)
Len Brown64684632006-06-26 23:41:38 -0400347 printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n",
348 object.processor.pblk_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 else {
350 pr->throttling.address = object.processor.pblk_address;
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300351 pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
352 pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 pr->pblk = object.processor.pblk_address;
355
356 /*
357 * We don't care about error returns - we just try to mark
358 * these reserved so that nobody else is confused into thinking
359 * that this region might be unused..
360 *
361 * (In particular, allocating the IO range for Cardbus)
362 */
363 request_region(pr->throttling.address, 6, "ACPI CPU throttle");
364 }
365
Alex Chiangfe086a72008-04-29 15:05:29 -0700366 /*
367 * If ACPI describes a slot number for this CPU, we can use it
368 * ensure we get the right value in the "physical id" field
369 * of /proc/cpuinfo
370 */
371 status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer);
372 if (ACPI_SUCCESS(status))
373 arch_fix_phys_package_id(pr->id, object.integer.value);
374
Patrick Mocheld550d982006-06-27 00:41:40 -0400375 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
Mike Travis706546d2008-06-09 16:22:23 -0700378static DEFINE_PER_CPU(void *, processor_device_array);
Venkatesh Pallipadicd8e2b42005-10-21 19:22:00 -0400379
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000380static void acpi_processor_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000382 struct acpi_processor *pr = acpi_driver_data(device);
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300383 int saved;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400386 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 switch (event) {
389 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300390 saved = pr->performance_platform_limit;
Zhao Yakuid81c45e12009-10-16 09:20:41 +0800391 acpi_processor_ppc_has_changed(pr, 1);
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300392 if (saved == pr->performance_platform_limit)
393 break;
Len Brown14e04fb32007-08-23 15:20:26 -0400394 acpi_bus_generate_proc_event(device, event,
Len Brown4be44fc2005-08-05 00:44:28 -0400395 pr->performance_platform_limit);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800396 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100397 dev_name(&device->dev), event,
Zhang Rui962ce8c2007-08-23 01:24:31 +0800398 pr->performance_platform_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 break;
400 case ACPI_PROCESSOR_NOTIFY_POWER:
401 acpi_processor_cst_has_changed(pr);
Len Brown14e04fb32007-08-23 15:20:26 -0400402 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800403 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100404 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 break;
Luming Yu01854e62007-05-26 22:49:58 +0800406 case ACPI_PROCESSOR_NOTIFY_THROTTLING:
407 acpi_processor_tstate_has_changed(pr);
Len Brown14e04fb32007-08-23 15:20:26 -0400408 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800409 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100410 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 default:
412 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400413 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 break;
415 }
416
Patrick Mocheld550d982006-06-27 00:41:40 -0400417 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200420static int acpi_cpu_soft_notify(struct notifier_block *nfb,
421 unsigned long action, void *hcpu)
422{
423 unsigned int cpu = (unsigned long)hcpu;
Mike Travis706546d2008-06-09 16:22:23 -0700424 struct acpi_processor *pr = per_cpu(processors, cpu);
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200425
426 if (action == CPU_ONLINE && pr) {
Thomas Renninger99b72502012-01-19 18:18:43 +0100427 /* CPU got physically hotplugged and onlined the first time:
428 * Initialize missing things
429 */
430 if (pr->flags.need_hotplug_init) {
431 struct cpuidle_driver *idle_driver =
432 cpuidle_get_driver();
433
434 printk(KERN_INFO "Will online and init hotplugged "
435 "CPU: %d\n", pr->id);
436 WARN(acpi_processor_start(pr), "Failed to start CPU:"
437 " %d\n", pr->id);
438 pr->flags.need_hotplug_init = 0;
439 if (idle_driver && !strcmp(idle_driver->name,
440 "intel_idle")) {
441 intel_idle_cpu_init(pr->id);
442 }
443 /* Normal CPU soft online event */
444 } else {
445 acpi_processor_ppc_has_changed(pr, 0);
446 acpi_processor_cst_has_changed(pr);
447 acpi_processor_reevaluate_tstate(pr, action);
448 acpi_processor_tstate_has_changed(pr);
449 }
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200450 }
Zhao Yakui5a344a52011-01-10 16:35:45 +0800451 if (action == CPU_DEAD && pr) {
452 /* invalidate the flag.throttling after one CPU is offline */
453 acpi_processor_reevaluate_tstate(pr, action);
454 }
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200455 return NOTIFY_OK;
456}
457
458static struct notifier_block acpi_cpu_notifier =
459{
460 .notifier_call = acpi_cpu_soft_notify,
461};
462
Thomas Renninger99b72502012-01-19 18:18:43 +0100463/*
464 * acpi_processor_start() is called by the cpu_hotplug_notifier func:
465 * acpi_cpu_soft_notify(). Getting it __cpuinit{data} is difficult, the
466 * root cause seem to be that acpi_processor_uninstall_hotplug_notify()
467 * is in the module_exit (__exit) func. Allowing acpi_processor_start()
468 * to not be in __cpuinit section, but being called from __cpuinit funcs
469 * via __ref looks like the right thing to do here.
470 */
471static __ref int acpi_processor_start(struct acpi_processor *pr)
Thomas Renninger54d5dcc2012-01-19 18:18:42 +0100472{
473 struct acpi_device *device = per_cpu(processor_device_array, pr->id);
474 int result = 0;
475
476#ifdef CONFIG_CPU_FREQ
477 acpi_processor_ppc_has_changed(pr, 0);
478#endif
479 acpi_processor_get_throttling_info(pr);
480 acpi_processor_get_limit_info(pr);
481
482 if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
483 acpi_processor_power_init(pr, device);
484
485 pr->cdev = thermal_cooling_device_register("Processor", device,
486 &processor_cooling_ops);
487 if (IS_ERR(pr->cdev)) {
488 result = PTR_ERR(pr->cdev);
489 goto err_power_exit;
490 }
491
492 dev_dbg(&device->dev, "registered as cooling_device%d\n",
493 pr->cdev->id);
494
495 result = sysfs_create_link(&device->dev.kobj,
496 &pr->cdev->device.kobj,
497 "thermal_cooling");
498 if (result) {
499 printk(KERN_ERR PREFIX "Create sysfs link\n");
500 goto err_thermal_unregister;
501 }
502 result = sysfs_create_link(&pr->cdev->device.kobj,
503 &device->dev.kobj,
504 "device");
505 if (result) {
506 printk(KERN_ERR PREFIX "Create sysfs link\n");
507 goto err_remove_sysfs_thermal;
508 }
509
510 return 0;
511
512err_remove_sysfs_thermal:
513 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
514err_thermal_unregister:
515 thermal_cooling_device_unregister(pr->cdev);
516err_power_exit:
517 acpi_processor_power_exit(pr, device);
518
519 return result;
520}
521
Thomas Renninger99b72502012-01-19 18:18:43 +0100522/*
523 * Do not put anything in here which needs the core to be online.
524 * For example MSR access or setting up things which check for cpuinfo_x86
525 * (cpu_data(cpu)) values, like CPU feature flags, family, model, etc.
526 * Such things have to be put in and set up above in acpi_processor_start()
527 */
Rakib Mullick941b10f2009-11-05 16:51:40 -0500528static int __cpuinit acpi_processor_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
Len Brown4be44fc2005-08-05 00:44:28 -0400530 struct acpi_processor *pr = NULL;
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000531 int result = 0;
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800532 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Burman Yan36bcbec2006-12-19 12:56:11 -0800534 pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400536 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Yinghai Lueaa95842009-06-06 14:51:36 -0700538 if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) {
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800539 kfree(pr);
540 return -ENOMEM;
541 }
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 pr->handle = device->handle;
544 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
545 strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700546 device->driver_data = pr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 result = acpi_processor_get_info(device);
549 if (result) {
550 /* Processor is physically not present */
551 return 0;
552 }
553
Thomas Renninger75cbfb92010-05-26 17:03:33 +0200554#ifdef CONFIG_SMP
555 if (pr->id >= setup_max_cpus && pr->id != 0)
556 return 0;
557#endif
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
560
561 /*
562 * Buggy BIOS check
563 * ACPI id of processors can be reported wrongly by the BIOS.
564 * Don't trust it blindly
565 */
566 if (per_cpu(processor_device_array, pr->id) != NULL &&
567 per_cpu(processor_device_array, pr->id) != device) {
568 printk(KERN_WARNING "BIOS reported wrong ACPI id "
569 "for the processor\n");
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000570 result = -ENODEV;
571 goto err_free_cpumask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 }
573 per_cpu(processor_device_array, pr->id) = device;
574
575 per_cpu(processors, pr->id) = pr;
576
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800577 dev = get_cpu_device(pr->id);
578 if (sysfs_create_link(&device->dev.kobj, &dev->kobj, "sysdev")) {
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000579 result = -EFAULT;
Zhang Ruicef6e8a2010-12-06 15:04:15 +0800580 goto err_free_cpumask;
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000581 }
Thomas Renninger99b72502012-01-19 18:18:43 +0100582
583 /*
584 * Do not start hotplugged CPUs now, but when they
585 * are onlined the first time
586 */
587 if (pr->flags.need_hotplug_init)
588 return 0;
589
Thomas Renninger54d5dcc2012-01-19 18:18:42 +0100590 result = acpi_processor_start(pr);
591 if (result)
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000592 goto err_remove_sysfs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Patrick Mocheld550d982006-06-27 00:41:40 -0400594 return 0;
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000595
596err_remove_sysfs:
Thomas Renninger3333ea72011-11-17 23:37:00 +0100597 sysfs_remove_link(&device->dev.kobj, "sysdev");
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000598err_free_cpumask:
599 free_cpumask_var(pr->throttling.shared_cpu_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
603
Len Brown4be44fc2005-08-05 00:44:28 -0400604static int acpi_processor_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605{
Len Brown4be44fc2005-08-05 00:44:28 -0400606 struct acpi_processor *pr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400610 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200612 pr = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800614 if (pr->id >= nr_cpu_ids)
615 goto free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 if (type == ACPI_BUS_REMOVAL_EJECT) {
618 if (acpi_processor_handle_eject(pr))
Patrick Mocheld550d982006-06-27 00:41:40 -0400619 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621
622 acpi_processor_power_exit(pr, device);
623
Zhang Rui9f1eb992008-04-29 02:36:07 -0400624 sysfs_remove_link(&device->dev.kobj, "sysdev");
625
Zhao Yakuif28bb452008-02-15 08:34:37 +0800626 if (pr->cdev) {
627 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
628 sysfs_remove_link(&pr->cdev->device.kobj, "device");
629 thermal_cooling_device_unregister(pr->cdev);
630 pr->cdev = NULL;
631 }
Zhang Ruid9460fd222008-01-17 15:51:23 +0800632
Mike Travis706546d2008-06-09 16:22:23 -0700633 per_cpu(processors, pr->id) = NULL;
634 per_cpu(processor_device_array, pr->id) = NULL;
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800635
636free:
637 free_cpumask_var(pr->throttling.shared_cpu_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 kfree(pr);
639
Patrick Mocheld550d982006-06-27 00:41:40 -0400640 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641}
642
643#ifdef CONFIG_ACPI_HOTPLUG_CPU
644/****************************************************************************
645 * Acpi processor hotplug support *
646 ****************************************************************************/
647
Len Brown4be44fc2005-08-05 00:44:28 -0400648static int is_processor_present(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
Len Brown4be44fc2005-08-05 00:44:28 -0400650 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400651 unsigned long long sta = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
Zhang Ruicfaf3742008-01-09 02:17:47 -0500655
656 if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
657 return 1;
658
Zhang Ruid0ce46f2008-02-23 01:53:09 -0500659 /*
660 * _STA is mandatory for a processor that supports hot plug
661 */
662 if (status == AE_NOT_FOUND)
663 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
664 "Processor does not support hot plug\n"));
665 else
666 ACPI_EXCEPTION((AE_INFO, status,
667 "Processor Device is not present"));
Zhang Ruicfaf3742008-01-09 02:17:47 -0500668 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}
670
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671static
Len Brown4be44fc2005-08-05 00:44:28 -0400672int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673{
Len Brown4be44fc2005-08-05 00:44:28 -0400674 acpi_handle phandle;
675 struct acpi_device *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678 if (acpi_get_parent(handle, &phandle)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400679 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 }
681
682 if (acpi_bus_get_device(phandle, &pdev)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400683 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685
686 if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400687 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 }
689
Patrick Mocheld550d982006-06-27 00:41:40 -0400690 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691}
692
Jan Beulich6430c9c2011-02-17 16:33:53 +0000693static void acpi_processor_hotplug_notify(acpi_handle handle,
694 u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Len Brown4be44fc2005-08-05 00:44:28 -0400696 struct acpi_processor *pr;
697 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 int result;
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
701 switch (event) {
702 case ACPI_NOTIFY_BUS_CHECK:
703 case ACPI_NOTIFY_DEVICE_CHECK:
Glauber Costad6f882e2008-03-04 15:06:36 -0800704 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
705 "Processor driver received %s event\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400706 (event == ACPI_NOTIFY_BUS_CHECK) ?
Glauber Costad6f882e2008-03-04 15:06:36 -0800707 "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
709 if (!is_processor_present(handle))
710 break;
711
712 if (acpi_bus_get_device(handle, &device)) {
713 result = acpi_processor_device_add(handle, &device);
714 if (result)
Len Brown64684632006-06-26 23:41:38 -0400715 printk(KERN_ERR PREFIX
716 "Unable to add the device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 break;
718 }
Len Brown4be44fc2005-08-05 00:44:28 -0400719 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 case ACPI_NOTIFY_EJECT_REQUEST:
Len Brown4be44fc2005-08-05 00:44:28 -0400721 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
722 "received ACPI_NOTIFY_EJECT_REQUEST\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 if (acpi_bus_get_device(handle, &device)) {
Len Brown64684632006-06-26 23:41:38 -0400725 printk(KERN_ERR PREFIX
726 "Device don't exist, dropping EJECT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 break;
728 }
729 pr = acpi_driver_data(device);
730 if (!pr) {
Len Brown64684632006-06-26 23:41:38 -0400731 printk(KERN_ERR PREFIX
732 "Driver data is NULL, dropping EJECT\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400733 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 break;
736 default:
737 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400738 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 break;
740 }
741
Patrick Mocheld550d982006-06-27 00:41:40 -0400742 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743}
744
Toshi Kani9f324bd2012-03-19 13:08:02 -0600745static acpi_status is_processor_device(acpi_handle handle)
746{
747 struct acpi_device_info *info;
748 char *hid;
749 acpi_status status;
750
751 status = acpi_get_object_info(handle, &info);
752 if (ACPI_FAILURE(status))
753 return status;
754
755 if (info->type == ACPI_TYPE_PROCESSOR) {
756 kfree(info);
757 return AE_OK; /* found a processor object */
758 }
759
760 if (!(info->valid & ACPI_VALID_HID)) {
761 kfree(info);
762 return AE_ERROR;
763 }
764
765 hid = info->hardware_id.string;
766 if ((hid == NULL) || strcmp(hid, ACPI_PROCESSOR_DEVICE_HID)) {
767 kfree(info);
768 return AE_ERROR;
769 }
770
771 kfree(info);
772 return AE_OK; /* found a processor device object */
773}
774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775static acpi_status
776processor_walk_namespace_cb(acpi_handle handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400777 u32 lvl, void *context, void **rv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778{
Len Brown4be44fc2005-08-05 00:44:28 -0400779 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 int *action = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Toshi Kani9f324bd2012-03-19 13:08:02 -0600782 status = is_processor_device(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 if (ACPI_FAILURE(status))
Toshi Kani9f324bd2012-03-19 13:08:02 -0600784 return AE_OK; /* not a processor; continue to walk */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Len Brown4be44fc2005-08-05 00:44:28 -0400786 switch (*action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 case INSTALL_NOTIFY_HANDLER:
788 acpi_install_notify_handler(handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400789 ACPI_SYSTEM_NOTIFY,
790 acpi_processor_hotplug_notify,
791 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 break;
793 case UNINSTALL_NOTIFY_HANDLER:
794 acpi_remove_notify_handler(handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400795 ACPI_SYSTEM_NOTIFY,
796 acpi_processor_hotplug_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 break;
798 default:
799 break;
800 }
801
Toshi Kani9f324bd2012-03-19 13:08:02 -0600802 /* found a processor; skip walking underneath */
803 return AE_CTRL_DEPTH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804}
805
Thomas Renninger3bd81a82012-01-17 22:40:07 +0100806static acpi_status acpi_processor_hotadd_init(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
Thomas Renninger3bd81a82012-01-17 22:40:07 +0100808 acpi_handle handle = pr->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
810 if (!is_processor_present(handle)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400811 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 }
813
Thomas Renninger3bd81a82012-01-17 22:40:07 +0100814 if (acpi_map_lsapic(handle, &pr->id))
Patrick Mocheld550d982006-06-27 00:41:40 -0400815 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Thomas Renninger3bd81a82012-01-17 22:40:07 +0100817 if (arch_register_cpu(pr->id)) {
818 acpi_unmap_lsapic(pr->id);
Patrick Mocheld550d982006-06-27 00:41:40 -0400819 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 }
821
Thomas Renninger99b72502012-01-19 18:18:43 +0100822 /* CPU got hot-plugged, but cpu_data is not initialized yet
823 * Set flag to delay cpu_idle/throttling initialization
824 * in:
825 * acpi_processor_add()
826 * acpi_processor_get_info()
827 * and do it when the CPU gets online the first time
828 * TBD: Cleanup above functions and try to do this more elegant.
829 */
830 printk(KERN_INFO "CPU %d got hotplugged\n", pr->id);
831 pr->flags.need_hotplug_init = 1;
832
Patrick Mocheld550d982006-06-27 00:41:40 -0400833 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834}
835
Len Brown4be44fc2005-08-05 00:44:28 -0400836static int acpi_processor_handle_eject(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
Zhang Ruib62b8ef2008-04-29 02:35:56 -0400838 if (cpu_online(pr->id))
839 cpu_down(pr->id);
840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 arch_unregister_cpu(pr->id);
842 acpi_unmap_lsapic(pr->id);
Len Brown4be44fc2005-08-05 00:44:28 -0400843 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844}
845#else
Thomas Renninger3bd81a82012-01-17 22:40:07 +0100846static acpi_status acpi_processor_hotadd_init(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
848 return AE_ERROR;
849}
Len Brown4be44fc2005-08-05 00:44:28 -0400850static int acpi_processor_handle_eject(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
Len Brown4be44fc2005-08-05 00:44:28 -0400852 return (-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853}
854#endif
855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856static
857void acpi_processor_install_hotplug_notify(void)
858{
859#ifdef CONFIG_ACPI_HOTPLUG_CPU
860 int action = INSTALL_NOTIFY_HANDLER;
Toshi Kani9f324bd2012-03-19 13:08:02 -0600861 acpi_walk_namespace(ACPI_TYPE_ANY,
Len Brown4be44fc2005-08-05 00:44:28 -0400862 ACPI_ROOT_OBJECT,
863 ACPI_UINT32_MAX,
Lin Ming22635762009-11-13 10:06:08 +0800864 processor_walk_namespace_cb, NULL, &action, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865#endif
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200866 register_hotcpu_notifier(&acpi_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867}
868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869static
870void acpi_processor_uninstall_hotplug_notify(void)
871{
872#ifdef CONFIG_ACPI_HOTPLUG_CPU
873 int action = UNINSTALL_NOTIFY_HANDLER;
Toshi Kani9f324bd2012-03-19 13:08:02 -0600874 acpi_walk_namespace(ACPI_TYPE_ANY,
Len Brown4be44fc2005-08-05 00:44:28 -0400875 ACPI_ROOT_OBJECT,
876 ACPI_UINT32_MAX,
Lin Ming22635762009-11-13 10:06:08 +0800877 processor_walk_namespace_cb, NULL, &action, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878#endif
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200879 unregister_hotcpu_notifier(&acpi_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880}
881
882/*
883 * We keep the driver loaded even when ACPI is not running.
884 * This is needed for the powernow-k8 driver, that works even without
885 * ACPI, but needs symbols from this driver
886 */
887
Len Brown4be44fc2005-08-05 00:44:28 -0400888static int __init acpi_processor_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889{
Len Brown4be44fc2005-08-05 00:44:28 -0400890 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Yinghai Luce8442b2009-08-26 14:29:26 -0700892 if (acpi_disabled)
893 return 0;
894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 memset(&errata, 0, sizeof(errata));
896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 result = acpi_bus_register_driver(&acpi_processor_driver);
Len Brown4f86d3a2007-10-03 18:58:00 -0400898 if (result < 0)
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530899 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901 acpi_processor_install_hotplug_notify();
902
903 acpi_thermal_cpufreq_init();
904
905 acpi_processor_ppc_init();
906
Zhao Yakui11805092008-01-28 13:53:42 +0800907 acpi_processor_throttling_init();
908
Patrick Mocheld550d982006-06-27 00:41:40 -0400909 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910}
911
Len Brown4be44fc2005-08-05 00:44:28 -0400912static void __exit acpi_processor_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913{
Yinghai Luce8442b2009-08-26 14:29:26 -0700914 if (acpi_disabled)
915 return;
916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 acpi_processor_ppc_exit();
918
919 acpi_thermal_cpufreq_exit();
920
921 acpi_processor_uninstall_hotplug_notify();
922
923 acpi_bus_unregister_driver(&acpi_processor_driver);
924
Patrick Mocheld550d982006-06-27 00:41:40 -0400925 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926}
927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928module_init(acpi_processor_init);
929module_exit(acpi_processor_exit);
930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931MODULE_ALIAS("processor");