]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/acpi/processor_driver.c
ixgbe: cleanup ATR filter setup function
[net-next-2.6.git] / drivers / acpi / processor_driver.c
CommitLineData
1da177e4
LT
1/*
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>
d5c6887c 43#ifdef CONFIG_ACPI_PROCFS
1da177e4
LT
44#include <linux/proc_fs.h>
45#include <linux/seq_file.h>
d5c6887c 46#endif
1da177e4
LT
47#include <linux/dmi.h>
48#include <linux/moduleparam.h>
4f86d3a8 49#include <linux/cpuidle.h>
5a0e3ad6 50#include <linux/slab.h>
1da177e4
LT
51
52#include <asm/io.h>
53#include <asm/system.h>
54#include <asm/cpu.h>
55#include <asm/delay.h>
56#include <asm/uaccess.h>
57#include <asm/processor.h>
58#include <asm/smp.h>
59#include <asm/acpi.h>
60
61#include <acpi/acpi_bus.h>
62#include <acpi/acpi_drivers.h>
63#include <acpi/processor.h>
64
a192a958
LB
65#define PREFIX "ACPI: "
66
1da177e4 67#define ACPI_PROCESSOR_CLASS "processor"
1da177e4
LT
68#define ACPI_PROCESSOR_DEVICE_NAME "Processor"
69#define ACPI_PROCESSOR_FILE_INFO "info"
70#define ACPI_PROCESSOR_FILE_THROTTLING "throttling"
71#define ACPI_PROCESSOR_FILE_LIMIT "limit"
72#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
73#define ACPI_PROCESSOR_NOTIFY_POWER 0x81
01854e69 74#define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82
1da177e4
LT
75
76#define ACPI_PROCESSOR_LIMIT_USER 0
77#define ACPI_PROCESSOR_LIMIT_THERMAL 1
78
1da177e4 79#define _COMPONENT ACPI_PROCESSOR_COMPONENT
0131aa3d 80ACPI_MODULE_NAME("processor_driver");
1da177e4 81
f52fd66d 82MODULE_AUTHOR("Paul Diefenbaugh");
7cda93e0 83MODULE_DESCRIPTION("ACPI Processor Driver");
1da177e4
LT
84MODULE_LICENSE("GPL");
85
4be44fcd 86static int acpi_processor_add(struct acpi_device *device);
4be44fcd 87static int acpi_processor_remove(struct acpi_device *device, int type);
7ec0a729 88static void acpi_processor_notify(struct acpi_device *device, u32 event);
1da177e4
LT
89static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
90static int acpi_processor_handle_eject(struct acpi_processor *pr);
01854e69 91
1da177e4 92
1ba90e3a 93static const struct acpi_device_id processor_device_ids[] = {
ad93a765 94 {ACPI_PROCESSOR_OBJECT_HID, 0},
9eccbc2f 95 {"ACPI0007", 0},
1ba90e3a
TR
96 {"", 0},
97};
98MODULE_DEVICE_TABLE(acpi, processor_device_ids);
99
1da177e4 100static struct acpi_driver acpi_processor_driver = {
c2b6705b 101 .name = "processor",
4be44fcd 102 .class = ACPI_PROCESSOR_CLASS,
1ba90e3a 103 .ids = processor_device_ids,
4be44fcd
LB
104 .ops = {
105 .add = acpi_processor_add,
106 .remove = acpi_processor_remove,
b04e7bdb
TG
107 .suspend = acpi_processor_suspend,
108 .resume = acpi_processor_resume,
7ec0a729 109 .notify = acpi_processor_notify,
4be44fcd 110 },
1da177e4
LT
111};
112
113#define INSTALL_NOTIFY_HANDLER 1
114#define UNINSTALL_NOTIFY_HANDLER 2
1da177e4 115
706546d0 116DEFINE_PER_CPU(struct acpi_processor *, processors);
0f1d683f
NC
117EXPORT_PER_CPU_SYMBOL(processors);
118
9f222718 119struct acpi_processor_errata errata __read_mostly;
1da177e4 120
1da177e4
LT
121/* --------------------------------------------------------------------------
122 Errata Handling
123 -------------------------------------------------------------------------- */
124
4be44fcd 125static int acpi_processor_errata_piix4(struct pci_dev *dev)
1da177e4 126{
4be44fcd
LB
127 u8 value1 = 0;
128 u8 value2 = 0;
1da177e4 129
1da177e4
LT
130
131 if (!dev)
d550d98d 132 return -EINVAL;
1da177e4
LT
133
134 /*
135 * Note that 'dev' references the PIIX4 ACPI Controller.
136 */
137
44c10138 138 switch (dev->revision) {
1da177e4
LT
139 case 0:
140 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
141 break;
142 case 1:
143 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n"));
144 break;
145 case 2:
146 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n"));
147 break;
148 case 3:
149 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n"));
150 break;
151 default:
152 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n"));
153 break;
154 }
155
44c10138 156 switch (dev->revision) {
1da177e4
LT
157
158 case 0: /* PIIX4 A-step */
159 case 1: /* PIIX4 B-step */
160 /*
161 * See specification changes #13 ("Manual Throttle Duty Cycle")
162 * and #14 ("Enabling and Disabling Manual Throttle"), plus
163 * erratum #5 ("STPCLK# Deassertion Time") from the January
164 * 2002 PIIX4 specification update. Applies to only older
165 * PIIX4 models.
166 */
167 errata.piix4.throttle = 1;
168
169 case 2: /* PIIX4E */
170 case 3: /* PIIX4M */
171 /*
172 * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
173 * Livelock") from the January 2002 PIIX4 specification update.
174 * Applies to all PIIX4 models.
175 */
176
177 /*
178 * BM-IDE
179 * ------
180 * Find the PIIX4 IDE Controller and get the Bus Master IDE
181 * Status register address. We'll use this later to read
182 * each IDE controller's DMA status to make sure we catch all
183 * DMA activity.
184 */
185 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
4be44fcd
LB
186 PCI_DEVICE_ID_INTEL_82371AB,
187 PCI_ANY_ID, PCI_ANY_ID, NULL);
1da177e4
LT
188 if (dev) {
189 errata.piix4.bmisx = pci_resource_start(dev, 4);
190 pci_dev_put(dev);
191 }
192
193 /*
194 * Type-F DMA
195 * ----------
196 * Find the PIIX4 ISA Controller and read the Motherboard
197 * DMA controller's status to see if Type-F (Fast) DMA mode
198 * is enabled (bit 7) on either channel. Note that we'll
199 * disable C3 support if this is enabled, as some legacy
200 * devices won't operate well if fast DMA is disabled.
201 */
202 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
4be44fcd
LB
203 PCI_DEVICE_ID_INTEL_82371AB_0,
204 PCI_ANY_ID, PCI_ANY_ID, NULL);
1da177e4
LT
205 if (dev) {
206 pci_read_config_byte(dev, 0x76, &value1);
207 pci_read_config_byte(dev, 0x77, &value2);
208 if ((value1 & 0x80) || (value2 & 0x80))
209 errata.piix4.fdma = 1;
210 pci_dev_put(dev);
211 }
212
213 break;
214 }
215
216 if (errata.piix4.bmisx)
217 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
4be44fcd 218 "Bus master activity detection (BM-IDE) erratum enabled\n"));
1da177e4
LT
219 if (errata.piix4.fdma)
220 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
4be44fcd 221 "Type-F DMA livelock erratum (C3 disabled)\n"));
1da177e4 222
d550d98d 223 return 0;
1da177e4
LT
224}
225
8713cbef 226static int acpi_processor_errata(struct acpi_processor *pr)
1da177e4 227{
4be44fcd
LB
228 int result = 0;
229 struct pci_dev *dev = NULL;
1da177e4 230
1da177e4
LT
231
232 if (!pr)
d550d98d 233 return -EINVAL;
1da177e4
LT
234
235 /*
236 * PIIX4
237 */
238 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
4be44fcd
LB
239 PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
240 PCI_ANY_ID, NULL);
1da177e4
LT
241 if (dev) {
242 result = acpi_processor_errata_piix4(dev);
243 pci_dev_put(dev);
244 }
245
d550d98d 246 return result;
1da177e4
LT
247}
248
d5c6887c 249#ifdef CONFIG_ACPI_PROCFS
4be44fcd 250static struct proc_dir_entry *acpi_processor_dir = NULL;
1da177e4 251
bf8b4542 252static int __cpuinit acpi_processor_add_fs(struct acpi_device *device)
1da177e4 253{
4be44fcd 254 struct proc_dir_entry *entry = NULL;
1da177e4 255
1da177e4
LT
256
257 if (!acpi_device_dir(device)) {
258 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
4be44fcd 259 acpi_processor_dir);
1da177e4 260 if (!acpi_device_dir(device))
d550d98d 261 return -ENODEV;
1da177e4 262 }
1da177e4 263
1da177e4 264 /* 'throttling' [R/W] */
cf7acfab
DL
265 entry = proc_create_data(ACPI_PROCESSOR_FILE_THROTTLING,
266 S_IFREG | S_IRUGO | S_IWUSR,
267 acpi_device_dir(device),
268 &acpi_processor_throttling_fops,
269 acpi_driver_data(device));
1da177e4 270 if (!entry)
d550d98d 271 return -EIO;
d550d98d 272 return 0;
1da177e4 273}
4be44fcd 274static int acpi_processor_remove_fs(struct acpi_device *device)
1da177e4 275{
1da177e4
LT
276
277 if (acpi_device_dir(device)) {
1da177e4 278 remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
4be44fcd 279 acpi_device_dir(device));
1da177e4
LT
280 remove_proc_entry(acpi_device_bid(device), acpi_processor_dir);
281 acpi_device_dir(device) = NULL;
282 }
283
d550d98d 284 return 0;
1da177e4 285}
d5c6887c
ZR
286#else
287static inline int acpi_processor_add_fs(struct acpi_device *device)
288{
289 return 0;
290}
291static inline int acpi_processor_remove_fs(struct acpi_device *device)
292{
293 return 0;
294}
295#endif
1da177e4
LT
296/* --------------------------------------------------------------------------
297 Driver Interface
298 -------------------------------------------------------------------------- */
299
b26e9286 300static int acpi_processor_get_info(struct acpi_device *device)
1da177e4 301{
4be44fcd
LB
302 acpi_status status = 0;
303 union acpi_object object = { 0 };
304 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
b26e9286
MS
305 struct acpi_processor *pr;
306 int cpu_index, device_declaration = 0;
4be44fcd 307 static int cpu0_initialized;
1da177e4 308
b26e9286 309 pr = acpi_driver_data(device);
1da177e4 310 if (!pr)
d550d98d 311 return -EINVAL;
1da177e4
LT
312
313 if (num_online_cpus() > 1)
314 errata.smp = TRUE;
315
316 acpi_processor_errata(pr);
317
318 /*
319 * Check to see if we have bus mastering arbitration control. This
320 * is required for proper C3 usage (to maintain cache coherency).
321 */
cee324b1 322 if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
1da177e4
LT
323 pr->flags.bm_control = 1;
324 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
4be44fcd
LB
325 "Bus mastering arbitration control present\n"));
326 } else
1da177e4 327 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
4be44fcd 328 "No bus mastering arbitration control\n"));
1da177e4 329
6cc73b48
BH
330 if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) {
331 /* Declared with "Processor" statement; match ProcessorID */
332 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
333 if (ACPI_FAILURE(status)) {
334 printk(KERN_ERR PREFIX "Evaluating processor object\n");
335 return -ENODEV;
336 }
337
338 /*
339 * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
340 * >>> 'acpi_get_processor_id(acpi_id, &id)' in
341 * arch/xxx/acpi.c
342 */
343 pr->acpi_id = object.processor.proc_id;
344 } else {
b26e9286
MS
345 /*
346 * Declared with "Device" statement; match _UID.
347 * Note that we don't handle string _UIDs yet.
348 */
27663c58 349 unsigned long long value;
11bf04c4
AS
350 status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
351 NULL, &value);
352 if (ACPI_FAILURE(status)) {
b26e9286
MS
353 printk(KERN_ERR PREFIX
354 "Evaluating processor _UID [%#x]\n", status);
11bf04c4
AS
355 return -ENODEV;
356 }
b26e9286 357 device_declaration = 1;
11bf04c4 358 pr->acpi_id = value;
11bf04c4 359 }
2e9d5e4e 360 cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id);
1da177e4 361
4be44fcd 362 /* Handle UP system running SMP kernel, with no LAPIC in MADT */
df42baa0 363 if (!cpu0_initialized && (cpu_index == -1) &&
4be44fcd
LB
364 (num_online_cpus() == 1)) {
365 cpu_index = 0;
366 }
367
368 cpu0_initialized = 1;
369
370 pr->id = cpu_index;
371
372 /*
373 * Extra Processor objects may be enumerated on MP systems with
374 * less than the max # of CPUs. They should be ignored _iff
375 * they are physically not present.
376 */
f18c5a08 377 if (pr->id == -1) {
4be44fcd
LB
378 if (ACPI_FAILURE
379 (acpi_processor_hotadd_init(pr->handle, &pr->id))) {
d550d98d 380 return -ENODEV;
4be44fcd
LB
381 }
382 }
7a04b849
ZY
383 /*
384 * On some boxes several processors use the same processor bus id.
385 * But they are located in different scope. For example:
386 * \_SB.SCK0.CPU0
387 * \_SB.SCK1.CPU0
388 * Rename the processor device bus id. And the new bus id will be
389 * generated as the following format:
390 * CPU+CPU ID.
391 */
392 sprintf(acpi_device_bid(device), "CPU%X", pr->id);
1da177e4 393 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
4be44fcd 394 pr->acpi_id));
1da177e4
LT
395
396 if (!object.processor.pblk_address)
397 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
398 else if (object.processor.pblk_length != 6)
6468463a
LB
399 printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n",
400 object.processor.pblk_length);
1da177e4
LT
401 else {
402 pr->throttling.address = object.processor.pblk_address;
cee324b1
AS
403 pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
404 pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
1da177e4
LT
405
406 pr->pblk = object.processor.pblk_address;
407
408 /*
409 * We don't care about error returns - we just try to mark
410 * these reserved so that nobody else is confused into thinking
411 * that this region might be unused..
412 *
413 * (In particular, allocating the IO range for Cardbus)
414 */
415 request_region(pr->throttling.address, 6, "ACPI CPU throttle");
416 }
417
fe086a7b
AC
418 /*
419 * If ACPI describes a slot number for this CPU, we can use it
420 * ensure we get the right value in the "physical id" field
421 * of /proc/cpuinfo
422 */
423 status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer);
424 if (ACPI_SUCCESS(status))
425 arch_fix_phys_package_id(pr->id, object.integer.value);
426
d550d98d 427 return 0;
1da177e4
LT
428}
429
706546d0 430static DEFINE_PER_CPU(void *, processor_device_array);
cd8e2b48 431
7ec0a729 432static void acpi_processor_notify(struct acpi_device *device, u32 event)
1da177e4 433{
7ec0a729 434 struct acpi_processor *pr = acpi_driver_data(device);
e790cc8b 435 int saved;
1da177e4
LT
436
437 if (!pr)
d550d98d 438 return;
1da177e4 439
1da177e4
LT
440 switch (event) {
441 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
e790cc8b 442 saved = pr->performance_platform_limit;
d81c45e1 443 acpi_processor_ppc_has_changed(pr, 1);
e790cc8b
AS
444 if (saved == pr->performance_platform_limit)
445 break;
14e04fb3 446 acpi_bus_generate_proc_event(device, event,
4be44fcd 447 pr->performance_platform_limit);
962ce8ca 448 acpi_bus_generate_netlink_event(device->pnp.device_class,
0794469d 449 dev_name(&device->dev), event,
962ce8ca 450 pr->performance_platform_limit);
1da177e4
LT
451 break;
452 case ACPI_PROCESSOR_NOTIFY_POWER:
453 acpi_processor_cst_has_changed(pr);
14e04fb3 454 acpi_bus_generate_proc_event(device, event, 0);
962ce8ca 455 acpi_bus_generate_netlink_event(device->pnp.device_class,
0794469d 456 dev_name(&device->dev), event, 0);
1da177e4 457 break;
01854e69
LY
458 case ACPI_PROCESSOR_NOTIFY_THROTTLING:
459 acpi_processor_tstate_has_changed(pr);
14e04fb3 460 acpi_bus_generate_proc_event(device, event, 0);
962ce8ca 461 acpi_bus_generate_netlink_event(device->pnp.device_class,
0794469d 462 dev_name(&device->dev), event, 0);
1da177e4
LT
463 default:
464 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
4be44fcd 465 "Unsupported event [0x%x]\n", event));
1da177e4
LT
466 break;
467 }
468
d550d98d 469 return;
1da177e4
LT
470}
471
729c6ba3
VP
472static int acpi_cpu_soft_notify(struct notifier_block *nfb,
473 unsigned long action, void *hcpu)
474{
475 unsigned int cpu = (unsigned long)hcpu;
706546d0 476 struct acpi_processor *pr = per_cpu(processors, cpu);
729c6ba3
VP
477
478 if (action == CPU_ONLINE && pr) {
d81c45e1 479 acpi_processor_ppc_has_changed(pr, 0);
729c6ba3
VP
480 acpi_processor_cst_has_changed(pr);
481 acpi_processor_tstate_has_changed(pr);
482 }
483 return NOTIFY_OK;
484}
485
486static struct notifier_block acpi_cpu_notifier =
487{
488 .notifier_call = acpi_cpu_soft_notify,
489};
490
941b10fa 491static int __cpuinit acpi_processor_add(struct acpi_device *device)
1da177e4 492{
4be44fcd 493 struct acpi_processor *pr = NULL;
970b0492
BH
494 int result = 0;
495 struct sys_device *sysdev;
1da177e4 496
36bcbec7 497 pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
1da177e4 498 if (!pr)
d550d98d 499 return -ENOMEM;
1da177e4 500
eaa95840 501 if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) {
2fdf66b4
RR
502 kfree(pr);
503 return -ENOMEM;
504 }
505
1da177e4
LT
506 pr->handle = device->handle;
507 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
508 strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
db89b4f0 509 device->driver_data = pr;
1da177e4 510
b26e9286 511 result = acpi_processor_get_info(device);
1da177e4
LT
512 if (result) {
513 /* Processor is physically not present */
d550d98d 514 return 0;
1da177e4
LT
515 }
516
75cbfb97
TR
517#ifdef CONFIG_SMP
518 if (pr->id >= setup_max_cpus && pr->id != 0)
519 return 0;
520#endif
521
fbb43ab0 522 BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
1da177e4 523
cd8e2b48
VP
524 /*
525 * Buggy BIOS check
526 * ACPI id of processors can be reported wrongly by the BIOS.
527 * Don't trust it blindly
528 */
706546d0
MT
529 if (per_cpu(processor_device_array, pr->id) != NULL &&
530 per_cpu(processor_device_array, pr->id) != device) {
4fdb2a05 531 printk(KERN_WARNING "BIOS reported wrong ACPI id "
0eacee58 532 "for the processor\n");
970b0492
BH
533 result = -ENODEV;
534 goto err_free_cpumask;
cd8e2b48 535 }
706546d0 536 per_cpu(processor_device_array, pr->id) = device;
cd8e2b48 537
706546d0 538 per_cpu(processors, pr->id) = pr;
1da177e4
LT
539
540 result = acpi_processor_add_fs(device);
541 if (result)
970b0492 542 goto err_free_cpumask;
1da177e4 543
9f1eb99c 544 sysdev = get_cpu_sysdev(pr->id);
d4e05261
BH
545 if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) {
546 result = -EFAULT;
547 goto err_remove_fs;
548 }
9f1eb99c 549
0ac3c571 550#ifdef CONFIG_CPU_FREQ
d81c45e1 551 acpi_processor_ppc_has_changed(pr, 0);
0ac3c571
ZY
552#endif
553 acpi_processor_get_throttling_info(pr);
554 acpi_processor_get_limit_info(pr);
555
05131ecc 556
541adf7c
LB
557 if (cpuidle_get_driver() == &acpi_idle_driver)
558 acpi_processor_power_init(pr, device);
1da177e4 559
d9460fd2
ZR
560 pr->cdev = thermal_cooling_device_register("Processor", device,
561 &processor_cooling_ops);
d76628c6
TS
562 if (IS_ERR(pr->cdev)) {
563 result = PTR_ERR(pr->cdev);
d4e05261 564 goto err_power_exit;
d76628c6 565 }
9030062f 566
13c41157 567 dev_dbg(&device->dev, "registered as cooling_device%d\n",
fc3a8828 568 pr->cdev->id);
9030062f
JL
569
570 result = sysfs_create_link(&device->dev.kobj,
571 &pr->cdev->device.kobj,
572 "thermal_cooling");
d4e05261 573 if (result) {
9030062f 574 printk(KERN_ERR PREFIX "Create sysfs link\n");
d4e05261
BH
575 goto err_thermal_unregister;
576 }
9030062f
JL
577 result = sysfs_create_link(&pr->cdev->device.kobj,
578 &device->dev.kobj,
579 "device");
d4e05261 580 if (result) {
9030062f 581 printk(KERN_ERR PREFIX "Create sysfs link\n");
d4e05261
BH
582 goto err_remove_sysfs;
583 }
d9460fd2 584
d550d98d 585 return 0;
d4e05261
BH
586
587err_remove_sysfs:
588 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
589err_thermal_unregister:
590 thermal_cooling_device_unregister(pr->cdev);
591err_power_exit:
592 acpi_processor_power_exit(pr, device);
593err_remove_fs:
594 acpi_processor_remove_fs(device);
970b0492
BH
595err_free_cpumask:
596 free_cpumask_var(pr->throttling.shared_cpu_map);
1da177e4 597
d550d98d 598 return result;
1da177e4
LT
599}
600
4be44fcd 601static int acpi_processor_remove(struct acpi_device *device, int type)
1da177e4 602{
4be44fcd 603 struct acpi_processor *pr = NULL;
1da177e4 604
1da177e4
LT
605
606 if (!device || !acpi_driver_data(device))
d550d98d 607 return -EINVAL;
1da177e4 608
50dd0969 609 pr = acpi_driver_data(device);
1da177e4 610
2fdf66b4
RR
611 if (pr->id >= nr_cpu_ids)
612 goto free;
1da177e4
LT
613
614 if (type == ACPI_BUS_REMOVAL_EJECT) {
615 if (acpi_processor_handle_eject(pr))
d550d98d 616 return -EINVAL;
1da177e4
LT
617 }
618
619 acpi_processor_power_exit(pr, device);
620
9f1eb99c
ZR
621 sysfs_remove_link(&device->dev.kobj, "sysdev");
622
1da177e4
LT
623 acpi_processor_remove_fs(device);
624
f28bb45e
ZY
625 if (pr->cdev) {
626 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
627 sysfs_remove_link(&pr->cdev->device.kobj, "device");
628 thermal_cooling_device_unregister(pr->cdev);
629 pr->cdev = NULL;
630 }
d9460fd2 631
706546d0
MT
632 per_cpu(processors, pr->id) = NULL;
633 per_cpu(processor_device_array, pr->id) = NULL;
2fdf66b4
RR
634
635free:
636 free_cpumask_var(pr->throttling.shared_cpu_map);
1da177e4
LT
637 kfree(pr);
638
d550d98d 639 return 0;
1da177e4
LT
640}
641
642#ifdef CONFIG_ACPI_HOTPLUG_CPU
643/****************************************************************************
644 * Acpi processor hotplug support *
645 ****************************************************************************/
646
4be44fcd 647static int is_processor_present(acpi_handle handle)
1da177e4 648{
4be44fcd 649 acpi_status status;
27663c58 650 unsigned long long sta = 0;
1da177e4 651
1da177e4
LT
652
653 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
cfaf3747
ZR
654
655 if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
656 return 1;
657
d0ce46f5
ZR
658 /*
659 * _STA is mandatory for a processor that supports hot plug
660 */
661 if (status == AE_NOT_FOUND)
662 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
663 "Processor does not support hot plug\n"));
664 else
665 ACPI_EXCEPTION((AE_INFO, status,
666 "Processor Device is not present"));
cfaf3747 667 return 0;
1da177e4
LT
668}
669
1da177e4 670static
4be44fcd 671int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
1da177e4 672{
4be44fcd
LB
673 acpi_handle phandle;
674 struct acpi_device *pdev;
1da177e4 675
1da177e4
LT
676
677 if (acpi_get_parent(handle, &phandle)) {
d550d98d 678 return -ENODEV;
1da177e4
LT
679 }
680
681 if (acpi_bus_get_device(phandle, &pdev)) {
d550d98d 682 return -ENODEV;
1da177e4
LT
683 }
684
685 if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
d550d98d 686 return -ENODEV;
1da177e4
LT
687 }
688
d550d98d 689 return 0;
1da177e4
LT
690}
691
b95e9e8d
SR
692static void __ref acpi_processor_hotplug_notify(acpi_handle handle,
693 u32 event, void *data)
1da177e4 694{
4be44fcd
LB
695 struct acpi_processor *pr;
696 struct acpi_device *device = NULL;
1da177e4
LT
697 int result;
698
1da177e4
LT
699
700 switch (event) {
701 case ACPI_NOTIFY_BUS_CHECK:
702 case ACPI_NOTIFY_DEVICE_CHECK:
d6f882e1
GC
703 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
704 "Processor driver received %s event\n",
4be44fcd 705 (event == ACPI_NOTIFY_BUS_CHECK) ?
d6f882e1 706 "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
1da177e4
LT
707
708 if (!is_processor_present(handle))
709 break;
710
711 if (acpi_bus_get_device(handle, &device)) {
712 result = acpi_processor_device_add(handle, &device);
713 if (result)
6468463a
LB
714 printk(KERN_ERR PREFIX
715 "Unable to add the device\n");
1da177e4
LT
716 break;
717 }
4be44fcd 718 break;
1da177e4 719 case ACPI_NOTIFY_EJECT_REQUEST:
4be44fcd
LB
720 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
721 "received ACPI_NOTIFY_EJECT_REQUEST\n"));
1da177e4
LT
722
723 if (acpi_bus_get_device(handle, &device)) {
6468463a
LB
724 printk(KERN_ERR PREFIX
725 "Device don't exist, dropping EJECT\n");
1da177e4
LT
726 break;
727 }
728 pr = acpi_driver_data(device);
729 if (!pr) {
6468463a
LB
730 printk(KERN_ERR PREFIX
731 "Driver data is NULL, dropping EJECT\n");
d550d98d 732 return;
1da177e4 733 }
1da177e4
LT
734 break;
735 default:
736 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
4be44fcd 737 "Unsupported event [0x%x]\n", event));
1da177e4
LT
738 break;
739 }
740
d550d98d 741 return;
1da177e4
LT
742}
743
744static acpi_status
745processor_walk_namespace_cb(acpi_handle handle,
4be44fcd 746 u32 lvl, void *context, void **rv)
1da177e4 747{
4be44fcd 748 acpi_status status;
1da177e4 749 int *action = context;
4be44fcd 750 acpi_object_type type = 0;
1da177e4
LT
751
752 status = acpi_get_type(handle, &type);
753 if (ACPI_FAILURE(status))
4be44fcd 754 return (AE_OK);
1da177e4
LT
755
756 if (type != ACPI_TYPE_PROCESSOR)
4be44fcd 757 return (AE_OK);
1da177e4 758
4be44fcd 759 switch (*action) {
1da177e4
LT
760 case INSTALL_NOTIFY_HANDLER:
761 acpi_install_notify_handler(handle,
4be44fcd
LB
762 ACPI_SYSTEM_NOTIFY,
763 acpi_processor_hotplug_notify,
764 NULL);
1da177e4
LT
765 break;
766 case UNINSTALL_NOTIFY_HANDLER:
767 acpi_remove_notify_handler(handle,
4be44fcd
LB
768 ACPI_SYSTEM_NOTIFY,
769 acpi_processor_hotplug_notify);
1da177e4
LT
770 break;
771 default:
772 break;
773 }
774
4be44fcd 775 return (AE_OK);
1da177e4
LT
776}
777
4be44fcd 778static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
1da177e4 779{
1da177e4
LT
780
781 if (!is_processor_present(handle)) {
d550d98d 782 return AE_ERROR;
1da177e4
LT
783 }
784
785 if (acpi_map_lsapic(handle, p_cpu))
d550d98d 786 return AE_ERROR;
1da177e4
LT
787
788 if (arch_register_cpu(*p_cpu)) {
789 acpi_unmap_lsapic(*p_cpu);
d550d98d 790 return AE_ERROR;
1da177e4
LT
791 }
792
d550d98d 793 return AE_OK;
1da177e4
LT
794}
795
4be44fcd 796static int acpi_processor_handle_eject(struct acpi_processor *pr)
1da177e4 797{
b62b8ef9
ZR
798 if (cpu_online(pr->id))
799 cpu_down(pr->id);
800
1da177e4
LT
801 arch_unregister_cpu(pr->id);
802 acpi_unmap_lsapic(pr->id);
4be44fcd 803 return (0);
1da177e4
LT
804}
805#else
4be44fcd 806static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
1da177e4
LT
807{
808 return AE_ERROR;
809}
4be44fcd 810static int acpi_processor_handle_eject(struct acpi_processor *pr)
1da177e4 811{
4be44fcd 812 return (-EINVAL);
1da177e4
LT
813}
814#endif
815
1da177e4
LT
816static
817void acpi_processor_install_hotplug_notify(void)
818{
819#ifdef CONFIG_ACPI_HOTPLUG_CPU
820 int action = INSTALL_NOTIFY_HANDLER;
821 acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
4be44fcd
LB
822 ACPI_ROOT_OBJECT,
823 ACPI_UINT32_MAX,
2263576c 824 processor_walk_namespace_cb, NULL, &action, NULL);
1da177e4 825#endif
729c6ba3 826 register_hotcpu_notifier(&acpi_cpu_notifier);
1da177e4
LT
827}
828
1da177e4
LT
829static
830void acpi_processor_uninstall_hotplug_notify(void)
831{
832#ifdef CONFIG_ACPI_HOTPLUG_CPU
833 int action = UNINSTALL_NOTIFY_HANDLER;
834 acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
4be44fcd
LB
835 ACPI_ROOT_OBJECT,
836 ACPI_UINT32_MAX,
2263576c 837 processor_walk_namespace_cb, NULL, &action, NULL);
1da177e4 838#endif
729c6ba3 839 unregister_hotcpu_notifier(&acpi_cpu_notifier);
1da177e4
LT
840}
841
842/*
843 * We keep the driver loaded even when ACPI is not running.
844 * This is needed for the powernow-k8 driver, that works even without
845 * ACPI, but needs symbols from this driver
846 */
847
4be44fcd 848static int __init acpi_processor_init(void)
1da177e4 849{
4be44fcd 850 int result = 0;
1da177e4 851
ce8442b5
YL
852 if (acpi_disabled)
853 return 0;
854
1da177e4
LT
855 memset(&errata, 0, sizeof(errata));
856
d5c6887c 857#ifdef CONFIG_ACPI_PROCFS
1da177e4
LT
858 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
859 if (!acpi_processor_dir)
83822fc9 860 return -ENOMEM;
d5c6887c 861#endif
541adf7c 862
26717172 863 if (!cpuidle_register_driver(&acpi_idle_driver)) {
541adf7c
LB
864 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
865 acpi_idle_driver.name);
26717172 866 } else {
e9a64ed4 867 printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s\n",
26717172
LB
868 cpuidle_get_driver()->name);
869 }
4f86d3a8 870
1da177e4 871 result = acpi_bus_register_driver(&acpi_processor_driver);
4f86d3a8
LB
872 if (result < 0)
873 goto out_cpuidle;
1da177e4
LT
874
875 acpi_processor_install_hotplug_notify();
876
877 acpi_thermal_cpufreq_init();
878
879 acpi_processor_ppc_init();
880
1180509f
ZY
881 acpi_processor_throttling_init();
882
d550d98d 883 return 0;
4f86d3a8
LB
884
885out_cpuidle:
886 cpuidle_unregister_driver(&acpi_idle_driver);
887
d5c6887c 888#ifdef CONFIG_ACPI_PROCFS
4f86d3a8 889 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
d5c6887c 890#endif
4f86d3a8
LB
891
892 return result;
1da177e4
LT
893}
894
4be44fcd 895static void __exit acpi_processor_exit(void)
1da177e4 896{
ce8442b5
YL
897 if (acpi_disabled)
898 return;
899
1da177e4
LT
900 acpi_processor_ppc_exit();
901
902 acpi_thermal_cpufreq_exit();
903
904 acpi_processor_uninstall_hotplug_notify();
905
906 acpi_bus_unregister_driver(&acpi_processor_driver);
907
4f86d3a8
LB
908 cpuidle_unregister_driver(&acpi_idle_driver);
909
d5c6887c 910#ifdef CONFIG_ACPI_PROCFS
1da177e4 911 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
d5c6887c 912#endif
1da177e4 913
d550d98d 914 return;
1da177e4
LT
915}
916
1da177e4
LT
917module_init(acpi_processor_init);
918module_exit(acpi_processor_exit);
919
1da177e4 920MODULE_ALIAS("processor");