ia64/linux-2.6.18-xen.hg

view drivers/acpi/processor_core.c @ 897:329ea0ccb344

balloon: try harder to balloon up under memory pressure.

Currently if the balloon driver is unable to increase the guest's
reservation it assumes the failure was due to reaching its full
allocation, gives up on the ballooning operation and records the limit
it reached as the "hard limit". The driver will not try again until
the target is set again (even to the same value).

However it is possible that ballooning has in fact failed due to
memory pressure in the host and therefore it is desirable to keep
attempting to reach the target in case memory becomes available. The
most likely scenario is that some guests are ballooning down while
others are ballooning up and therefore there is temporary memory
pressure while things stabilise. You would not expect a well behaved
toolstack to ask a domain to balloon to more than its allocation nor
would you expect it to deliberately over-commit memory by setting
balloon targets which exceed the total host memory.

This patch drops the concept of a hard limit and causes the balloon
driver to retry increasing the reservation on a timer in the same
manner as when decreasing the reservation.

Also if we partially succeed in increasing the reservation
(i.e. receive less pages than we asked for) then we may as well keep
those pages rather than returning them to Xen.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 05 14:01:20 2009 +0100 (2009-06-05)
parents c86e5fde3fb1
children
line source
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 */
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>
43 #include <linux/proc_fs.h>
44 #include <linux/seq_file.h>
45 #include <linux/dmi.h>
46 #include <linux/moduleparam.h>
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>
57 #include <acpi/acpi_bus.h>
58 #include <acpi/acpi_drivers.h>
59 #include <acpi/processor.h>
61 #define ACPI_PROCESSOR_COMPONENT 0x01000000
62 #define ACPI_PROCESSOR_CLASS "processor"
63 #define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
64 #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
70 #define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82
72 #define ACPI_PROCESSOR_LIMIT_USER 0
73 #define ACPI_PROCESSOR_LIMIT_THERMAL 1
75 #define ACPI_STA_PRESENT 0x00000001
77 #define _COMPONENT ACPI_PROCESSOR_COMPONENT
78 ACPI_MODULE_NAME("acpi_processor")
80 MODULE_AUTHOR("Paul Diefenbaugh");
81 MODULE_DESCRIPTION(ACPI_PROCESSOR_DRIVER_NAME);
82 MODULE_LICENSE("GPL");
84 static int acpi_processor_add(struct acpi_device *device);
85 static int acpi_processor_start(struct acpi_device *device);
86 static int acpi_processor_remove(struct acpi_device *device, int type);
87 static int acpi_processor_info_open_fs(struct inode *inode, struct file *file);
88 static void acpi_processor_notify(acpi_handle handle, u32 event, void *data);
89 static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
90 static int acpi_processor_handle_eject(struct acpi_processor *pr);
92 static struct acpi_driver acpi_processor_driver = {
93 .name = ACPI_PROCESSOR_DRIVER_NAME,
94 .class = ACPI_PROCESSOR_CLASS,
95 .ids = ACPI_PROCESSOR_HID,
96 .ops = {
97 .add = acpi_processor_add,
98 .remove = acpi_processor_remove,
99 .start = acpi_processor_start,
100 },
101 };
103 #define INSTALL_NOTIFY_HANDLER 1
104 #define UNINSTALL_NOTIFY_HANDLER 2
106 static const struct file_operations acpi_processor_info_fops = {
107 .open = acpi_processor_info_open_fs,
108 .read = seq_read,
109 .llseek = seq_lseek,
110 .release = single_release,
111 };
113 struct acpi_processor *processors[NR_CPUS];
114 struct acpi_processor_errata errata __read_mostly;
116 /* --------------------------------------------------------------------------
117 Errata Handling
118 -------------------------------------------------------------------------- */
120 static int acpi_processor_errata_piix4(struct pci_dev *dev)
121 {
122 u8 rev = 0;
123 u8 value1 = 0;
124 u8 value2 = 0;
127 if (!dev)
128 return -EINVAL;
130 /*
131 * Note that 'dev' references the PIIX4 ACPI Controller.
132 */
134 pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
136 switch (rev) {
137 case 0:
138 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
139 break;
140 case 1:
141 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n"));
142 break;
143 case 2:
144 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n"));
145 break;
146 case 3:
147 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n"));
148 break;
149 default:
150 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n"));
151 break;
152 }
154 switch (rev) {
156 case 0: /* PIIX4 A-step */
157 case 1: /* PIIX4 B-step */
158 /*
159 * See specification changes #13 ("Manual Throttle Duty Cycle")
160 * and #14 ("Enabling and Disabling Manual Throttle"), plus
161 * erratum #5 ("STPCLK# Deassertion Time") from the January
162 * 2002 PIIX4 specification update. Applies to only older
163 * PIIX4 models.
164 */
165 errata.piix4.throttle = 1;
167 case 2: /* PIIX4E */
168 case 3: /* PIIX4M */
169 /*
170 * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
171 * Livelock") from the January 2002 PIIX4 specification update.
172 * Applies to all PIIX4 models.
173 */
175 /*
176 * BM-IDE
177 * ------
178 * Find the PIIX4 IDE Controller and get the Bus Master IDE
179 * Status register address. We'll use this later to read
180 * each IDE controller's DMA status to make sure we catch all
181 * DMA activity.
182 */
183 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
184 PCI_DEVICE_ID_INTEL_82371AB,
185 PCI_ANY_ID, PCI_ANY_ID, NULL);
186 if (dev) {
187 errata.piix4.bmisx = pci_resource_start(dev, 4);
188 pci_dev_put(dev);
189 }
191 /*
192 * Type-F DMA
193 * ----------
194 * Find the PIIX4 ISA Controller and read the Motherboard
195 * DMA controller's status to see if Type-F (Fast) DMA mode
196 * is enabled (bit 7) on either channel. Note that we'll
197 * disable C3 support if this is enabled, as some legacy
198 * devices won't operate well if fast DMA is disabled.
199 */
200 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
201 PCI_DEVICE_ID_INTEL_82371AB_0,
202 PCI_ANY_ID, PCI_ANY_ID, NULL);
203 if (dev) {
204 pci_read_config_byte(dev, 0x76, &value1);
205 pci_read_config_byte(dev, 0x77, &value2);
206 if ((value1 & 0x80) || (value2 & 0x80))
207 errata.piix4.fdma = 1;
208 pci_dev_put(dev);
209 }
211 break;
212 }
214 if (errata.piix4.bmisx)
215 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
216 "Bus master activity detection (BM-IDE) erratum enabled\n"));
217 if (errata.piix4.fdma)
218 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
219 "Type-F DMA livelock erratum (C3 disabled)\n"));
221 return 0;
222 }
224 static int acpi_processor_errata(struct acpi_processor *pr)
225 {
226 int result = 0;
227 struct pci_dev *dev = NULL;
230 if (!pr)
231 return -EINVAL;
233 /*
234 * PIIX4
235 */
236 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
237 PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
238 PCI_ANY_ID, NULL);
239 if (dev) {
240 result = acpi_processor_errata_piix4(dev);
241 pci_dev_put(dev);
242 }
244 return result;
245 }
247 /* --------------------------------------------------------------------------
248 Common ACPI processor functions
249 -------------------------------------------------------------------------- */
251 /*
252 * _PDC is required for a BIOS-OS handshake for most of the newer
253 * ACPI processor features.
254 */
255 static int acpi_processor_set_pdc(struct acpi_processor *pr)
256 {
257 struct acpi_object_list *pdc_in = pr->pdc;
258 acpi_status status = AE_OK;
261 if (!pdc_in)
262 return status;
264 status = acpi_evaluate_object(pr->handle, "_PDC", pdc_in, NULL);
266 if (ACPI_FAILURE(status))
267 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
268 "Could not evaluate _PDC, using legacy perf. control...\n"));
270 return status;
271 }
273 /* --------------------------------------------------------------------------
274 FS Interface (/proc)
275 -------------------------------------------------------------------------- */
277 static struct proc_dir_entry *acpi_processor_dir = NULL;
279 static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset)
280 {
281 struct acpi_processor *pr = (struct acpi_processor *)seq->private;
284 if (!pr)
285 goto end;
287 seq_printf(seq, "processor id: %d\n"
288 "acpi id: %d\n"
289 "bus mastering control: %s\n"
290 "power management: %s\n"
291 "throttling control: %s\n"
292 "limit interface: %s\n",
293 pr->id,
294 pr->acpi_id,
295 pr->flags.bm_control ? "yes" : "no",
296 pr->flags.power ? "yes" : "no",
297 pr->flags.throttling ? "yes" : "no",
298 pr->flags.limit ? "yes" : "no");
300 end:
301 return 0;
302 }
304 static int acpi_processor_info_open_fs(struct inode *inode, struct file *file)
305 {
306 return single_open(file, acpi_processor_info_seq_show,
307 PDE(inode)->data);
308 }
310 static int acpi_processor_add_fs(struct acpi_device *device)
311 {
312 struct proc_dir_entry *entry = NULL;
315 if (!acpi_device_dir(device)) {
316 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
317 acpi_processor_dir);
318 if (!acpi_device_dir(device))
319 return -ENODEV;
320 }
321 acpi_device_dir(device)->owner = THIS_MODULE;
323 /* 'info' [R] */
324 entry = create_proc_entry(ACPI_PROCESSOR_FILE_INFO,
325 S_IRUGO, acpi_device_dir(device));
326 if (!entry)
327 return -EIO;
328 else {
329 entry->proc_fops = &acpi_processor_info_fops;
330 entry->data = acpi_driver_data(device);
331 entry->owner = THIS_MODULE;
332 }
334 /* 'throttling' [R/W] */
335 entry = create_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
336 S_IFREG | S_IRUGO | S_IWUSR,
337 acpi_device_dir(device));
338 if (!entry)
339 return -EIO;
340 else {
341 entry->proc_fops = &acpi_processor_throttling_fops;
342 entry->data = acpi_driver_data(device);
343 entry->owner = THIS_MODULE;
344 }
346 /* 'limit' [R/W] */
347 entry = create_proc_entry(ACPI_PROCESSOR_FILE_LIMIT,
348 S_IFREG | S_IRUGO | S_IWUSR,
349 acpi_device_dir(device));
350 if (!entry)
351 return -EIO;
352 else {
353 entry->proc_fops = &acpi_processor_limit_fops;
354 entry->data = acpi_driver_data(device);
355 entry->owner = THIS_MODULE;
356 }
358 return 0;
359 }
361 static int acpi_processor_remove_fs(struct acpi_device *device)
362 {
364 if (acpi_device_dir(device)) {
365 remove_proc_entry(ACPI_PROCESSOR_FILE_INFO,
366 acpi_device_dir(device));
367 remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
368 acpi_device_dir(device));
369 remove_proc_entry(ACPI_PROCESSOR_FILE_LIMIT,
370 acpi_device_dir(device));
371 remove_proc_entry(acpi_device_bid(device), acpi_processor_dir);
372 acpi_device_dir(device) = NULL;
373 }
375 return 0;
376 }
378 /* Use the acpiid in MADT to map cpus in case of SMP */
379 #ifndef CONFIG_SMP
380 #define convert_acpiid_to_cpu(acpi_id) (-1)
381 #else
383 #ifdef CONFIG_IA64
384 #define arch_acpiid_to_apicid ia64_acpiid_to_sapicid
385 #define arch_cpu_to_apicid ia64_cpu_to_sapicid
386 #define ARCH_BAD_APICID (0xffff)
387 #else
388 #define arch_acpiid_to_apicid x86_acpiid_to_apicid
389 #define arch_cpu_to_apicid x86_cpu_to_apicid
390 #define ARCH_BAD_APICID (0xff)
391 #endif
393 static int convert_acpiid_to_cpu(u8 acpi_id)
394 {
395 u16 apic_id;
396 int i;
398 apic_id = arch_acpiid_to_apicid[acpi_id];
399 if (apic_id == ARCH_BAD_APICID)
400 return -1;
402 for (i = 0; i < NR_CPUS; i++) {
403 if (arch_cpu_to_apicid[i] == apic_id)
404 return i;
405 }
406 return -1;
407 }
408 #endif
410 /* --------------------------------------------------------------------------
411 Driver Interface
412 -------------------------------------------------------------------------- */
414 static int acpi_processor_get_info(struct acpi_processor *pr)
415 {
416 acpi_status status = 0;
417 union acpi_object object = { 0 };
418 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
419 int cpu_index;
420 static int cpu0_initialized;
423 if (!pr)
424 return -EINVAL;
426 if (num_online_cpus() > 1)
427 errata.smp = TRUE;
429 acpi_processor_errata(pr);
431 /*
432 * Check to see if we have bus mastering arbitration control. This
433 * is required for proper C3 usage (to maintain cache coherency).
434 */
435 if (acpi_fadt.V1_pm2_cnt_blk && acpi_fadt.pm2_cnt_len) {
436 pr->flags.bm_control = 1;
437 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
438 "Bus mastering arbitration control present\n"));
439 } else
440 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
441 "No bus mastering arbitration control\n"));
443 /*
444 * Evalute the processor object. Note that it is common on SMP to
445 * have the first (boot) processor with a valid PBLK address while
446 * all others have a NULL address.
447 */
448 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
449 if (ACPI_FAILURE(status)) {
450 printk(KERN_ERR PREFIX "Evaluating processor object\n");
451 return -ENODEV;
452 }
454 /*
455 * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
456 * >>> 'acpi_get_processor_id(acpi_id, &id)' in arch/xxx/acpi.c
457 */
458 pr->acpi_id = object.processor.proc_id;
460 cpu_index = convert_acpiid_to_cpu(pr->acpi_id);
462 /* Handle UP system running SMP kernel, with no LAPIC in MADT */
463 if (!cpu0_initialized && (cpu_index == -1) &&
464 (num_online_cpus() == 1)) {
465 cpu_index = 0;
466 }
468 cpu0_initialized = 1;
470 pr->id = cpu_index;
472 /*
473 * Extra Processor objects may be enumerated on MP systems with
474 * less than the max # of CPUs. They should be ignored _iff
475 * they are physically not present.
476 */
477 if (cpu_index == -1) {
478 if (ACPI_FAILURE
479 (acpi_processor_hotadd_init(pr->handle, &pr->id)) &&
480 !processor_cntl_external()) {
481 printk(KERN_ERR PREFIX
482 "Getting cpuindex for acpiid 0x%x\n",
483 pr->acpi_id);
484 return -ENODEV;
485 }
486 }
488 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
489 pr->acpi_id));
491 if (!object.processor.pblk_address)
492 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
493 else if (object.processor.pblk_length != 6)
494 printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n",
495 object.processor.pblk_length);
496 else {
497 pr->throttling.address = object.processor.pblk_address;
498 pr->throttling.duty_offset = acpi_fadt.duty_offset;
499 pr->throttling.duty_width = acpi_fadt.duty_width;
501 pr->pblk = object.processor.pblk_address;
503 /*
504 * We don't care about error returns - we just try to mark
505 * these reserved so that nobody else is confused into thinking
506 * that this region might be unused..
507 *
508 * (In particular, allocating the IO range for Cardbus)
509 */
510 request_region(pr->throttling.address, 6, "ACPI CPU throttle");
511 }
513 return 0;
514 }
516 static void *processor_device_array[NR_ACPI_CPUS];
518 static int acpi_processor_start(struct acpi_device *device)
519 {
520 int result = 0;
521 acpi_status status = AE_OK;
522 struct acpi_processor *pr;
524 processor_extcntl_init();
526 pr = acpi_driver_data(device);
528 result = acpi_processor_get_info(pr);
529 if (result ||
530 ((pr->id == -1) && !processor_cntl_external())) {
531 /* Processor is physically not present */
532 return 0;
533 }
535 BUG_ON(!processor_cntl_external() &&
536 ((pr->id >= NR_CPUS) || (pr->id < 0)));
538 /*
539 * Buggy BIOS check
540 * ACPI id of processors can be reported wrongly by the BIOS.
541 * Don't trust it blindly
542 */
543 #ifdef CONFIG_XEN
544 BUG_ON(pr->acpi_id >= NR_ACPI_CPUS);
545 if (processor_device_array[pr->acpi_id] != NULL &&
546 processor_device_array[pr->acpi_id] != (void *)device) {
547 #else
548 if (processor_device_array[pr->id] != NULL &&
549 processor_device_array[pr->id] != (void *)device) {
550 #endif /* CONFIG_XEN */
551 printk(KERN_WARNING "BIOS reported wrong ACPI id"
552 "for the processor\n");
553 return -ENODEV;
554 }
555 #ifdef CONFIG_XEN
556 processor_device_array[pr->acpi_id] = (void *)device;
557 if (pr->id != -1)
558 processors[pr->id] = pr;
559 #else
560 processor_device_array[pr->id] = (void *)device;
562 processors[pr->id] = pr;
563 #endif /* CONFIG_XEN */
565 result = acpi_processor_add_fs(device);
566 if (result)
567 goto end;
569 status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
570 acpi_processor_notify, pr);
572 /* _PDC call should be done before doing anything else (if reqd.). */
573 arch_acpi_processor_init_pdc(pr);
574 acpi_processor_set_pdc(pr);
576 #if defined(CONFIG_CPU_FREQ) || defined(CONFIG_PROCESSOR_EXTERNAL_CONTROL)
577 acpi_processor_ppc_has_changed(pr);
578 #endif
580 /*
581 * pr->id may equal to -1 while processor_cntl_external enabled.
582 * throttle and thermal module don't support this case.
583 * Tx only works when dom0 vcpu == pcpu num by far, as we give
584 * control to dom0.
585 */
586 if (pr->id != -1) {
587 acpi_processor_get_throttling_info(pr);
588 acpi_processor_get_limit_info(pr);
589 }
591 acpi_processor_power_init(pr, device);
593 result = processor_extcntl_prepare(pr);
594 if (result)
595 goto end;
597 if (pr->flags.throttling) {
598 printk(KERN_INFO PREFIX "%s [%s] (supports",
599 acpi_device_name(device), acpi_device_bid(device));
600 printk(" %d throttling states", pr->throttling.state_count);
601 printk(")\n");
602 }
604 end:
606 return result;
607 }
609 static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
610 {
611 struct acpi_processor *pr = (struct acpi_processor *)data;
612 struct acpi_device *device = NULL;
615 if (!pr)
616 return;
618 if (acpi_bus_get_device(pr->handle, &device))
619 return;
621 switch (event) {
622 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
623 acpi_processor_ppc_has_changed(pr);
624 acpi_bus_generate_event(device, event,
625 pr->performance_platform_limit);
626 break;
627 case ACPI_PROCESSOR_NOTIFY_POWER:
628 acpi_processor_cst_has_changed(pr);
629 acpi_bus_generate_event(device, event, 0);
630 break;
631 case ACPI_PROCESSOR_NOTIFY_THROTTLING:
632 acpi_processor_tstate_has_changed(pr);
633 acpi_bus_generate_event(device, event, 0);
634 break;
635 default:
636 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
637 "Unsupported event [0x%x]\n", event));
638 break;
639 }
641 return;
642 }
644 static int acpi_processor_add(struct acpi_device *device)
645 {
646 struct acpi_processor *pr = NULL;
649 if (!device)
650 return -EINVAL;
652 pr = kmalloc(sizeof(struct acpi_processor), GFP_KERNEL);
653 if (!pr)
654 return -ENOMEM;
655 memset(pr, 0, sizeof(struct acpi_processor));
657 pr->handle = device->handle;
658 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
659 strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
660 acpi_driver_data(device) = pr;
662 return 0;
663 }
665 static int acpi_processor_remove(struct acpi_device *device, int type)
666 {
667 acpi_status status = AE_OK;
668 struct acpi_processor *pr = NULL;
671 if (!device || !acpi_driver_data(device))
672 return -EINVAL;
674 pr = (struct acpi_processor *)acpi_driver_data(device);
676 if (!processor_cntl_external() && pr->id >= NR_CPUS) {
677 kfree(pr);
678 return 0;
679 }
681 if (type == ACPI_BUS_REMOVAL_EJECT) {
682 if (acpi_processor_handle_eject(pr))
683 return -EINVAL;
684 }
686 acpi_processor_power_exit(pr, device);
688 status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
689 acpi_processor_notify);
691 acpi_processor_remove_fs(device);
693 #ifdef CONFIG_XEN
694 if (pr->id != -1)
695 processors[pr->id] = NULL;
696 #else
697 processors[pr->id] = NULL;
698 #endif /* CONFIG_XEN */
701 kfree(pr);
703 return 0;
704 }
706 #ifdef CONFIG_ACPI_HOTPLUG_CPU
707 /****************************************************************************
708 * Acpi processor hotplug support *
709 ****************************************************************************/
711 static int is_processor_present(acpi_handle handle);
713 static int is_processor_present(acpi_handle handle)
714 {
715 acpi_status status;
716 unsigned long sta = 0;
719 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
720 if (ACPI_FAILURE(status) || !(sta & ACPI_STA_PRESENT)) {
721 ACPI_EXCEPTION((AE_INFO, status, "Processor Device is not present"));
722 return 0;
723 }
724 return 1;
725 }
727 static
728 int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
729 {
730 acpi_handle phandle;
731 struct acpi_device *pdev;
732 struct acpi_processor *pr;
735 if (acpi_get_parent(handle, &phandle)) {
736 return -ENODEV;
737 }
739 if (acpi_bus_get_device(phandle, &pdev)) {
740 return -ENODEV;
741 }
743 if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
744 return -ENODEV;
745 }
747 acpi_bus_start(*device);
749 pr = acpi_driver_data(*device);
750 if (!pr)
751 return -ENODEV;
753 if (processor_cntl_external())
754 processor_notify_external(pr,
755 PROCESSOR_HOTPLUG, HOTPLUG_TYPE_ADD);
757 if ((pr->id >= 0) && (pr->id < NR_CPUS)) {
758 kobject_uevent(&(*device)->kobj, KOBJ_ONLINE);
759 }
760 return 0;
761 }
763 static void
764 acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
765 {
766 struct acpi_processor *pr;
767 struct acpi_device *device = NULL;
768 int result;
771 switch (event) {
772 case ACPI_NOTIFY_BUS_CHECK:
773 case ACPI_NOTIFY_DEVICE_CHECK:
774 printk("Processor driver received %s event\n",
775 (event == ACPI_NOTIFY_BUS_CHECK) ?
776 "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK");
778 if (!is_processor_present(handle))
779 break;
781 if (acpi_bus_get_device(handle, &device)) {
782 result = acpi_processor_device_add(handle, &device);
783 if (result)
784 printk(KERN_ERR PREFIX
785 "Unable to add the device\n");
786 break;
787 }
789 pr = acpi_driver_data(device);
790 if (!pr) {
791 printk(KERN_ERR PREFIX "Driver data is NULL\n");
792 break;
793 }
795 if (processor_cntl_external())
796 processor_notify_external(pr,
797 PROCESSOR_HOTPLUG, HOTPLUG_TYPE_ADD);
799 if (pr->id >= 0 && (pr->id < NR_CPUS)) {
800 kobject_uevent(&device->kobj, KOBJ_OFFLINE);
801 break;
802 }
804 result = acpi_processor_start(device);
805 if ((!result) && ((pr->id >= 0) && (pr->id < NR_CPUS))) {
806 kobject_uevent(&device->kobj, KOBJ_ONLINE);
807 } else {
808 printk(KERN_ERR PREFIX "Device [%s] failed to start\n",
809 acpi_device_bid(device));
810 }
811 break;
812 case ACPI_NOTIFY_EJECT_REQUEST:
813 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
814 "received ACPI_NOTIFY_EJECT_REQUEST\n"));
816 if (acpi_bus_get_device(handle, &device)) {
817 printk(KERN_ERR PREFIX
818 "Device don't exist, dropping EJECT\n");
819 break;
820 }
821 pr = acpi_driver_data(device);
822 if (!pr) {
823 printk(KERN_ERR PREFIX
824 "Driver data is NULL, dropping EJECT\n");
825 return;
826 }
828 if ((pr->id < NR_CPUS) && (cpu_present(pr->id)))
829 kobject_uevent(&device->kobj, KOBJ_OFFLINE);
831 if (processor_cntl_external())
832 processor_notify_external(pr, PROCESSOR_HOTPLUG,
833 HOTPLUG_TYPE_REMOVE);
835 break;
836 default:
837 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
838 "Unsupported event [0x%x]\n", event));
839 break;
840 }
842 return;
843 }
845 static acpi_status
846 processor_walk_namespace_cb(acpi_handle handle,
847 u32 lvl, void *context, void **rv)
848 {
849 acpi_status status;
850 int *action = context;
851 acpi_object_type type = 0;
853 status = acpi_get_type(handle, &type);
854 if (ACPI_FAILURE(status))
855 return (AE_OK);
857 if (type != ACPI_TYPE_PROCESSOR)
858 return (AE_OK);
860 switch (*action) {
861 case INSTALL_NOTIFY_HANDLER:
862 acpi_install_notify_handler(handle,
863 ACPI_SYSTEM_NOTIFY,
864 acpi_processor_hotplug_notify,
865 NULL);
866 break;
867 case UNINSTALL_NOTIFY_HANDLER:
868 acpi_remove_notify_handler(handle,
869 ACPI_SYSTEM_NOTIFY,
870 acpi_processor_hotplug_notify);
871 break;
872 default:
873 break;
874 }
876 return (AE_OK);
877 }
879 static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
880 {
882 if (!is_processor_present(handle)) {
883 return AE_ERROR;
884 }
886 if (acpi_map_lsapic(handle, p_cpu))
887 return AE_ERROR;
889 if (arch_register_cpu(*p_cpu)) {
890 acpi_unmap_lsapic(*p_cpu);
891 return AE_ERROR;
892 }
894 return AE_OK;
895 }
897 static int acpi_processor_handle_eject(struct acpi_processor *pr)
898 {
899 #ifdef CONFIG_XEN
900 if (pr->id == -1)
901 return (0);
902 #endif /* CONFIG_XEN */
904 if (cpu_online(pr->id)) {
905 return (-EINVAL);
906 }
907 arch_unregister_cpu(pr->id);
908 acpi_unmap_lsapic(pr->id);
909 return (0);
910 }
911 #else
912 static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
913 {
914 return AE_ERROR;
915 }
916 static int acpi_processor_handle_eject(struct acpi_processor *pr)
917 {
918 return (-EINVAL);
919 }
920 #endif
922 static
923 void acpi_processor_install_hotplug_notify(void)
924 {
925 #ifdef CONFIG_ACPI_HOTPLUG_CPU
926 int action = INSTALL_NOTIFY_HANDLER;
927 acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
928 ACPI_ROOT_OBJECT,
929 ACPI_UINT32_MAX,
930 processor_walk_namespace_cb, &action, NULL);
931 #endif
932 }
934 static
935 void acpi_processor_uninstall_hotplug_notify(void)
936 {
937 #ifdef CONFIG_ACPI_HOTPLUG_CPU
938 int action = UNINSTALL_NOTIFY_HANDLER;
939 acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
940 ACPI_ROOT_OBJECT,
941 ACPI_UINT32_MAX,
942 processor_walk_namespace_cb, &action, NULL);
943 #endif
944 }
946 /*
947 * We keep the driver loaded even when ACPI is not running.
948 * This is needed for the powernow-k8 driver, that works even without
949 * ACPI, but needs symbols from this driver
950 */
952 static int __init acpi_processor_init(void)
953 {
954 int result = 0;
957 memset(&processors, 0, sizeof(processors));
958 memset(&errata, 0, sizeof(errata));
960 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
961 if (!acpi_processor_dir)
962 return 0;
963 acpi_processor_dir->owner = THIS_MODULE;
965 result = acpi_bus_register_driver(&acpi_processor_driver);
966 if (result < 0) {
967 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
968 return 0;
969 }
971 acpi_processor_install_hotplug_notify();
973 acpi_thermal_cpufreq_init();
975 acpi_processor_ppc_init();
977 acpi_processor_throttling_init();
979 return 0;
980 }
982 static void __exit acpi_processor_exit(void)
983 {
985 acpi_processor_ppc_exit();
987 acpi_thermal_cpufreq_exit();
989 acpi_processor_uninstall_hotplug_notify();
991 acpi_bus_unregister_driver(&acpi_processor_driver);
993 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
995 return;
996 }
998 module_init(acpi_processor_init);
999 module_exit(acpi_processor_exit);
1001 EXPORT_SYMBOL(acpi_processor_set_thermal_limit);
1003 MODULE_ALIAS("processor");