blob: 15602189238942cc9db03b9d9f25c18823128ea0 [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>
43#include <linux/proc_fs.h>
44#include <linux/seq_file.h>
45#include <linux/dmi.h>
46#include <linux/moduleparam.h>
Len Brown4f86d3a2007-10-03 18:58:00 -040047#include <linux/cpuidle.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090048#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <asm/io.h>
51#include <asm/system.h>
52#include <asm/cpu.h>
53#include <asm/delay.h>
54#include <asm/uaccess.h>
55#include <asm/processor.h>
56#include <asm/smp.h>
57#include <asm/acpi.h>
58
59#include <acpi/acpi_bus.h>
60#include <acpi/acpi_drivers.h>
61#include <acpi/processor.h>
62
Len Browna192a952009-07-28 16:45:54 -040063#define PREFIX "ACPI: "
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define ACPI_PROCESSOR_CLASS "processor"
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#define ACPI_PROCESSOR_DEVICE_NAME "Processor"
67#define ACPI_PROCESSOR_FILE_INFO "info"
68#define ACPI_PROCESSOR_FILE_THROTTLING "throttling"
69#define ACPI_PROCESSOR_FILE_LIMIT "limit"
70#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
71#define ACPI_PROCESSOR_NOTIFY_POWER 0x81
Luming Yu01854e62007-05-26 22:49:58 +080072#define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74#define ACPI_PROCESSOR_LIMIT_USER 0
75#define ACPI_PROCESSOR_LIMIT_THERMAL 1
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#define _COMPONENT ACPI_PROCESSOR_COMPONENT
Alex Chiang0131aa32010-02-22 12:11:08 -070078ACPI_MODULE_NAME("processor_driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Len Brownf52fd662007-02-12 22:42:12 -050080MODULE_AUTHOR("Paul Diefenbaugh");
Len Brown7cda93e2007-02-12 23:50:02 -050081MODULE_DESCRIPTION("ACPI Processor Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070082MODULE_LICENSE("GPL");
83
Len Brown4be44fc2005-08-05 00:44:28 -040084static int acpi_processor_add(struct acpi_device *device);
Len Brown4be44fc2005-08-05 00:44:28 -040085static int acpi_processor_remove(struct acpi_device *device, int type);
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +000086static void acpi_processor_notify(struct acpi_device *device, u32 event);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
88static int acpi_processor_handle_eject(struct acpi_processor *pr);
Luming Yu01854e62007-05-26 22:49:58 +080089
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Thomas Renninger1ba90e32007-07-23 14:44:41 +020091static const struct acpi_device_id processor_device_ids[] = {
Myron Stowead93a762008-11-04 14:52:55 -070092 {ACPI_PROCESSOR_OBJECT_HID, 0},
Bjorn Helgaas9eccbc22009-04-27 16:33:46 -060093 {"ACPI0007", 0},
Thomas Renninger1ba90e32007-07-23 14:44:41 +020094 {"", 0},
95};
96MODULE_DEVICE_TABLE(acpi, processor_device_ids);
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098static struct acpi_driver acpi_processor_driver = {
Len Brownc2b67052007-02-12 23:33:40 -050099 .name = "processor",
Len Brown4be44fc2005-08-05 00:44:28 -0400100 .class = ACPI_PROCESSOR_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200101 .ids = processor_device_ids,
Len Brown4be44fc2005-08-05 00:44:28 -0400102 .ops = {
103 .add = acpi_processor_add,
104 .remove = acpi_processor_remove,
Thomas Gleixnerb04e7bd2007-09-22 22:29:05 +0000105 .suspend = acpi_processor_suspend,
106 .resume = acpi_processor_resume,
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000107 .notify = acpi_processor_notify,
Len Brown4be44fc2005-08-05 00:44:28 -0400108 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109};
110
111#define INSTALL_NOTIFY_HANDLER 1
112#define UNINSTALL_NOTIFY_HANDLER 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Mike Travis706546d2008-06-09 16:22:23 -0700114DEFINE_PER_CPU(struct acpi_processor *, processors);
Naga Chumbalkar0f1d6832009-12-17 20:18:27 +0000115EXPORT_PER_CPU_SYMBOL(processors);
116
Andreas Mohr9f222712006-06-23 02:04:27 -0700117struct acpi_processor_errata errata __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119/* --------------------------------------------------------------------------
120 Errata Handling
121 -------------------------------------------------------------------------- */
122
Len Brown4be44fc2005-08-05 00:44:28 -0400123static int acpi_processor_errata_piix4(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Len Brown4be44fc2005-08-05 00:44:28 -0400125 u8 value1 = 0;
126 u8 value2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400130 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /*
133 * Note that 'dev' references the PIIX4 ACPI Controller.
134 */
135
Auke Kok44c10132007-06-08 15:46:36 -0700136 switch (dev->revision) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 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 }
153
Auke Kok44c10132007-06-08 15:46:36 -0700154 switch (dev->revision) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
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;
166
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 */
174
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,
Len Brown4be44fc2005-08-05 00:44:28 -0400184 PCI_DEVICE_ID_INTEL_82371AB,
185 PCI_ANY_ID, PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 if (dev) {
187 errata.piix4.bmisx = pci_resource_start(dev, 4);
188 pci_dev_put(dev);
189 }
190
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,
Len Brown4be44fc2005-08-05 00:44:28 -0400201 PCI_DEVICE_ID_INTEL_82371AB_0,
202 PCI_ANY_ID, PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 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 }
210
211 break;
212 }
213
214 if (errata.piix4.bmisx)
215 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400216 "Bus master activity detection (BM-IDE) erratum enabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 if (errata.piix4.fdma)
218 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400219 "Type-F DMA livelock erratum (C3 disabled)\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Patrick Mocheld550d982006-06-27 00:41:40 -0400221 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
223
Adrian Bunk8713cbe2005-09-02 17:16:48 -0400224static int acpi_processor_errata(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Len Brown4be44fc2005-08-05 00:44:28 -0400226 int result = 0;
227 struct pci_dev *dev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400231 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 /*
234 * PIIX4
235 */
236 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
Len Brown4be44fc2005-08-05 00:44:28 -0400237 PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
238 PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 if (dev) {
240 result = acpi_processor_errata_piix4(dev);
241 pci_dev_put(dev);
242 }
243
Patrick Mocheld550d982006-06-27 00:41:40 -0400244 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}
246
Len Brown4be44fc2005-08-05 00:44:28 -0400247static struct proc_dir_entry *acpi_processor_dir = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Thomas Renningerbf8b4542009-10-26 17:44:18 +0100249static int __cpuinit acpi_processor_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Len Brown4be44fc2005-08-05 00:44:28 -0400251 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 if (!acpi_device_dir(device)) {
255 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400256 acpi_processor_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400258 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 /* 'throttling' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700262 entry = proc_create_data(ACPI_PROCESSOR_FILE_THROTTLING,
263 S_IFREG | S_IRUGO | S_IWUSR,
264 acpi_device_dir(device),
265 &acpi_processor_throttling_fops,
266 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400268 return -EIO;
Patrick Mocheld550d982006-06-27 00:41:40 -0400269 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270}
Len Brown4be44fc2005-08-05 00:44:28 -0400271static int acpi_processor_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 if (acpi_device_dir(device)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
Len Brown4be44fc2005-08-05 00:44:28 -0400276 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 remove_proc_entry(acpi_device_bid(device), acpi_processor_dir);
278 acpi_device_dir(device) = NULL;
279 }
280
Patrick Mocheld550d982006-06-27 00:41:40 -0400281 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284/* --------------------------------------------------------------------------
285 Driver Interface
286 -------------------------------------------------------------------------- */
287
Myron Stoweb26e9282008-11-04 14:53:00 -0700288static int acpi_processor_get_info(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Len Brown4be44fc2005-08-05 00:44:28 -0400290 acpi_status status = 0;
291 union acpi_object object = { 0 };
292 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
Myron Stoweb26e9282008-11-04 14:53:00 -0700293 struct acpi_processor *pr;
294 int cpu_index, device_declaration = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400295 static int cpu0_initialized;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Myron Stoweb26e9282008-11-04 14:53:00 -0700297 pr = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400299 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301 if (num_online_cpus() > 1)
302 errata.smp = TRUE;
303
304 acpi_processor_errata(pr);
305
306 /*
307 * Check to see if we have bus mastering arbitration control. This
308 * is required for proper C3 usage (to maintain cache coherency).
309 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300310 if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 pr->flags.bm_control = 1;
312 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400313 "Bus mastering arbitration control present\n"));
314 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400316 "No bus mastering arbitration control\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Bjorn Helgaas6cc73b42009-04-27 16:33:41 -0600318 if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) {
319 /* Declared with "Processor" statement; match ProcessorID */
320 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
321 if (ACPI_FAILURE(status)) {
322 printk(KERN_ERR PREFIX "Evaluating processor object\n");
323 return -ENODEV;
324 }
325
326 /*
327 * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
328 * >>> 'acpi_get_processor_id(acpi_id, &id)' in
329 * arch/xxx/acpi.c
330 */
331 pr->acpi_id = object.processor.proc_id;
332 } else {
Myron Stoweb26e9282008-11-04 14:53:00 -0700333 /*
334 * Declared with "Device" statement; match _UID.
335 * Note that we don't handle string _UIDs yet.
336 */
Matthew Wilcox27663c52008-10-10 02:22:59 -0400337 unsigned long long value;
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300338 status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
339 NULL, &value);
340 if (ACPI_FAILURE(status)) {
Myron Stoweb26e9282008-11-04 14:53:00 -0700341 printk(KERN_ERR PREFIX
342 "Evaluating processor _UID [%#x]\n", status);
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300343 return -ENODEV;
344 }
Myron Stoweb26e9282008-11-04 14:53:00 -0700345 device_declaration = 1;
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300346 pr->acpi_id = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 }
Alex Chiang2e9d5e42010-02-22 12:11:19 -0700348 cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Len Brown4be44fc2005-08-05 00:44:28 -0400350 /* Handle UP system running SMP kernel, with no LAPIC in MADT */
Ashok Rajdf42baa2006-03-28 17:04:00 -0500351 if (!cpu0_initialized && (cpu_index == -1) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400352 (num_online_cpus() == 1)) {
353 cpu_index = 0;
354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 cpu0_initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Len Brown4be44fc2005-08-05 00:44:28 -0400358 pr->id = cpu_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Len Brown4be44fc2005-08-05 00:44:28 -0400360 /*
361 * Extra Processor objects may be enumerated on MP systems with
362 * less than the max # of CPUs. They should be ignored _iff
363 * they are physically not present.
364 */
Alexey Starikovskiyf18c5a02007-02-02 19:48:23 +0300365 if (pr->id == -1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400366 if (ACPI_FAILURE
367 (acpi_processor_hotadd_init(pr->handle, &pr->id))) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400368 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400369 }
370 }
Zhao Yakui7a04b842009-06-24 11:46:44 +0800371 /*
372 * On some boxes several processors use the same processor bus id.
373 * But they are located in different scope. For example:
374 * \_SB.SCK0.CPU0
375 * \_SB.SCK1.CPU0
376 * Rename the processor device bus id. And the new bus id will be
377 * generated as the following format:
378 * CPU+CPU ID.
379 */
380 sprintf(acpi_device_bid(device), "CPU%X", pr->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
Len Brown4be44fc2005-08-05 00:44:28 -0400382 pr->acpi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 if (!object.processor.pblk_address)
385 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
386 else if (object.processor.pblk_length != 6)
Len Brown64684632006-06-26 23:41:38 -0400387 printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n",
388 object.processor.pblk_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 else {
390 pr->throttling.address = object.processor.pblk_address;
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300391 pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
392 pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394 pr->pblk = object.processor.pblk_address;
395
396 /*
397 * We don't care about error returns - we just try to mark
398 * these reserved so that nobody else is confused into thinking
399 * that this region might be unused..
400 *
401 * (In particular, allocating the IO range for Cardbus)
402 */
403 request_region(pr->throttling.address, 6, "ACPI CPU throttle");
404 }
405
Alex Chiangfe086a72008-04-29 15:05:29 -0700406 /*
407 * If ACPI describes a slot number for this CPU, we can use it
408 * ensure we get the right value in the "physical id" field
409 * of /proc/cpuinfo
410 */
411 status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer);
412 if (ACPI_SUCCESS(status))
413 arch_fix_phys_package_id(pr->id, object.integer.value);
414
Patrick Mocheld550d982006-06-27 00:41:40 -0400415 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
Mike Travis706546d2008-06-09 16:22:23 -0700418static DEFINE_PER_CPU(void *, processor_device_array);
Venkatesh Pallipadicd8e2b42005-10-21 19:22:00 -0400419
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000420static void acpi_processor_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000422 struct acpi_processor *pr = acpi_driver_data(device);
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300423 int saved;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400426 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 switch (event) {
429 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300430 saved = pr->performance_platform_limit;
Zhao Yakuid81c45e12009-10-16 09:20:41 +0800431 acpi_processor_ppc_has_changed(pr, 1);
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300432 if (saved == pr->performance_platform_limit)
433 break;
Len Brown14e04fb2007-08-23 15:20:26 -0400434 acpi_bus_generate_proc_event(device, event,
Len Brown4be44fc2005-08-05 00:44:28 -0400435 pr->performance_platform_limit);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800436 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100437 dev_name(&device->dev), event,
Zhang Rui962ce8c2007-08-23 01:24:31 +0800438 pr->performance_platform_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 break;
440 case ACPI_PROCESSOR_NOTIFY_POWER:
441 acpi_processor_cst_has_changed(pr);
Len Brown14e04fb2007-08-23 15:20:26 -0400442 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800443 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100444 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 break;
Luming Yu01854e62007-05-26 22:49:58 +0800446 case ACPI_PROCESSOR_NOTIFY_THROTTLING:
447 acpi_processor_tstate_has_changed(pr);
Len Brown14e04fb2007-08-23 15:20:26 -0400448 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800449 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100450 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 default:
452 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400453 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 break;
455 }
456
Patrick Mocheld550d982006-06-27 00:41:40 -0400457 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
459
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200460static int acpi_cpu_soft_notify(struct notifier_block *nfb,
461 unsigned long action, void *hcpu)
462{
463 unsigned int cpu = (unsigned long)hcpu;
Mike Travis706546d2008-06-09 16:22:23 -0700464 struct acpi_processor *pr = per_cpu(processors, cpu);
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200465
466 if (action == CPU_ONLINE && pr) {
Zhao Yakuid81c45e12009-10-16 09:20:41 +0800467 acpi_processor_ppc_has_changed(pr, 0);
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200468 acpi_processor_cst_has_changed(pr);
469 acpi_processor_tstate_has_changed(pr);
470 }
471 return NOTIFY_OK;
472}
473
474static struct notifier_block acpi_cpu_notifier =
475{
476 .notifier_call = acpi_cpu_soft_notify,
477};
478
Rakib Mullick941b10f2009-11-05 16:51:40 -0500479static int __cpuinit acpi_processor_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Len Brown4be44fc2005-08-05 00:44:28 -0400481 struct acpi_processor *pr = NULL;
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000482 int result = 0;
483 struct sys_device *sysdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Burman Yan36bcbec2006-12-19 12:56:11 -0800485 pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400487 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Yinghai Lueaa95842009-06-06 14:51:36 -0700489 if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) {
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800490 kfree(pr);
491 return -ENOMEM;
492 }
493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 pr->handle = device->handle;
495 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
496 strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700497 device->driver_data = pr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 result = acpi_processor_get_info(device);
500 if (result) {
501 /* Processor is physically not present */
502 return 0;
503 }
504
Thomas Renninger75cbfb92010-05-26 17:03:33 +0200505#ifdef CONFIG_SMP
506 if (pr->id >= setup_max_cpus && pr->id != 0)
507 return 0;
508#endif
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
511
512 /*
513 * Buggy BIOS check
514 * ACPI id of processors can be reported wrongly by the BIOS.
515 * Don't trust it blindly
516 */
517 if (per_cpu(processor_device_array, pr->id) != NULL &&
518 per_cpu(processor_device_array, pr->id) != device) {
519 printk(KERN_WARNING "BIOS reported wrong ACPI id "
520 "for the processor\n");
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000521 result = -ENODEV;
522 goto err_free_cpumask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
524 per_cpu(processor_device_array, pr->id) = device;
525
526 per_cpu(processors, pr->id) = pr;
527
528 result = acpi_processor_add_fs(device);
529 if (result)
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000530 goto err_free_cpumask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532 sysdev = get_cpu_sysdev(pr->id);
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000533 if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) {
534 result = -EFAULT;
535 goto err_remove_fs;
536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538#ifdef CONFIG_CPU_FREQ
Zhao Yakuid81c45e12009-10-16 09:20:41 +0800539 acpi_processor_ppc_has_changed(pr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540#endif
541 acpi_processor_get_throttling_info(pr);
542 acpi_processor_get_limit_info(pr);
543
544
Len Brown541adf72010-05-22 17:03:29 -0400545 if (cpuidle_get_driver() == &acpi_idle_driver)
546 acpi_processor_power_init(pr, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 pr->cdev = thermal_cooling_device_register("Processor", device,
549 &processor_cooling_ops);
550 if (IS_ERR(pr->cdev)) {
551 result = PTR_ERR(pr->cdev);
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000552 goto err_power_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 }
554
Mike Travis13c41152009-12-14 13:38:30 -0800555 dev_dbg(&device->dev, "registered as cooling_device%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 pr->cdev->id);
557
558 result = sysfs_create_link(&device->dev.kobj,
559 &pr->cdev->device.kobj,
560 "thermal_cooling");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000561 if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 printk(KERN_ERR PREFIX "Create sysfs link\n");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000563 goto err_thermal_unregister;
564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 result = sysfs_create_link(&pr->cdev->device.kobj,
566 &device->dev.kobj,
567 "device");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000568 if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 printk(KERN_ERR PREFIX "Create sysfs link\n");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000570 goto err_remove_sysfs;
571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Patrick Mocheld550d982006-06-27 00:41:40 -0400573 return 0;
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000574
575err_remove_sysfs:
576 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
577err_thermal_unregister:
578 thermal_cooling_device_unregister(pr->cdev);
579err_power_exit:
580 acpi_processor_power_exit(pr, device);
581err_remove_fs:
582 acpi_processor_remove_fs(device);
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000583err_free_cpumask:
584 free_cpumask_var(pr->throttling.shared_cpu_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
588
Len Brown4be44fc2005-08-05 00:44:28 -0400589static int acpi_processor_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590{
Len Brown4be44fc2005-08-05 00:44:28 -0400591 struct acpi_processor *pr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
594 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400595 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200597 pr = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800599 if (pr->id >= nr_cpu_ids)
600 goto free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 if (type == ACPI_BUS_REMOVAL_EJECT) {
603 if (acpi_processor_handle_eject(pr))
Patrick Mocheld550d982006-06-27 00:41:40 -0400604 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
606
607 acpi_processor_power_exit(pr, device);
608
Zhang Rui9f1eb992008-04-29 02:36:07 -0400609 sysfs_remove_link(&device->dev.kobj, "sysdev");
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 acpi_processor_remove_fs(device);
612
Zhao Yakuif28bb452008-02-15 08:34:37 +0800613 if (pr->cdev) {
614 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
615 sysfs_remove_link(&pr->cdev->device.kobj, "device");
616 thermal_cooling_device_unregister(pr->cdev);
617 pr->cdev = NULL;
618 }
Zhang Ruid9460fd222008-01-17 15:51:23 +0800619
Mike Travis706546d2008-06-09 16:22:23 -0700620 per_cpu(processors, pr->id) = NULL;
621 per_cpu(processor_device_array, pr->id) = NULL;
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800622
623free:
624 free_cpumask_var(pr->throttling.shared_cpu_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 kfree(pr);
626
Patrick Mocheld550d982006-06-27 00:41:40 -0400627 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628}
629
630#ifdef CONFIG_ACPI_HOTPLUG_CPU
631/****************************************************************************
632 * Acpi processor hotplug support *
633 ****************************************************************************/
634
Len Brown4be44fc2005-08-05 00:44:28 -0400635static int is_processor_present(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636{
Len Brown4be44fc2005-08-05 00:44:28 -0400637 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400638 unsigned long long sta = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
Zhang Ruicfaf3742008-01-09 02:17:47 -0500642
643 if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
644 return 1;
645
Zhang Ruid0ce46f2008-02-23 01:53:09 -0500646 /*
647 * _STA is mandatory for a processor that supports hot plug
648 */
649 if (status == AE_NOT_FOUND)
650 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
651 "Processor does not support hot plug\n"));
652 else
653 ACPI_EXCEPTION((AE_INFO, status,
654 "Processor Device is not present"));
Zhang Ruicfaf3742008-01-09 02:17:47 -0500655 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656}
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658static
Len Brown4be44fc2005-08-05 00:44:28 -0400659int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
Len Brown4be44fc2005-08-05 00:44:28 -0400661 acpi_handle phandle;
662 struct acpi_device *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
665 if (acpi_get_parent(handle, &phandle)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400666 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 }
668
669 if (acpi_bus_get_device(phandle, &pdev)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400670 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
672
673 if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400674 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 }
676
Patrick Mocheld550d982006-06-27 00:41:40 -0400677 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
Sam Ravnborgb95e9e82008-02-17 13:22:48 +0100680static void __ref acpi_processor_hotplug_notify(acpi_handle handle,
681 u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
Len Brown4be44fc2005-08-05 00:44:28 -0400683 struct acpi_processor *pr;
684 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 int result;
686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688 switch (event) {
689 case ACPI_NOTIFY_BUS_CHECK:
690 case ACPI_NOTIFY_DEVICE_CHECK:
Glauber Costad6f882e2008-03-04 15:06:36 -0800691 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
692 "Processor driver received %s event\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400693 (event == ACPI_NOTIFY_BUS_CHECK) ?
Glauber Costad6f882e2008-03-04 15:06:36 -0800694 "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696 if (!is_processor_present(handle))
697 break;
698
699 if (acpi_bus_get_device(handle, &device)) {
700 result = acpi_processor_device_add(handle, &device);
701 if (result)
Len Brown64684632006-06-26 23:41:38 -0400702 printk(KERN_ERR PREFIX
703 "Unable to add the device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 break;
705 }
Len Brown4be44fc2005-08-05 00:44:28 -0400706 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 case ACPI_NOTIFY_EJECT_REQUEST:
Len Brown4be44fc2005-08-05 00:44:28 -0400708 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
709 "received ACPI_NOTIFY_EJECT_REQUEST\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
711 if (acpi_bus_get_device(handle, &device)) {
Len Brown64684632006-06-26 23:41:38 -0400712 printk(KERN_ERR PREFIX
713 "Device don't exist, dropping EJECT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 break;
715 }
716 pr = acpi_driver_data(device);
717 if (!pr) {
Len Brown64684632006-06-26 23:41:38 -0400718 printk(KERN_ERR PREFIX
719 "Driver data is NULL, dropping EJECT\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400720 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 break;
723 default:
724 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400725 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 break;
727 }
728
Patrick Mocheld550d982006-06-27 00:41:40 -0400729 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730}
731
732static acpi_status
733processor_walk_namespace_cb(acpi_handle handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400734 u32 lvl, void *context, void **rv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Len Brown4be44fc2005-08-05 00:44:28 -0400736 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 int *action = context;
Len Brown4be44fc2005-08-05 00:44:28 -0400738 acpi_object_type type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 status = acpi_get_type(handle, &type);
741 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400742 return (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
744 if (type != ACPI_TYPE_PROCESSOR)
Len Brown4be44fc2005-08-05 00:44:28 -0400745 return (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Len Brown4be44fc2005-08-05 00:44:28 -0400747 switch (*action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 case INSTALL_NOTIFY_HANDLER:
749 acpi_install_notify_handler(handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400750 ACPI_SYSTEM_NOTIFY,
751 acpi_processor_hotplug_notify,
752 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 break;
754 case UNINSTALL_NOTIFY_HANDLER:
755 acpi_remove_notify_handler(handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400756 ACPI_SYSTEM_NOTIFY,
757 acpi_processor_hotplug_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 break;
759 default:
760 break;
761 }
762
Len Brown4be44fc2005-08-05 00:44:28 -0400763 return (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764}
765
Len Brown4be44fc2005-08-05 00:44:28 -0400766static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 if (!is_processor_present(handle)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400770 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 }
772
773 if (acpi_map_lsapic(handle, p_cpu))
Patrick Mocheld550d982006-06-27 00:41:40 -0400774 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 if (arch_register_cpu(*p_cpu)) {
777 acpi_unmap_lsapic(*p_cpu);
Patrick Mocheld550d982006-06-27 00:41:40 -0400778 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 }
780
Patrick Mocheld550d982006-06-27 00:41:40 -0400781 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782}
783
Len Brown4be44fc2005-08-05 00:44:28 -0400784static int acpi_processor_handle_eject(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
Zhang Ruib62b8ef2008-04-29 02:35:56 -0400786 if (cpu_online(pr->id))
787 cpu_down(pr->id);
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 arch_unregister_cpu(pr->id);
790 acpi_unmap_lsapic(pr->id);
Len Brown4be44fc2005-08-05 00:44:28 -0400791 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792}
793#else
Len Brown4be44fc2005-08-05 00:44:28 -0400794static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795{
796 return AE_ERROR;
797}
Len Brown4be44fc2005-08-05 00:44:28 -0400798static int acpi_processor_handle_eject(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
Len Brown4be44fc2005-08-05 00:44:28 -0400800 return (-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801}
802#endif
803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804static
805void acpi_processor_install_hotplug_notify(void)
806{
807#ifdef CONFIG_ACPI_HOTPLUG_CPU
808 int action = INSTALL_NOTIFY_HANDLER;
809 acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
Len Brown4be44fc2005-08-05 00:44:28 -0400810 ACPI_ROOT_OBJECT,
811 ACPI_UINT32_MAX,
Lin Ming22635762009-11-13 10:06:08 +0800812 processor_walk_namespace_cb, NULL, &action, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813#endif
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200814 register_hotcpu_notifier(&acpi_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815}
816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817static
818void acpi_processor_uninstall_hotplug_notify(void)
819{
820#ifdef CONFIG_ACPI_HOTPLUG_CPU
821 int action = UNINSTALL_NOTIFY_HANDLER;
822 acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
Len Brown4be44fc2005-08-05 00:44:28 -0400823 ACPI_ROOT_OBJECT,
824 ACPI_UINT32_MAX,
Lin Ming22635762009-11-13 10:06:08 +0800825 processor_walk_namespace_cb, NULL, &action, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826#endif
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200827 unregister_hotcpu_notifier(&acpi_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828}
829
830/*
831 * We keep the driver loaded even when ACPI is not running.
832 * This is needed for the powernow-k8 driver, that works even without
833 * ACPI, but needs symbols from this driver
834 */
835
Len Brown4be44fc2005-08-05 00:44:28 -0400836static int __init acpi_processor_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
Len Brown4be44fc2005-08-05 00:44:28 -0400838 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Yinghai Luce8442b2009-08-26 14:29:26 -0700840 if (acpi_disabled)
841 return 0;
842
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 memset(&errata, 0, sizeof(errata));
844
845 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
846 if (!acpi_processor_dir)
Akinobu Mita83822fc2006-12-19 12:56:10 -0800847 return -ENOMEM;
Len Brown541adf72010-05-22 17:03:29 -0400848
Len Brown26717172010-03-08 14:07:30 -0500849 if (!cpuidle_register_driver(&acpi_idle_driver)) {
Len Brown541adf72010-05-22 17:03:29 -0400850 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
851 acpi_idle_driver.name);
Len Brown26717172010-03-08 14:07:30 -0500852 } else {
853 printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s",
854 cpuidle_get_driver()->name);
855 }
Len Brown4f86d3a2007-10-03 18:58:00 -0400856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 result = acpi_bus_register_driver(&acpi_processor_driver);
Len Brown4f86d3a2007-10-03 18:58:00 -0400858 if (result < 0)
859 goto out_cpuidle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
861 acpi_processor_install_hotplug_notify();
862
863 acpi_thermal_cpufreq_init();
864
865 acpi_processor_ppc_init();
866
Zhao Yakui11805092008-01-28 13:53:42 +0800867 acpi_processor_throttling_init();
868
Patrick Mocheld550d982006-06-27 00:41:40 -0400869 return 0;
Len Brown4f86d3a2007-10-03 18:58:00 -0400870
871out_cpuidle:
872 cpuidle_unregister_driver(&acpi_idle_driver);
873
Len Brown4f86d3a2007-10-03 18:58:00 -0400874 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
875
876 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877}
878
Len Brown4be44fc2005-08-05 00:44:28 -0400879static void __exit acpi_processor_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880{
Yinghai Luce8442b2009-08-26 14:29:26 -0700881 if (acpi_disabled)
882 return;
883
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 acpi_processor_ppc_exit();
885
886 acpi_thermal_cpufreq_exit();
887
888 acpi_processor_uninstall_hotplug_notify();
889
890 acpi_bus_unregister_driver(&acpi_processor_driver);
891
Len Brown4f86d3a2007-10-03 18:58:00 -0400892 cpuidle_unregister_driver(&acpi_idle_driver);
893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
895
Patrick Mocheld550d982006-06-27 00:41:40 -0400896 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897}
898
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899module_init(acpi_processor_init);
900module_exit(acpi_processor_exit);
901
902EXPORT_SYMBOL(acpi_processor_set_thermal_limit);
903
904MODULE_ALIAS("processor");