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