blob: c8a0ca2af839993bde9c9d849cdc6fdccec5ef04 [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>
Zhang Ruid5c68872010-10-08 13:55:15 +080043#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/proc_fs.h>
45#include <linux/seq_file.h>
Zhang Ruid5c68872010-10-08 13:55:15 +080046#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/dmi.h>
48#include <linux/moduleparam.h>
Len Brown4f86d3a2007-10-03 18:58:00 -040049#include <linux/cpuidle.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090050#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
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
Len Browna192a952009-07-28 16:45:54 -040065#define PREFIX "ACPI: "
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define ACPI_PROCESSOR_CLASS "processor"
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#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
Luming Yu01854e62007-05-26 22:49:58 +080074#define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76#define ACPI_PROCESSOR_LIMIT_USER 0
77#define ACPI_PROCESSOR_LIMIT_THERMAL 1
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#define _COMPONENT ACPI_PROCESSOR_COMPONENT
Alex Chiang0131aa32010-02-22 12:11:08 -070080ACPI_MODULE_NAME("processor_driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Len Brownf52fd662007-02-12 22:42:12 -050082MODULE_AUTHOR("Paul Diefenbaugh");
Len Brown7cda93e2007-02-12 23:50:02 -050083MODULE_DESCRIPTION("ACPI Processor Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070084MODULE_LICENSE("GPL");
85
Len Brown4be44fc2005-08-05 00:44:28 -040086static int acpi_processor_add(struct acpi_device *device);
Len Brown4be44fc2005-08-05 00:44:28 -040087static int acpi_processor_remove(struct acpi_device *device, int type);
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +000088static void acpi_processor_notify(struct acpi_device *device, u32 event);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
90static int acpi_processor_handle_eject(struct acpi_processor *pr);
Luming Yu01854e62007-05-26 22:49:58 +080091
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Thomas Renninger1ba90e32007-07-23 14:44:41 +020093static const struct acpi_device_id processor_device_ids[] = {
Myron Stowead93a762008-11-04 14:52:55 -070094 {ACPI_PROCESSOR_OBJECT_HID, 0},
Bjorn Helgaas9eccbc22009-04-27 16:33:46 -060095 {"ACPI0007", 0},
Thomas Renninger1ba90e32007-07-23 14:44:41 +020096 {"", 0},
97};
98MODULE_DEVICE_TABLE(acpi, processor_device_ids);
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100static struct acpi_driver acpi_processor_driver = {
Len Brownc2b67052007-02-12 23:33:40 -0500101 .name = "processor",
Len Brown4be44fc2005-08-05 00:44:28 -0400102 .class = ACPI_PROCESSOR_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200103 .ids = processor_device_ids,
Len Brown4be44fc2005-08-05 00:44:28 -0400104 .ops = {
105 .add = acpi_processor_add,
106 .remove = acpi_processor_remove,
Thomas Gleixnerb04e7bd2007-09-22 22:29:05 +0000107 .suspend = acpi_processor_suspend,
108 .resume = acpi_processor_resume,
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000109 .notify = acpi_processor_notify,
Len Brown4be44fc2005-08-05 00:44:28 -0400110 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
113#define INSTALL_NOTIFY_HANDLER 1
114#define UNINSTALL_NOTIFY_HANDLER 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Mike Travis706546d2008-06-09 16:22:23 -0700116DEFINE_PER_CPU(struct acpi_processor *, processors);
Naga Chumbalkar0f1d6832009-12-17 20:18:27 +0000117EXPORT_PER_CPU_SYMBOL(processors);
118
Andreas Mohr9f222712006-06-23 02:04:27 -0700119struct acpi_processor_errata errata __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121/* --------------------------------------------------------------------------
122 Errata Handling
123 -------------------------------------------------------------------------- */
124
Len Brown4be44fc2005-08-05 00:44:28 -0400125static int acpi_processor_errata_piix4(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Len Brown4be44fc2005-08-05 00:44:28 -0400127 u8 value1 = 0;
128 u8 value2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400132 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 /*
135 * Note that 'dev' references the PIIX4 ACPI Controller.
136 */
137
Auke Kok44c10132007-06-08 15:46:36 -0700138 switch (dev->revision) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 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
Auke Kok44c10132007-06-08 15:46:36 -0700156 switch (dev->revision) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
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,
Len Brown4be44fc2005-08-05 00:44:28 -0400186 PCI_DEVICE_ID_INTEL_82371AB,
187 PCI_ANY_ID, PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 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,
Len Brown4be44fc2005-08-05 00:44:28 -0400203 PCI_DEVICE_ID_INTEL_82371AB_0,
204 PCI_ANY_ID, PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 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,
Len Brown4be44fc2005-08-05 00:44:28 -0400218 "Bus master activity detection (BM-IDE) erratum enabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 if (errata.piix4.fdma)
220 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400221 "Type-F DMA livelock erratum (C3 disabled)\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Patrick Mocheld550d982006-06-27 00:41:40 -0400223 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225
Adrian Bunk8713cbe2005-09-02 17:16:48 -0400226static int acpi_processor_errata(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
Len Brown4be44fc2005-08-05 00:44:28 -0400228 int result = 0;
229 struct pci_dev *dev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400233 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 /*
236 * PIIX4
237 */
238 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
Len Brown4be44fc2005-08-05 00:44:28 -0400239 PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
240 PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 if (dev) {
242 result = acpi_processor_errata_piix4(dev);
243 pci_dev_put(dev);
244 }
245
Patrick Mocheld550d982006-06-27 00:41:40 -0400246 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
Zhang Ruid5c68872010-10-08 13:55:15 +0800249#ifdef CONFIG_ACPI_PROCFS
Len Brown4be44fc2005-08-05 00:44:28 -0400250static struct proc_dir_entry *acpi_processor_dir = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Thomas Renningerbf8b4542009-10-26 17:44:18 +0100252static int __cpuinit acpi_processor_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Len Brown4be44fc2005-08-05 00:44:28 -0400254 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 if (!acpi_device_dir(device)) {
258 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400259 acpi_processor_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400261 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 /* 'throttling' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700265 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400271 return -EIO;
Patrick Mocheld550d982006-06-27 00:41:40 -0400272 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
Len Brown4be44fc2005-08-05 00:44:28 -0400274static int acpi_processor_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 if (acpi_device_dir(device)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
Len Brown4be44fc2005-08-05 00:44:28 -0400279 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 remove_proc_entry(acpi_device_bid(device), acpi_processor_dir);
281 acpi_device_dir(device) = NULL;
282 }
283
Patrick Mocheld550d982006-06-27 00:41:40 -0400284 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
Zhang Ruid5c68872010-10-08 13:55:15 +0800286#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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296/* --------------------------------------------------------------------------
297 Driver Interface
298 -------------------------------------------------------------------------- */
299
Myron Stoweb26e9282008-11-04 14:53:00 -0700300static int acpi_processor_get_info(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
Len Brown4be44fc2005-08-05 00:44:28 -0400302 acpi_status status = 0;
303 union acpi_object object = { 0 };
304 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
Myron Stoweb26e9282008-11-04 14:53:00 -0700305 struct acpi_processor *pr;
306 int cpu_index, device_declaration = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400307 static int cpu0_initialized;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Myron Stoweb26e9282008-11-04 14:53:00 -0700309 pr = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400311 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
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 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300322 if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 pr->flags.bm_control = 1;
324 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400325 "Bus mastering arbitration control present\n"));
326 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400328 "No bus mastering arbitration control\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Bjorn Helgaas6cc73b42009-04-27 16:33:41 -0600330 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 {
Myron Stoweb26e9282008-11-04 14:53:00 -0700345 /*
346 * Declared with "Device" statement; match _UID.
347 * Note that we don't handle string _UIDs yet.
348 */
Matthew Wilcox27663c52008-10-10 02:22:59 -0400349 unsigned long long value;
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300350 status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
351 NULL, &value);
352 if (ACPI_FAILURE(status)) {
Myron Stoweb26e9282008-11-04 14:53:00 -0700353 printk(KERN_ERR PREFIX
354 "Evaluating processor _UID [%#x]\n", status);
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300355 return -ENODEV;
356 }
Myron Stoweb26e9282008-11-04 14:53:00 -0700357 device_declaration = 1;
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300358 pr->acpi_id = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 }
Alex Chiang2e9d5e42010-02-22 12:11:19 -0700360 cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Len Brown4be44fc2005-08-05 00:44:28 -0400362 /* Handle UP system running SMP kernel, with no LAPIC in MADT */
Ashok Rajdf42baa2006-03-28 17:04:00 -0500363 if (!cpu0_initialized && (cpu_index == -1) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400364 (num_online_cpus() == 1)) {
365 cpu_index = 0;
366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Len Brown4be44fc2005-08-05 00:44:28 -0400368 cpu0_initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Len Brown4be44fc2005-08-05 00:44:28 -0400370 pr->id = cpu_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Len Brown4be44fc2005-08-05 00:44:28 -0400372 /*
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 */
Alexey Starikovskiyf18c5a02007-02-02 19:48:23 +0300377 if (pr->id == -1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400378 if (ACPI_FAILURE
379 (acpi_processor_hotadd_init(pr->handle, &pr->id))) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400380 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400381 }
382 }
Zhao Yakui7a04b842009-06-24 11:46:44 +0800383 /*
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
Len Brown4be44fc2005-08-05 00:44:28 -0400394 pr->acpi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
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)
Len Brown64684632006-06-26 23:41:38 -0400399 printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n",
400 object.processor.pblk_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 else {
402 pr->throttling.address = object.processor.pblk_address;
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300403 pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
404 pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
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
Alex Chiangfe086a72008-04-29 15:05:29 -0700418 /*
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
Patrick Mocheld550d982006-06-27 00:41:40 -0400427 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428}
429
Mike Travis706546d2008-06-09 16:22:23 -0700430static DEFINE_PER_CPU(void *, processor_device_array);
Venkatesh Pallipadicd8e2b42005-10-21 19:22:00 -0400431
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000432static void acpi_processor_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000434 struct acpi_processor *pr = acpi_driver_data(device);
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300435 int saved;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400438 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 switch (event) {
441 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300442 saved = pr->performance_platform_limit;
Zhao Yakuid81c45e12009-10-16 09:20:41 +0800443 acpi_processor_ppc_has_changed(pr, 1);
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300444 if (saved == pr->performance_platform_limit)
445 break;
Len Brown14e04fb32007-08-23 15:20:26 -0400446 acpi_bus_generate_proc_event(device, event,
Len Brown4be44fc2005-08-05 00:44:28 -0400447 pr->performance_platform_limit);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800448 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100449 dev_name(&device->dev), event,
Zhang Rui962ce8c2007-08-23 01:24:31 +0800450 pr->performance_platform_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 break;
452 case ACPI_PROCESSOR_NOTIFY_POWER:
453 acpi_processor_cst_has_changed(pr);
Len Brown14e04fb32007-08-23 15:20:26 -0400454 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800455 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100456 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 break;
Luming Yu01854e62007-05-26 22:49:58 +0800458 case ACPI_PROCESSOR_NOTIFY_THROTTLING:
459 acpi_processor_tstate_has_changed(pr);
Len Brown14e04fb32007-08-23 15:20:26 -0400460 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800461 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100462 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 default:
464 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400465 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 break;
467 }
468
Patrick Mocheld550d982006-06-27 00:41:40 -0400469 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
471
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200472static int acpi_cpu_soft_notify(struct notifier_block *nfb,
473 unsigned long action, void *hcpu)
474{
475 unsigned int cpu = (unsigned long)hcpu;
Mike Travis706546d2008-06-09 16:22:23 -0700476 struct acpi_processor *pr = per_cpu(processors, cpu);
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200477
478 if (action == CPU_ONLINE && pr) {
Zhao Yakuid81c45e12009-10-16 09:20:41 +0800479 acpi_processor_ppc_has_changed(pr, 0);
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200480 acpi_processor_cst_has_changed(pr);
Zhao Yakui5a344a52011-01-10 16:35:45 +0800481 acpi_processor_reevaluate_tstate(pr, action);
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200482 acpi_processor_tstate_has_changed(pr);
483 }
Zhao Yakui5a344a52011-01-10 16:35:45 +0800484 if (action == CPU_DEAD && pr) {
485 /* invalidate the flag.throttling after one CPU is offline */
486 acpi_processor_reevaluate_tstate(pr, action);
487 }
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200488 return NOTIFY_OK;
489}
490
491static struct notifier_block acpi_cpu_notifier =
492{
493 .notifier_call = acpi_cpu_soft_notify,
494};
495
Rakib Mullick941b10f2009-11-05 16:51:40 -0500496static int __cpuinit acpi_processor_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
Len Brown4be44fc2005-08-05 00:44:28 -0400498 struct acpi_processor *pr = NULL;
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000499 int result = 0;
500 struct sys_device *sysdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Burman Yan36bcbec2006-12-19 12:56:11 -0800502 pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400504 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Yinghai Lueaa95842009-06-06 14:51:36 -0700506 if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) {
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800507 kfree(pr);
508 return -ENOMEM;
509 }
510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 pr->handle = device->handle;
512 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
513 strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700514 device->driver_data = pr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 result = acpi_processor_get_info(device);
517 if (result) {
518 /* Processor is physically not present */
519 return 0;
520 }
521
Thomas Renninger75cbfb92010-05-26 17:03:33 +0200522#ifdef CONFIG_SMP
523 if (pr->id >= setup_max_cpus && pr->id != 0)
524 return 0;
525#endif
526
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
528
529 /*
530 * Buggy BIOS check
531 * ACPI id of processors can be reported wrongly by the BIOS.
532 * Don't trust it blindly
533 */
534 if (per_cpu(processor_device_array, pr->id) != NULL &&
535 per_cpu(processor_device_array, pr->id) != device) {
536 printk(KERN_WARNING "BIOS reported wrong ACPI id "
537 "for the processor\n");
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000538 result = -ENODEV;
539 goto err_free_cpumask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 }
541 per_cpu(processor_device_array, pr->id) = device;
542
543 per_cpu(processors, pr->id) = pr;
544
545 result = acpi_processor_add_fs(device);
546 if (result)
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000547 goto err_free_cpumask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 sysdev = get_cpu_sysdev(pr->id);
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000550 if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) {
551 result = -EFAULT;
552 goto err_remove_fs;
553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#ifdef CONFIG_CPU_FREQ
Zhao Yakuid81c45e12009-10-16 09:20:41 +0800556 acpi_processor_ppc_has_changed(pr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#endif
558 acpi_processor_get_throttling_info(pr);
559 acpi_processor_get_limit_info(pr);
560
561
Len Brown541adf72010-05-22 17:03:29 -0400562 if (cpuidle_get_driver() == &acpi_idle_driver)
563 acpi_processor_power_init(pr, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 pr->cdev = thermal_cooling_device_register("Processor", device,
566 &processor_cooling_ops);
567 if (IS_ERR(pr->cdev)) {
568 result = PTR_ERR(pr->cdev);
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000569 goto err_power_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 }
571
Mike Travis13c41152009-12-14 13:38:30 -0800572 dev_dbg(&device->dev, "registered as cooling_device%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 pr->cdev->id);
574
575 result = sysfs_create_link(&device->dev.kobj,
576 &pr->cdev->device.kobj,
577 "thermal_cooling");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000578 if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 printk(KERN_ERR PREFIX "Create sysfs link\n");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000580 goto err_thermal_unregister;
581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 result = sysfs_create_link(&pr->cdev->device.kobj,
583 &device->dev.kobj,
584 "device");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000585 if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 printk(KERN_ERR PREFIX "Create sysfs link\n");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000587 goto err_remove_sysfs;
588 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Patrick Mocheld550d982006-06-27 00:41:40 -0400590 return 0;
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000591
592err_remove_sysfs:
593 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
594err_thermal_unregister:
595 thermal_cooling_device_unregister(pr->cdev);
596err_power_exit:
597 acpi_processor_power_exit(pr, device);
598err_remove_fs:
599 acpi_processor_remove_fs(device);
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000600err_free_cpumask:
601 free_cpumask_var(pr->throttling.shared_cpu_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
Len Brown4be44fc2005-08-05 00:44:28 -0400606static int acpi_processor_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
Len Brown4be44fc2005-08-05 00:44:28 -0400608 struct acpi_processor *pr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400612 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200614 pr = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800616 if (pr->id >= nr_cpu_ids)
617 goto free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
619 if (type == ACPI_BUS_REMOVAL_EJECT) {
620 if (acpi_processor_handle_eject(pr))
Patrick Mocheld550d982006-06-27 00:41:40 -0400621 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 }
623
624 acpi_processor_power_exit(pr, device);
625
Zhang Rui9f1eb992008-04-29 02:36:07 -0400626 sysfs_remove_link(&device->dev.kobj, "sysdev");
627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 acpi_processor_remove_fs(device);
629
Zhao Yakuif28bb452008-02-15 08:34:37 +0800630 if (pr->cdev) {
631 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
632 sysfs_remove_link(&pr->cdev->device.kobj, "device");
633 thermal_cooling_device_unregister(pr->cdev);
634 pr->cdev = NULL;
635 }
Zhang Ruid9460fd222008-01-17 15:51:23 +0800636
Mike Travis706546d2008-06-09 16:22:23 -0700637 per_cpu(processors, pr->id) = NULL;
638 per_cpu(processor_device_array, pr->id) = NULL;
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800639
640free:
641 free_cpumask_var(pr->throttling.shared_cpu_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 kfree(pr);
643
Patrick Mocheld550d982006-06-27 00:41:40 -0400644 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645}
646
647#ifdef CONFIG_ACPI_HOTPLUG_CPU
648/****************************************************************************
649 * Acpi processor hotplug support *
650 ****************************************************************************/
651
Len Brown4be44fc2005-08-05 00:44:28 -0400652static int is_processor_present(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
Len Brown4be44fc2005-08-05 00:44:28 -0400654 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400655 unsigned long long sta = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
Zhang Ruicfaf3742008-01-09 02:17:47 -0500659
660 if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
661 return 1;
662
Zhang Ruid0ce46f2008-02-23 01:53:09 -0500663 /*
664 * _STA is mandatory for a processor that supports hot plug
665 */
666 if (status == AE_NOT_FOUND)
667 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
668 "Processor does not support hot plug\n"));
669 else
670 ACPI_EXCEPTION((AE_INFO, status,
671 "Processor Device is not present"));
Zhang Ruicfaf3742008-01-09 02:17:47 -0500672 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673}
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675static
Len Brown4be44fc2005-08-05 00:44:28 -0400676int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677{
Len Brown4be44fc2005-08-05 00:44:28 -0400678 acpi_handle phandle;
679 struct acpi_device *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682 if (acpi_get_parent(handle, &phandle)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400683 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685
686 if (acpi_bus_get_device(phandle, &pdev)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400687 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 }
689
690 if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400691 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 }
693
Patrick Mocheld550d982006-06-27 00:41:40 -0400694 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695}
696
Sam Ravnborgb95e9e82008-02-17 13:22:48 +0100697static void __ref acpi_processor_hotplug_notify(acpi_handle handle,
698 u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699{
Len Brown4be44fc2005-08-05 00:44:28 -0400700 struct acpi_processor *pr;
701 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 int result;
703
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705 switch (event) {
706 case ACPI_NOTIFY_BUS_CHECK:
707 case ACPI_NOTIFY_DEVICE_CHECK:
Glauber Costad6f882e2008-03-04 15:06:36 -0800708 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
709 "Processor driver received %s event\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400710 (event == ACPI_NOTIFY_BUS_CHECK) ?
Glauber Costad6f882e2008-03-04 15:06:36 -0800711 "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713 if (!is_processor_present(handle))
714 break;
715
716 if (acpi_bus_get_device(handle, &device)) {
717 result = acpi_processor_device_add(handle, &device);
718 if (result)
Len Brown64684632006-06-26 23:41:38 -0400719 printk(KERN_ERR PREFIX
720 "Unable to add the device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 break;
722 }
Len Brown4be44fc2005-08-05 00:44:28 -0400723 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 case ACPI_NOTIFY_EJECT_REQUEST:
Len Brown4be44fc2005-08-05 00:44:28 -0400725 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
726 "received ACPI_NOTIFY_EJECT_REQUEST\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 if (acpi_bus_get_device(handle, &device)) {
Len Brown64684632006-06-26 23:41:38 -0400729 printk(KERN_ERR PREFIX
730 "Device don't exist, dropping EJECT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 break;
732 }
733 pr = acpi_driver_data(device);
734 if (!pr) {
Len Brown64684632006-06-26 23:41:38 -0400735 printk(KERN_ERR PREFIX
736 "Driver data is NULL, dropping EJECT\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400737 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 break;
740 default:
741 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400742 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 break;
744 }
745
Patrick Mocheld550d982006-06-27 00:41:40 -0400746 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747}
748
749static acpi_status
750processor_walk_namespace_cb(acpi_handle handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400751 u32 lvl, void *context, void **rv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752{
Len Brown4be44fc2005-08-05 00:44:28 -0400753 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 int *action = context;
Len Brown4be44fc2005-08-05 00:44:28 -0400755 acpi_object_type type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 status = acpi_get_type(handle, &type);
758 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400759 return (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 if (type != ACPI_TYPE_PROCESSOR)
Len Brown4be44fc2005-08-05 00:44:28 -0400762 return (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Len Brown4be44fc2005-08-05 00:44:28 -0400764 switch (*action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 case INSTALL_NOTIFY_HANDLER:
766 acpi_install_notify_handler(handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400767 ACPI_SYSTEM_NOTIFY,
768 acpi_processor_hotplug_notify,
769 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 break;
771 case UNINSTALL_NOTIFY_HANDLER:
772 acpi_remove_notify_handler(handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400773 ACPI_SYSTEM_NOTIFY,
774 acpi_processor_hotplug_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 break;
776 default:
777 break;
778 }
779
Len Brown4be44fc2005-08-05 00:44:28 -0400780 return (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
782
Len Brown4be44fc2005-08-05 00:44:28 -0400783static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
786 if (!is_processor_present(handle)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400787 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 }
789
790 if (acpi_map_lsapic(handle, p_cpu))
Patrick Mocheld550d982006-06-27 00:41:40 -0400791 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793 if (arch_register_cpu(*p_cpu)) {
794 acpi_unmap_lsapic(*p_cpu);
Patrick Mocheld550d982006-06-27 00:41:40 -0400795 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 }
797
Patrick Mocheld550d982006-06-27 00:41:40 -0400798 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799}
800
Len Brown4be44fc2005-08-05 00:44:28 -0400801static int acpi_processor_handle_eject(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
Zhang Ruib62b8ef2008-04-29 02:35:56 -0400803 if (cpu_online(pr->id))
804 cpu_down(pr->id);
805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 arch_unregister_cpu(pr->id);
807 acpi_unmap_lsapic(pr->id);
Len Brown4be44fc2005-08-05 00:44:28 -0400808 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809}
810#else
Len Brown4be44fc2005-08-05 00:44:28 -0400811static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812{
813 return AE_ERROR;
814}
Len Brown4be44fc2005-08-05 00:44:28 -0400815static int acpi_processor_handle_eject(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816{
Len Brown4be44fc2005-08-05 00:44:28 -0400817 return (-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819#endif
820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821static
822void acpi_processor_install_hotplug_notify(void)
823{
824#ifdef CONFIG_ACPI_HOTPLUG_CPU
825 int action = INSTALL_NOTIFY_HANDLER;
826 acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
Len Brown4be44fc2005-08-05 00:44:28 -0400827 ACPI_ROOT_OBJECT,
828 ACPI_UINT32_MAX,
Lin Ming22635762009-11-13 10:06:08 +0800829 processor_walk_namespace_cb, NULL, &action, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830#endif
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200831 register_hotcpu_notifier(&acpi_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832}
833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834static
835void acpi_processor_uninstall_hotplug_notify(void)
836{
837#ifdef CONFIG_ACPI_HOTPLUG_CPU
838 int action = UNINSTALL_NOTIFY_HANDLER;
839 acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
Len Brown4be44fc2005-08-05 00:44:28 -0400840 ACPI_ROOT_OBJECT,
841 ACPI_UINT32_MAX,
Lin Ming22635762009-11-13 10:06:08 +0800842 processor_walk_namespace_cb, NULL, &action, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843#endif
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200844 unregister_hotcpu_notifier(&acpi_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845}
846
847/*
848 * We keep the driver loaded even when ACPI is not running.
849 * This is needed for the powernow-k8 driver, that works even without
850 * ACPI, but needs symbols from this driver
851 */
852
Len Brown4be44fc2005-08-05 00:44:28 -0400853static int __init acpi_processor_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854{
Len Brown4be44fc2005-08-05 00:44:28 -0400855 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Yinghai Luce8442b2009-08-26 14:29:26 -0700857 if (acpi_disabled)
858 return 0;
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 memset(&errata, 0, sizeof(errata));
861
Zhang Ruid5c68872010-10-08 13:55:15 +0800862#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
864 if (!acpi_processor_dir)
Akinobu Mita83822fc2006-12-19 12:56:10 -0800865 return -ENOMEM;
Zhang Ruid5c68872010-10-08 13:55:15 +0800866#endif
Len Brown541adf72010-05-22 17:03:29 -0400867
Len Brown26717172010-03-08 14:07:30 -0500868 if (!cpuidle_register_driver(&acpi_idle_driver)) {
Len Brown541adf72010-05-22 17:03:29 -0400869 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
870 acpi_idle_driver.name);
Len Brown26717172010-03-08 14:07:30 -0500871 } else {
Len Browne9a64ed2010-09-24 20:50:02 -0400872 printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s\n",
Len Brown26717172010-03-08 14:07:30 -0500873 cpuidle_get_driver()->name);
874 }
Len Brown4f86d3a2007-10-03 18:58:00 -0400875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 result = acpi_bus_register_driver(&acpi_processor_driver);
Len Brown4f86d3a2007-10-03 18:58:00 -0400877 if (result < 0)
878 goto out_cpuidle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
880 acpi_processor_install_hotplug_notify();
881
882 acpi_thermal_cpufreq_init();
883
884 acpi_processor_ppc_init();
885
Zhao Yakui11805092008-01-28 13:53:42 +0800886 acpi_processor_throttling_init();
887
Patrick Mocheld550d982006-06-27 00:41:40 -0400888 return 0;
Len Brown4f86d3a2007-10-03 18:58:00 -0400889
890out_cpuidle:
891 cpuidle_unregister_driver(&acpi_idle_driver);
892
Zhang Ruid5c68872010-10-08 13:55:15 +0800893#ifdef CONFIG_ACPI_PROCFS
Len Brown4f86d3a2007-10-03 18:58:00 -0400894 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
Zhang Ruid5c68872010-10-08 13:55:15 +0800895#endif
Len Brown4f86d3a2007-10-03 18:58:00 -0400896
897 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898}
899
Len Brown4be44fc2005-08-05 00:44:28 -0400900static void __exit acpi_processor_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901{
Yinghai Luce8442b2009-08-26 14:29:26 -0700902 if (acpi_disabled)
903 return;
904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 acpi_processor_ppc_exit();
906
907 acpi_thermal_cpufreq_exit();
908
909 acpi_processor_uninstall_hotplug_notify();
910
911 acpi_bus_unregister_driver(&acpi_processor_driver);
912
Len Brown4f86d3a2007-10-03 18:58:00 -0400913 cpuidle_unregister_driver(&acpi_idle_driver);
914
Zhang Ruid5c68872010-10-08 13:55:15 +0800915#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
Zhang Ruid5c68872010-10-08 13:55:15 +0800917#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Patrick Mocheld550d982006-06-27 00:41:40 -0400919 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920}
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922module_init(acpi_processor_init);
923module_exit(acpi_processor_exit);
924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925MODULE_ALIAS("processor");