blob: 38ea0cc6dc49aba88b53a503107d144fcebe992b [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);
Zhao Yakui74cad4e2009-06-24 11:49:49 +080086#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static int acpi_processor_info_open_fs(struct inode *inode, struct file *file);
Zhao Yakui74cad4e2009-06-24 11:49:49 +080088#endif
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +000089static void acpi_processor_notify(struct acpi_device *device, u32 event);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
91static int acpi_processor_handle_eject(struct acpi_processor *pr);
Luming Yu01854e62007-05-26 22:49:58 +080092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Thomas Renninger1ba90e32007-07-23 14:44:41 +020094static const struct acpi_device_id processor_device_ids[] = {
Myron Stowead93a762008-11-04 14:52:55 -070095 {ACPI_PROCESSOR_OBJECT_HID, 0},
Bjorn Helgaas9eccbc22009-04-27 16:33:46 -060096 {"ACPI0007", 0},
Thomas Renninger1ba90e32007-07-23 14:44:41 +020097 {"", 0},
98};
99MODULE_DEVICE_TABLE(acpi, processor_device_ids);
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static struct acpi_driver acpi_processor_driver = {
Len Brownc2b6705b2007-02-12 23:33:40 -0500102 .name = "processor",
Len Brown4be44fc2005-08-05 00:44:28 -0400103 .class = ACPI_PROCESSOR_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200104 .ids = processor_device_ids,
Len Brown4be44fc2005-08-05 00:44:28 -0400105 .ops = {
106 .add = acpi_processor_add,
107 .remove = acpi_processor_remove,
Thomas Gleixnerb04e7bd2007-09-22 22:29:05 +0000108 .suspend = acpi_processor_suspend,
109 .resume = acpi_processor_resume,
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000110 .notify = acpi_processor_notify,
Len Brown4be44fc2005-08-05 00:44:28 -0400111 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112};
113
114#define INSTALL_NOTIFY_HANDLER 1
115#define UNINSTALL_NOTIFY_HANDLER 2
Zhao Yakui74cad4e2009-06-24 11:49:49 +0800116#ifdef CONFIG_ACPI_PROCFS
Arjan van de Vend7508032006-07-04 13:06:00 -0400117static const struct file_operations acpi_processor_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700118 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400119 .open = acpi_processor_info_open_fs,
120 .read = seq_read,
121 .llseek = seq_lseek,
122 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123};
Zhao Yakui74cad4e2009-06-24 11:49:49 +0800124#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Mike Travis706546d2008-06-09 16:22:23 -0700126DEFINE_PER_CPU(struct acpi_processor *, processors);
Naga Chumbalkar0f1d6832009-12-17 20:18:27 +0000127EXPORT_PER_CPU_SYMBOL(processors);
128
Andreas Mohr9f222712006-06-23 02:04:27 -0700129struct acpi_processor_errata errata __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/* --------------------------------------------------------------------------
132 Errata Handling
133 -------------------------------------------------------------------------- */
134
Len Brown4be44fc2005-08-05 00:44:28 -0400135static int acpi_processor_errata_piix4(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Len Brown4be44fc2005-08-05 00:44:28 -0400137 u8 value1 = 0;
138 u8 value2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400142 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /*
145 * Note that 'dev' references the PIIX4 ACPI Controller.
146 */
147
Auke Kok44c10132007-06-08 15:46:36 -0700148 switch (dev->revision) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 case 0:
150 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
151 break;
152 case 1:
153 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n"));
154 break;
155 case 2:
156 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n"));
157 break;
158 case 3:
159 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n"));
160 break;
161 default:
162 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n"));
163 break;
164 }
165
Auke Kok44c10132007-06-08 15:46:36 -0700166 switch (dev->revision) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 case 0: /* PIIX4 A-step */
169 case 1: /* PIIX4 B-step */
170 /*
171 * See specification changes #13 ("Manual Throttle Duty Cycle")
172 * and #14 ("Enabling and Disabling Manual Throttle"), plus
173 * erratum #5 ("STPCLK# Deassertion Time") from the January
174 * 2002 PIIX4 specification update. Applies to only older
175 * PIIX4 models.
176 */
177 errata.piix4.throttle = 1;
178
179 case 2: /* PIIX4E */
180 case 3: /* PIIX4M */
181 /*
182 * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
183 * Livelock") from the January 2002 PIIX4 specification update.
184 * Applies to all PIIX4 models.
185 */
186
187 /*
188 * BM-IDE
189 * ------
190 * Find the PIIX4 IDE Controller and get the Bus Master IDE
191 * Status register address. We'll use this later to read
192 * each IDE controller's DMA status to make sure we catch all
193 * DMA activity.
194 */
195 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
Len Brown4be44fc2005-08-05 00:44:28 -0400196 PCI_DEVICE_ID_INTEL_82371AB,
197 PCI_ANY_ID, PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 if (dev) {
199 errata.piix4.bmisx = pci_resource_start(dev, 4);
200 pci_dev_put(dev);
201 }
202
203 /*
204 * Type-F DMA
205 * ----------
206 * Find the PIIX4 ISA Controller and read the Motherboard
207 * DMA controller's status to see if Type-F (Fast) DMA mode
208 * is enabled (bit 7) on either channel. Note that we'll
209 * disable C3 support if this is enabled, as some legacy
210 * devices won't operate well if fast DMA is disabled.
211 */
212 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
Len Brown4be44fc2005-08-05 00:44:28 -0400213 PCI_DEVICE_ID_INTEL_82371AB_0,
214 PCI_ANY_ID, PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 if (dev) {
216 pci_read_config_byte(dev, 0x76, &value1);
217 pci_read_config_byte(dev, 0x77, &value2);
218 if ((value1 & 0x80) || (value2 & 0x80))
219 errata.piix4.fdma = 1;
220 pci_dev_put(dev);
221 }
222
223 break;
224 }
225
226 if (errata.piix4.bmisx)
227 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400228 "Bus master activity detection (BM-IDE) erratum enabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 if (errata.piix4.fdma)
230 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400231 "Type-F DMA livelock erratum (C3 disabled)\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Patrick Mocheld550d982006-06-27 00:41:40 -0400233 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235
Adrian Bunk8713cbe2005-09-02 17:16:48 -0400236static int acpi_processor_errata(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
Len Brown4be44fc2005-08-05 00:44:28 -0400238 int result = 0;
239 struct pci_dev *dev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400243 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 /*
246 * PIIX4
247 */
248 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
Len Brown4be44fc2005-08-05 00:44:28 -0400249 PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
250 PCI_ANY_ID, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 if (dev) {
252 result = acpi_processor_errata_piix4(dev);
253 pci_dev_put(dev);
254 }
255
Patrick Mocheld550d982006-06-27 00:41:40 -0400256 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259/* --------------------------------------------------------------------------
260 FS Interface (/proc)
261 -------------------------------------------------------------------------- */
262
Zhao Yakui74cad4e2009-06-24 11:49:49 +0800263#ifdef CONFIG_ACPI_PROCFS
Len Brown4be44fc2005-08-05 00:44:28 -0400264static struct proc_dir_entry *acpi_processor_dir = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
266static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset)
267{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200268 struct acpi_processor *pr = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271 if (!pr)
272 goto end;
273
274 seq_printf(seq, "processor id: %d\n"
Len Brown4be44fc2005-08-05 00:44:28 -0400275 "acpi id: %d\n"
276 "bus mastering control: %s\n"
277 "power management: %s\n"
278 "throttling control: %s\n"
279 "limit interface: %s\n",
280 pr->id,
281 pr->acpi_id,
282 pr->flags.bm_control ? "yes" : "no",
283 pr->flags.power ? "yes" : "no",
284 pr->flags.throttling ? "yes" : "no",
285 pr->flags.limit ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Len Brown4be44fc2005-08-05 00:44:28 -0400287 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400288 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289}
290
291static int acpi_processor_info_open_fs(struct inode *inode, struct file *file)
292{
293 return single_open(file, acpi_processor_info_seq_show,
Len Brown4be44fc2005-08-05 00:44:28 -0400294 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
Thomas Renningerbf8b4542009-10-26 17:44:18 +0100297static int __cpuinit acpi_processor_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Len Brown4be44fc2005-08-05 00:44:28 -0400299 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 if (!acpi_device_dir(device)) {
303 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400304 acpi_processor_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400306 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 /* 'info' [R] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700310 entry = proc_create_data(ACPI_PROCESSOR_FILE_INFO,
311 S_IRUGO, acpi_device_dir(device),
312 &acpi_processor_info_fops,
313 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400315 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 /* 'throttling' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700318 entry = proc_create_data(ACPI_PROCESSOR_FILE_THROTTLING,
319 S_IFREG | S_IRUGO | S_IWUSR,
320 acpi_device_dir(device),
321 &acpi_processor_throttling_fops,
322 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400324 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 /* 'limit' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700327 entry = proc_create_data(ACPI_PROCESSOR_FILE_LIMIT,
328 S_IFREG | S_IRUGO | S_IWUSR,
329 acpi_device_dir(device),
330 &acpi_processor_limit_fops,
331 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400333 return -EIO;
Patrick Mocheld550d982006-06-27 00:41:40 -0400334 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
Len Brown4be44fc2005-08-05 00:44:28 -0400336static int acpi_processor_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 if (acpi_device_dir(device)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400340 remove_proc_entry(ACPI_PROCESSOR_FILE_INFO,
341 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
Len Brown4be44fc2005-08-05 00:44:28 -0400343 acpi_device_dir(device));
344 remove_proc_entry(ACPI_PROCESSOR_FILE_LIMIT,
345 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 remove_proc_entry(acpi_device_bid(device), acpi_processor_dir);
347 acpi_device_dir(device) = NULL;
348 }
349
Patrick Mocheld550d982006-06-27 00:41:40 -0400350 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
Zhao Yakui74cad4e2009-06-24 11:49:49 +0800352#else
353static inline int acpi_processor_add_fs(struct acpi_device *device)
354{
355 return 0;
356}
357static inline int acpi_processor_remove_fs(struct acpi_device *device)
358{
359 return 0;
360}
361#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363/* --------------------------------------------------------------------------
364 Driver Interface
365 -------------------------------------------------------------------------- */
366
Myron Stoweb26e9282008-11-04 14:53:00 -0700367static int acpi_processor_get_info(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Len Brown4be44fc2005-08-05 00:44:28 -0400369 acpi_status status = 0;
370 union acpi_object object = { 0 };
371 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
Myron Stoweb26e9282008-11-04 14:53:00 -0700372 struct acpi_processor *pr;
373 int cpu_index, device_declaration = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400374 static int cpu0_initialized;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Myron Stoweb26e9282008-11-04 14:53:00 -0700376 pr = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400378 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
380 if (num_online_cpus() > 1)
381 errata.smp = TRUE;
382
383 acpi_processor_errata(pr);
384
385 /*
386 * Check to see if we have bus mastering arbitration control. This
387 * is required for proper C3 usage (to maintain cache coherency).
388 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300389 if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 pr->flags.bm_control = 1;
391 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400392 "Bus mastering arbitration control present\n"));
393 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400395 "No bus mastering arbitration control\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Bjorn Helgaas6cc73b42009-04-27 16:33:41 -0600397 if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) {
398 /* Declared with "Processor" statement; match ProcessorID */
399 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
400 if (ACPI_FAILURE(status)) {
401 printk(KERN_ERR PREFIX "Evaluating processor object\n");
402 return -ENODEV;
403 }
404
405 /*
406 * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
407 * >>> 'acpi_get_processor_id(acpi_id, &id)' in
408 * arch/xxx/acpi.c
409 */
410 pr->acpi_id = object.processor.proc_id;
411 } else {
Myron Stoweb26e9282008-11-04 14:53:00 -0700412 /*
413 * Declared with "Device" statement; match _UID.
414 * Note that we don't handle string _UIDs yet.
415 */
Matthew Wilcox27663c52008-10-10 02:22:59 -0400416 unsigned long long value;
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300417 status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
418 NULL, &value);
419 if (ACPI_FAILURE(status)) {
Myron Stoweb26e9282008-11-04 14:53:00 -0700420 printk(KERN_ERR PREFIX
421 "Evaluating processor _UID [%#x]\n", status);
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300422 return -ENODEV;
423 }
Myron Stoweb26e9282008-11-04 14:53:00 -0700424 device_declaration = 1;
Alexey Starikovskiy11bf04c2007-02-02 19:48:23 +0300425 pr->acpi_id = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
Alex Chiang2e9d5e42010-02-22 12:11:19 -0700427 cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Len Brown4be44fc2005-08-05 00:44:28 -0400429 /* Handle UP system running SMP kernel, with no LAPIC in MADT */
Ashok Rajdf42baa2006-03-28 17:04:00 -0500430 if (!cpu0_initialized && (cpu_index == -1) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400431 (num_online_cpus() == 1)) {
432 cpu_index = 0;
433 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Len Brown4be44fc2005-08-05 00:44:28 -0400435 cpu0_initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Len Brown4be44fc2005-08-05 00:44:28 -0400437 pr->id = cpu_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Len Brown4be44fc2005-08-05 00:44:28 -0400439 /*
440 * Extra Processor objects may be enumerated on MP systems with
441 * less than the max # of CPUs. They should be ignored _iff
442 * they are physically not present.
443 */
Alexey Starikovskiyf18c5a02007-02-02 19:48:23 +0300444 if (pr->id == -1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400445 if (ACPI_FAILURE
446 (acpi_processor_hotadd_init(pr->handle, &pr->id))) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400447 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400448 }
449 }
Zhao Yakui7a04b842009-06-24 11:46:44 +0800450 /*
451 * On some boxes several processors use the same processor bus id.
452 * But they are located in different scope. For example:
453 * \_SB.SCK0.CPU0
454 * \_SB.SCK1.CPU0
455 * Rename the processor device bus id. And the new bus id will be
456 * generated as the following format:
457 * CPU+CPU ID.
458 */
459 sprintf(acpi_device_bid(device), "CPU%X", pr->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
Len Brown4be44fc2005-08-05 00:44:28 -0400461 pr->acpi_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 if (!object.processor.pblk_address)
464 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
465 else if (object.processor.pblk_length != 6)
Len Brown64684632006-06-26 23:41:38 -0400466 printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n",
467 object.processor.pblk_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 else {
469 pr->throttling.address = object.processor.pblk_address;
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300470 pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
471 pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
473 pr->pblk = object.processor.pblk_address;
474
475 /*
476 * We don't care about error returns - we just try to mark
477 * these reserved so that nobody else is confused into thinking
478 * that this region might be unused..
479 *
480 * (In particular, allocating the IO range for Cardbus)
481 */
482 request_region(pr->throttling.address, 6, "ACPI CPU throttle");
483 }
484
Alex Chiangfe086a72008-04-29 15:05:29 -0700485 /*
486 * If ACPI describes a slot number for this CPU, we can use it
487 * ensure we get the right value in the "physical id" field
488 * of /proc/cpuinfo
489 */
490 status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer);
491 if (ACPI_SUCCESS(status))
492 arch_fix_phys_package_id(pr->id, object.integer.value);
493
Patrick Mocheld550d982006-06-27 00:41:40 -0400494 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495}
496
Mike Travis706546d2008-06-09 16:22:23 -0700497static DEFINE_PER_CPU(void *, processor_device_array);
Venkatesh Pallipadicd8e2b42005-10-21 19:22:00 -0400498
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000499static void acpi_processor_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Bjorn Helgaas7ec0a722009-03-30 17:48:24 +0000501 struct acpi_processor *pr = acpi_driver_data(device);
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300502 int saved;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400505 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 switch (event) {
508 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300509 saved = pr->performance_platform_limit;
Zhao Yakuid81c45e2009-10-16 09:20:41 +0800510 acpi_processor_ppc_has_changed(pr, 1);
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300511 if (saved == pr->performance_platform_limit)
512 break;
Len Brown14e04fb2007-08-23 15:20:26 -0400513 acpi_bus_generate_proc_event(device, event,
Len Brown4be44fc2005-08-05 00:44:28 -0400514 pr->performance_platform_limit);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800515 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100516 dev_name(&device->dev), event,
Zhang Rui962ce8c2007-08-23 01:24:31 +0800517 pr->performance_platform_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 break;
519 case ACPI_PROCESSOR_NOTIFY_POWER:
520 acpi_processor_cst_has_changed(pr);
Len Brown14e04fb2007-08-23 15:20:26 -0400521 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800522 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100523 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 break;
Luming Yu01854e62007-05-26 22:49:58 +0800525 case ACPI_PROCESSOR_NOTIFY_THROTTLING:
526 acpi_processor_tstate_has_changed(pr);
Len Brown14e04fb2007-08-23 15:20:26 -0400527 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800528 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100529 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 default:
531 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400532 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 break;
534 }
535
Patrick Mocheld550d982006-06-27 00:41:40 -0400536 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200539static int acpi_cpu_soft_notify(struct notifier_block *nfb,
540 unsigned long action, void *hcpu)
541{
542 unsigned int cpu = (unsigned long)hcpu;
Mike Travis706546d2008-06-09 16:22:23 -0700543 struct acpi_processor *pr = per_cpu(processors, cpu);
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200544
545 if (action == CPU_ONLINE && pr) {
Zhao Yakuid81c45e2009-10-16 09:20:41 +0800546 acpi_processor_ppc_has_changed(pr, 0);
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200547 acpi_processor_cst_has_changed(pr);
548 acpi_processor_tstate_has_changed(pr);
549 }
550 return NOTIFY_OK;
551}
552
553static struct notifier_block acpi_cpu_notifier =
554{
555 .notifier_call = acpi_cpu_soft_notify,
556};
557
Rakib Mullick941b10f2009-11-05 16:51:40 -0500558static int __cpuinit acpi_processor_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559{
Len Brown4be44fc2005-08-05 00:44:28 -0400560 struct acpi_processor *pr = NULL;
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000561 int result = 0;
562 struct sys_device *sysdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Burman Yan36bcbec2006-12-19 12:56:11 -0800564 pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400566 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Yinghai Lueaa95842009-06-06 14:51:36 -0700568 if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) {
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800569 kfree(pr);
570 return -ENOMEM;
571 }
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 pr->handle = device->handle;
574 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
575 strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700576 device->driver_data = pr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 result = acpi_processor_get_info(device);
579 if (result) {
580 /* Processor is physically not present */
581 return 0;
582 }
583
Thomas Renninger75cbfb92010-05-26 17:03:33 +0200584#ifdef CONFIG_SMP
585 if (pr->id >= setup_max_cpus && pr->id != 0)
586 return 0;
587#endif
588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
590
591 /*
592 * Buggy BIOS check
593 * ACPI id of processors can be reported wrongly by the BIOS.
594 * Don't trust it blindly
595 */
596 if (per_cpu(processor_device_array, pr->id) != NULL &&
597 per_cpu(processor_device_array, pr->id) != device) {
598 printk(KERN_WARNING "BIOS reported wrong ACPI id "
599 "for the processor\n");
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000600 result = -ENODEV;
601 goto err_free_cpumask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 }
603 per_cpu(processor_device_array, pr->id) = device;
604
605 per_cpu(processors, pr->id) = pr;
606
607 result = acpi_processor_add_fs(device);
608 if (result)
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000609 goto err_free_cpumask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 sysdev = get_cpu_sysdev(pr->id);
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000612 if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) {
613 result = -EFAULT;
614 goto err_remove_fs;
615 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#ifdef CONFIG_CPU_FREQ
Zhao Yakuid81c45e2009-10-16 09:20:41 +0800618 acpi_processor_ppc_has_changed(pr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#endif
620 acpi_processor_get_throttling_info(pr);
621 acpi_processor_get_limit_info(pr);
622
623
Len Brown541adf72010-05-22 17:03:29 -0400624 if (cpuidle_get_driver() == &acpi_idle_driver)
625 acpi_processor_power_init(pr, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 pr->cdev = thermal_cooling_device_register("Processor", device,
628 &processor_cooling_ops);
629 if (IS_ERR(pr->cdev)) {
630 result = PTR_ERR(pr->cdev);
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000631 goto err_power_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 }
633
Mike Travis13c41152009-12-14 13:38:30 -0800634 dev_dbg(&device->dev, "registered as cooling_device%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 pr->cdev->id);
636
637 result = sysfs_create_link(&device->dev.kobj,
638 &pr->cdev->device.kobj,
639 "thermal_cooling");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000640 if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 printk(KERN_ERR PREFIX "Create sysfs link\n");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000642 goto err_thermal_unregister;
643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 result = sysfs_create_link(&pr->cdev->device.kobj,
645 &device->dev.kobj,
646 "device");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000647 if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 printk(KERN_ERR PREFIX "Create sysfs link\n");
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000649 goto err_remove_sysfs;
650 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Patrick Mocheld550d982006-06-27 00:41:40 -0400652 return 0;
Bjorn Helgaasd4e05262009-06-22 20:41:09 +0000653
654err_remove_sysfs:
655 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
656err_thermal_unregister:
657 thermal_cooling_device_unregister(pr->cdev);
658err_power_exit:
659 acpi_processor_power_exit(pr, device);
660err_remove_fs:
661 acpi_processor_remove_fs(device);
Bjorn Helgaas970b0492009-06-22 20:41:19 +0000662err_free_cpumask:
663 free_cpumask_var(pr->throttling.shared_cpu_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
665 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
Len Brown4be44fc2005-08-05 00:44:28 -0400668static int acpi_processor_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669{
Len Brown4be44fc2005-08-05 00:44:28 -0400670 struct acpi_processor *pr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400674 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200676 pr = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800678 if (pr->id >= nr_cpu_ids)
679 goto free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
681 if (type == ACPI_BUS_REMOVAL_EJECT) {
682 if (acpi_processor_handle_eject(pr))
Patrick Mocheld550d982006-06-27 00:41:40 -0400683 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685
686 acpi_processor_power_exit(pr, device);
687
Zhang Rui9f1eb992008-04-29 02:36:07 -0400688 sysfs_remove_link(&device->dev.kobj, "sysdev");
689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 acpi_processor_remove_fs(device);
691
Zhao Yakuif28bb452008-02-15 08:34:37 +0800692 if (pr->cdev) {
693 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
694 sysfs_remove_link(&pr->cdev->device.kobj, "device");
695 thermal_cooling_device_unregister(pr->cdev);
696 pr->cdev = NULL;
697 }
Zhang Ruid9460fd22008-01-17 15:51:23 +0800698
Mike Travis706546d2008-06-09 16:22:23 -0700699 per_cpu(processors, pr->id) = NULL;
700 per_cpu(processor_device_array, pr->id) = NULL;
Rusty Russell2fdf66b2008-12-31 18:08:47 -0800701
702free:
703 free_cpumask_var(pr->throttling.shared_cpu_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 kfree(pr);
705
Patrick Mocheld550d982006-06-27 00:41:40 -0400706 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707}
708
709#ifdef CONFIG_ACPI_HOTPLUG_CPU
710/****************************************************************************
711 * Acpi processor hotplug support *
712 ****************************************************************************/
713
Len Brown4be44fc2005-08-05 00:44:28 -0400714static int is_processor_present(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715{
Len Brown4be44fc2005-08-05 00:44:28 -0400716 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400717 unsigned long long sta = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
Zhang Ruicfaf3742008-01-09 02:17:47 -0500721
722 if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
723 return 1;
724
Zhang Ruid0ce46f2008-02-23 01:53:09 -0500725 /*
726 * _STA is mandatory for a processor that supports hot plug
727 */
728 if (status == AE_NOT_FOUND)
729 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
730 "Processor does not support hot plug\n"));
731 else
732 ACPI_EXCEPTION((AE_INFO, status,
733 "Processor Device is not present"));
Zhang Ruicfaf3742008-01-09 02:17:47 -0500734 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735}
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737static
Len Brown4be44fc2005-08-05 00:44:28 -0400738int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739{
Len Brown4be44fc2005-08-05 00:44:28 -0400740 acpi_handle phandle;
741 struct acpi_device *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
744 if (acpi_get_parent(handle, &phandle)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400745 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 }
747
748 if (acpi_bus_get_device(phandle, &pdev)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400749 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 }
751
752 if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400753 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 }
755
Patrick Mocheld550d982006-06-27 00:41:40 -0400756 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757}
758
Sam Ravnborgb95e9e82008-02-17 13:22:48 +0100759static void __ref acpi_processor_hotplug_notify(acpi_handle handle,
760 u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761{
Len Brown4be44fc2005-08-05 00:44:28 -0400762 struct acpi_processor *pr;
763 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 int result;
765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
767 switch (event) {
768 case ACPI_NOTIFY_BUS_CHECK:
769 case ACPI_NOTIFY_DEVICE_CHECK:
Glauber Costad6f882e2008-03-04 15:06:36 -0800770 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
771 "Processor driver received %s event\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400772 (event == ACPI_NOTIFY_BUS_CHECK) ?
Glauber Costad6f882e2008-03-04 15:06:36 -0800773 "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775 if (!is_processor_present(handle))
776 break;
777
778 if (acpi_bus_get_device(handle, &device)) {
779 result = acpi_processor_device_add(handle, &device);
780 if (result)
Len Brown64684632006-06-26 23:41:38 -0400781 printk(KERN_ERR PREFIX
782 "Unable to add the device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 break;
784 }
Len Brown4be44fc2005-08-05 00:44:28 -0400785 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 case ACPI_NOTIFY_EJECT_REQUEST:
Len Brown4be44fc2005-08-05 00:44:28 -0400787 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
788 "received ACPI_NOTIFY_EJECT_REQUEST\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 if (acpi_bus_get_device(handle, &device)) {
Len Brown64684632006-06-26 23:41:38 -0400791 printk(KERN_ERR PREFIX
792 "Device don't exist, dropping EJECT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 break;
794 }
795 pr = acpi_driver_data(device);
796 if (!pr) {
Len Brown64684632006-06-26 23:41:38 -0400797 printk(KERN_ERR PREFIX
798 "Driver data is NULL, dropping EJECT\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400799 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 break;
802 default:
803 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400804 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 break;
806 }
807
Patrick Mocheld550d982006-06-27 00:41:40 -0400808 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809}
810
811static acpi_status
812processor_walk_namespace_cb(acpi_handle handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400813 u32 lvl, void *context, void **rv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
Len Brown4be44fc2005-08-05 00:44:28 -0400815 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 int *action = context;
Len Brown4be44fc2005-08-05 00:44:28 -0400817 acpi_object_type type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 status = acpi_get_type(handle, &type);
820 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400821 return (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 if (type != ACPI_TYPE_PROCESSOR)
Len Brown4be44fc2005-08-05 00:44:28 -0400824 return (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Len Brown4be44fc2005-08-05 00:44:28 -0400826 switch (*action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 case INSTALL_NOTIFY_HANDLER:
828 acpi_install_notify_handler(handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400829 ACPI_SYSTEM_NOTIFY,
830 acpi_processor_hotplug_notify,
831 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 break;
833 case UNINSTALL_NOTIFY_HANDLER:
834 acpi_remove_notify_handler(handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400835 ACPI_SYSTEM_NOTIFY,
836 acpi_processor_hotplug_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 break;
838 default:
839 break;
840 }
841
Len Brown4be44fc2005-08-05 00:44:28 -0400842 return (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
844
Len Brown4be44fc2005-08-05 00:44:28 -0400845static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 if (!is_processor_present(handle)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400849 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 }
851
852 if (acpi_map_lsapic(handle, p_cpu))
Patrick Mocheld550d982006-06-27 00:41:40 -0400853 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855 if (arch_register_cpu(*p_cpu)) {
856 acpi_unmap_lsapic(*p_cpu);
Patrick Mocheld550d982006-06-27 00:41:40 -0400857 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 }
859
Patrick Mocheld550d982006-06-27 00:41:40 -0400860 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861}
862
Len Brown4be44fc2005-08-05 00:44:28 -0400863static int acpi_processor_handle_eject(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Zhang Ruib62b8ef2008-04-29 02:35:56 -0400865 if (cpu_online(pr->id))
866 cpu_down(pr->id);
867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 arch_unregister_cpu(pr->id);
869 acpi_unmap_lsapic(pr->id);
Len Brown4be44fc2005-08-05 00:44:28 -0400870 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871}
872#else
Len Brown4be44fc2005-08-05 00:44:28 -0400873static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
875 return AE_ERROR;
876}
Len Brown4be44fc2005-08-05 00:44:28 -0400877static int acpi_processor_handle_eject(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
Len Brown4be44fc2005-08-05 00:44:28 -0400879 return (-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880}
881#endif
882
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883static
884void acpi_processor_install_hotplug_notify(void)
885{
886#ifdef CONFIG_ACPI_HOTPLUG_CPU
887 int action = INSTALL_NOTIFY_HANDLER;
888 acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
Len Brown4be44fc2005-08-05 00:44:28 -0400889 ACPI_ROOT_OBJECT,
890 ACPI_UINT32_MAX,
Lin Ming22635762009-11-13 10:06:08 +0800891 processor_walk_namespace_cb, NULL, &action, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892#endif
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200893 register_hotcpu_notifier(&acpi_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896static
897void acpi_processor_uninstall_hotplug_notify(void)
898{
899#ifdef CONFIG_ACPI_HOTPLUG_CPU
900 int action = UNINSTALL_NOTIFY_HANDLER;
901 acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
Len Brown4be44fc2005-08-05 00:44:28 -0400902 ACPI_ROOT_OBJECT,
903 ACPI_UINT32_MAX,
Lin Ming22635762009-11-13 10:06:08 +0800904 processor_walk_namespace_cb, NULL, &action, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905#endif
Venkatesh Pallipadi729c6ba2007-09-16 15:36:43 +0200906 unregister_hotcpu_notifier(&acpi_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907}
908
909/*
910 * We keep the driver loaded even when ACPI is not running.
911 * This is needed for the powernow-k8 driver, that works even without
912 * ACPI, but needs symbols from this driver
913 */
914
Len Brown4be44fc2005-08-05 00:44:28 -0400915static int __init acpi_processor_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916{
Len Brown4be44fc2005-08-05 00:44:28 -0400917 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Yinghai Luce8442b2009-08-26 14:29:26 -0700919 if (acpi_disabled)
920 return 0;
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 memset(&errata, 0, sizeof(errata));
923
Zhao Yakui74cad4e2009-06-24 11:49:49 +0800924#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
926 if (!acpi_processor_dir)
Akinobu Mita83822fc2006-12-19 12:56:10 -0800927 return -ENOMEM;
Zhao Yakui74cad4e2009-06-24 11:49:49 +0800928#endif
Len Brown541adf72010-05-22 17:03:29 -0400929
Len Brown26717172010-03-08 14:07:30 -0500930 if (!cpuidle_register_driver(&acpi_idle_driver)) {
Len Brown541adf72010-05-22 17:03:29 -0400931 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
932 acpi_idle_driver.name);
Len Brown26717172010-03-08 14:07:30 -0500933 } else {
934 printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s",
935 cpuidle_get_driver()->name);
936 }
Len Brown4f86d3a2007-10-03 18:58:00 -0400937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 result = acpi_bus_register_driver(&acpi_processor_driver);
Len Brown4f86d3a2007-10-03 18:58:00 -0400939 if (result < 0)
940 goto out_cpuidle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 acpi_processor_install_hotplug_notify();
943
944 acpi_thermal_cpufreq_init();
945
946 acpi_processor_ppc_init();
947
Zhao Yakui11805092008-01-28 13:53:42 +0800948 acpi_processor_throttling_init();
949
Patrick Mocheld550d982006-06-27 00:41:40 -0400950 return 0;
Len Brown4f86d3a2007-10-03 18:58:00 -0400951
952out_cpuidle:
953 cpuidle_unregister_driver(&acpi_idle_driver);
954
Zhao Yakui74cad4e2009-06-24 11:49:49 +0800955#ifdef CONFIG_ACPI_PROCFS
Len Brown4f86d3a2007-10-03 18:58:00 -0400956 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
Zhao Yakui74cad4e2009-06-24 11:49:49 +0800957#endif
Len Brown4f86d3a2007-10-03 18:58:00 -0400958
959 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960}
961
Len Brown4be44fc2005-08-05 00:44:28 -0400962static void __exit acpi_processor_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963{
Yinghai Luce8442b2009-08-26 14:29:26 -0700964 if (acpi_disabled)
965 return;
966
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 acpi_processor_ppc_exit();
968
969 acpi_thermal_cpufreq_exit();
970
971 acpi_processor_uninstall_hotplug_notify();
972
973 acpi_bus_unregister_driver(&acpi_processor_driver);
974
Len Brown4f86d3a2007-10-03 18:58:00 -0400975 cpuidle_unregister_driver(&acpi_idle_driver);
976
Zhao Yakui74cad4e2009-06-24 11:49:49 +0800977#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
Zhao Yakui74cad4e2009-06-24 11:49:49 +0800979#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Patrick Mocheld550d982006-06-27 00:41:40 -0400981 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982}
983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984module_init(acpi_processor_init);
985module_exit(acpi_processor_exit);
986
987EXPORT_SYMBOL(acpi_processor_set_thermal_limit);
988
989MODULE_ALIAS("processor");