]>
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> | |
43 | #include <linux/proc_fs.h> | |
44 | #include <linux/seq_file.h> | |
45 | #include <linux/dmi.h> | |
46 | #include <linux/moduleparam.h> | |
4f86d3a8 | 47 | #include <linux/cpuidle.h> |
5a0e3ad6 | 48 | #include <linux/slab.h> |
1da177e4 LT |
49 | |
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 | ||
a192a958 LB |
63 | #define PREFIX "ACPI: " |
64 | ||
1da177e4 | 65 | #define ACPI_PROCESSOR_CLASS "processor" |
1da177e4 LT |
66 | #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 | |
01854e69 | 72 | #define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82 |
1da177e4 LT |
73 | |
74 | #define ACPI_PROCESSOR_LIMIT_USER 0 | |
75 | #define ACPI_PROCESSOR_LIMIT_THERMAL 1 | |
76 | ||
1da177e4 | 77 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT |
0131aa3d | 78 | ACPI_MODULE_NAME("processor_driver"); |
1da177e4 | 79 | |
f52fd66d | 80 | MODULE_AUTHOR("Paul Diefenbaugh"); |
7cda93e0 | 81 | MODULE_DESCRIPTION("ACPI Processor Driver"); |
1da177e4 LT |
82 | MODULE_LICENSE("GPL"); |
83 | ||
4be44fcd | 84 | static int acpi_processor_add(struct acpi_device *device); |
4be44fcd | 85 | static int acpi_processor_remove(struct acpi_device *device, int type); |
7ec0a729 | 86 | static void acpi_processor_notify(struct acpi_device *device, u32 event); |
1da177e4 LT |
87 | static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu); |
88 | static int acpi_processor_handle_eject(struct acpi_processor *pr); | |
01854e69 | 89 | |
1da177e4 | 90 | |
1ba90e3a | 91 | static const struct acpi_device_id processor_device_ids[] = { |
ad93a765 | 92 | {ACPI_PROCESSOR_OBJECT_HID, 0}, |
9eccbc2f | 93 | {"ACPI0007", 0}, |
1ba90e3a TR |
94 | {"", 0}, |
95 | }; | |
96 | MODULE_DEVICE_TABLE(acpi, processor_device_ids); | |
97 | ||
1da177e4 | 98 | static struct acpi_driver acpi_processor_driver = { |
c2b6705b | 99 | .name = "processor", |
4be44fcd | 100 | .class = ACPI_PROCESSOR_CLASS, |
1ba90e3a | 101 | .ids = processor_device_ids, |
4be44fcd LB |
102 | .ops = { |
103 | .add = acpi_processor_add, | |
104 | .remove = acpi_processor_remove, | |
b04e7bdb TG |
105 | .suspend = acpi_processor_suspend, |
106 | .resume = acpi_processor_resume, | |
7ec0a729 | 107 | .notify = acpi_processor_notify, |
4be44fcd | 108 | }, |
1da177e4 LT |
109 | }; |
110 | ||
111 | #define INSTALL_NOTIFY_HANDLER 1 | |
112 | #define UNINSTALL_NOTIFY_HANDLER 2 | |
1da177e4 | 113 | |
706546d0 | 114 | DEFINE_PER_CPU(struct acpi_processor *, processors); |
0f1d683f NC |
115 | EXPORT_PER_CPU_SYMBOL(processors); |
116 | ||
9f222718 | 117 | struct acpi_processor_errata errata __read_mostly; |
1da177e4 | 118 | |
1da177e4 LT |
119 | /* -------------------------------------------------------------------------- |
120 | Errata Handling | |
121 | -------------------------------------------------------------------------- */ | |
122 | ||
4be44fcd | 123 | static int acpi_processor_errata_piix4(struct pci_dev *dev) |
1da177e4 | 124 | { |
4be44fcd LB |
125 | u8 value1 = 0; |
126 | u8 value2 = 0; | |
1da177e4 | 127 | |
1da177e4 LT |
128 | |
129 | if (!dev) | |
d550d98d | 130 | return -EINVAL; |
1da177e4 LT |
131 | |
132 | /* | |
133 | * Note that 'dev' references the PIIX4 ACPI Controller. | |
134 | */ | |
135 | ||
44c10138 | 136 | switch (dev->revision) { |
1da177e4 LT |
137 | case 0: |
138 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n")); | |
139 | break; | |
140 | case 1: | |
141 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n")); | |
142 | break; | |
143 | case 2: | |
144 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n")); | |
145 | break; | |
146 | case 3: | |
147 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n")); | |
148 | break; | |
149 | default: | |
150 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n")); | |
151 | break; | |
152 | } | |
153 | ||
44c10138 | 154 | switch (dev->revision) { |
1da177e4 LT |
155 | |
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, | |
4be44fcd LB |
184 | PCI_DEVICE_ID_INTEL_82371AB, |
185 | PCI_ANY_ID, PCI_ANY_ID, NULL); | |
1da177e4 LT |
186 | 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, | |
4be44fcd LB |
201 | PCI_DEVICE_ID_INTEL_82371AB_0, |
202 | PCI_ANY_ID, PCI_ANY_ID, NULL); | |
1da177e4 LT |
203 | if (dev) { |
204 | pci_read_config_byte(dev, 0x76, &value1); | |
205 | pci_read_config_byte(dev, 0x77, &value2); | |
206 | if ((value1 & 0x80) || (value2 & 0x80)) | |
207 | errata.piix4.fdma = 1; | |
208 | pci_dev_put(dev); | |
209 | } | |
210 | ||
211 | break; | |
212 | } | |
213 | ||
214 | if (errata.piix4.bmisx) | |
215 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 216 | "Bus master activity detection (BM-IDE) erratum enabled\n")); |
1da177e4 LT |
217 | if (errata.piix4.fdma) |
218 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 219 | "Type-F DMA livelock erratum (C3 disabled)\n")); |
1da177e4 | 220 | |
d550d98d | 221 | return 0; |
1da177e4 LT |
222 | } |
223 | ||
8713cbef | 224 | static int acpi_processor_errata(struct acpi_processor *pr) |
1da177e4 | 225 | { |
4be44fcd LB |
226 | int result = 0; |
227 | struct pci_dev *dev = NULL; | |
1da177e4 | 228 | |
1da177e4 LT |
229 | |
230 | if (!pr) | |
d550d98d | 231 | return -EINVAL; |
1da177e4 LT |
232 | |
233 | /* | |
234 | * PIIX4 | |
235 | */ | |
236 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | |
4be44fcd LB |
237 | PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID, |
238 | PCI_ANY_ID, NULL); | |
1da177e4 LT |
239 | if (dev) { |
240 | result = acpi_processor_errata_piix4(dev); | |
241 | pci_dev_put(dev); | |
242 | } | |
243 | ||
d550d98d | 244 | return result; |
1da177e4 LT |
245 | } |
246 | ||
4be44fcd | 247 | static struct proc_dir_entry *acpi_processor_dir = NULL; |
1da177e4 | 248 | |
bf8b4542 | 249 | static int __cpuinit acpi_processor_add_fs(struct acpi_device *device) |
1da177e4 | 250 | { |
4be44fcd | 251 | struct proc_dir_entry *entry = NULL; |
1da177e4 | 252 | |
1da177e4 LT |
253 | |
254 | if (!acpi_device_dir(device)) { | |
255 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | |
4be44fcd | 256 | acpi_processor_dir); |
1da177e4 | 257 | if (!acpi_device_dir(device)) |
d550d98d | 258 | return -ENODEV; |
1da177e4 | 259 | } |
1da177e4 | 260 | |
1da177e4 | 261 | /* 'throttling' [R/W] */ |
cf7acfab DL |
262 | 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)); | |
1da177e4 | 267 | if (!entry) |
d550d98d | 268 | return -EIO; |
d550d98d | 269 | return 0; |
1da177e4 | 270 | } |
4be44fcd | 271 | static int acpi_processor_remove_fs(struct acpi_device *device) |
1da177e4 | 272 | { |
1da177e4 LT |
273 | |
274 | if (acpi_device_dir(device)) { | |
1da177e4 | 275 | remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING, |
4be44fcd | 276 | acpi_device_dir(device)); |
1da177e4 LT |
277 | remove_proc_entry(acpi_device_bid(device), acpi_processor_dir); |
278 | acpi_device_dir(device) = NULL; | |
279 | } | |
280 | ||
d550d98d | 281 | return 0; |
1da177e4 LT |
282 | } |
283 | ||
1da177e4 LT |
284 | /* -------------------------------------------------------------------------- |
285 | Driver Interface | |
286 | -------------------------------------------------------------------------- */ | |
287 | ||
b26e9286 | 288 | static int acpi_processor_get_info(struct acpi_device *device) |
1da177e4 | 289 | { |
4be44fcd LB |
290 | acpi_status status = 0; |
291 | union acpi_object object = { 0 }; | |
292 | struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; | |
b26e9286 MS |
293 | struct acpi_processor *pr; |
294 | int cpu_index, device_declaration = 0; | |
4be44fcd | 295 | static int cpu0_initialized; |
1da177e4 | 296 | |
b26e9286 | 297 | pr = acpi_driver_data(device); |
1da177e4 | 298 | if (!pr) |
d550d98d | 299 | return -EINVAL; |
1da177e4 LT |
300 | |
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 | */ | |
cee324b1 | 310 | if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) { |
1da177e4 LT |
311 | pr->flags.bm_control = 1; |
312 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd LB |
313 | "Bus mastering arbitration control present\n")); |
314 | } else | |
1da177e4 | 315 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
4be44fcd | 316 | "No bus mastering arbitration control\n")); |
1da177e4 | 317 | |
6cc73b48 BH |
318 | 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 { | |
b26e9286 MS |
333 | /* |
334 | * Declared with "Device" statement; match _UID. | |
335 | * Note that we don't handle string _UIDs yet. | |
336 | */ | |
27663c58 | 337 | unsigned long long value; |
11bf04c4 AS |
338 | status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID, |
339 | NULL, &value); | |
340 | if (ACPI_FAILURE(status)) { | |
b26e9286 MS |
341 | printk(KERN_ERR PREFIX |
342 | "Evaluating processor _UID [%#x]\n", status); | |
11bf04c4 AS |
343 | return -ENODEV; |
344 | } | |
b26e9286 | 345 | device_declaration = 1; |
11bf04c4 | 346 | pr->acpi_id = value; |
11bf04c4 | 347 | } |
2e9d5e4e | 348 | cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id); |
1da177e4 | 349 | |
4be44fcd | 350 | /* Handle UP system running SMP kernel, with no LAPIC in MADT */ |
df42baa0 | 351 | if (!cpu0_initialized && (cpu_index == -1) && |
4be44fcd LB |
352 | (num_online_cpus() == 1)) { |
353 | cpu_index = 0; | |
354 | } | |
355 | ||
356 | cpu0_initialized = 1; | |
357 | ||
358 | pr->id = cpu_index; | |
359 | ||
360 | /* | |
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 | */ | |
f18c5a08 | 365 | if (pr->id == -1) { |
4be44fcd LB |
366 | if (ACPI_FAILURE |
367 | (acpi_processor_hotadd_init(pr->handle, &pr->id))) { | |
d550d98d | 368 | return -ENODEV; |
4be44fcd LB |
369 | } |
370 | } | |
7a04b849 ZY |
371 | /* |
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); | |
1da177e4 | 381 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id, |
4be44fcd | 382 | pr->acpi_id)); |
1da177e4 LT |
383 | |
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) | |
6468463a LB |
387 | printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n", |
388 | object.processor.pblk_length); | |
1da177e4 LT |
389 | else { |
390 | pr->throttling.address = object.processor.pblk_address; | |
cee324b1 AS |
391 | pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset; |
392 | pr->throttling.duty_width = acpi_gbl_FADT.duty_width; | |
1da177e4 LT |
393 | |
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 | ||
fe086a7b AC |
406 | /* |
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 | ||
d550d98d | 415 | return 0; |
1da177e4 LT |
416 | } |
417 | ||
706546d0 | 418 | static DEFINE_PER_CPU(void *, processor_device_array); |
cd8e2b48 | 419 | |
7ec0a729 | 420 | static void acpi_processor_notify(struct acpi_device *device, u32 event) |
1da177e4 | 421 | { |
7ec0a729 | 422 | struct acpi_processor *pr = acpi_driver_data(device); |
e790cc8b | 423 | int saved; |
1da177e4 LT |
424 | |
425 | if (!pr) | |
d550d98d | 426 | return; |
1da177e4 | 427 | |
1da177e4 LT |
428 | switch (event) { |
429 | case ACPI_PROCESSOR_NOTIFY_PERFORMANCE: | |
e790cc8b | 430 | saved = pr->performance_platform_limit; |
d81c45e1 | 431 | acpi_processor_ppc_has_changed(pr, 1); |
e790cc8b AS |
432 | if (saved == pr->performance_platform_limit) |
433 | break; | |
14e04fb3 | 434 | acpi_bus_generate_proc_event(device, event, |
4be44fcd | 435 | pr->performance_platform_limit); |
962ce8ca | 436 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
0794469d | 437 | dev_name(&device->dev), event, |
962ce8ca | 438 | pr->performance_platform_limit); |
1da177e4 LT |
439 | break; |
440 | case ACPI_PROCESSOR_NOTIFY_POWER: | |
441 | acpi_processor_cst_has_changed(pr); | |
14e04fb3 | 442 | acpi_bus_generate_proc_event(device, event, 0); |
962ce8ca | 443 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
0794469d | 444 | dev_name(&device->dev), event, 0); |
1da177e4 | 445 | break; |
01854e69 LY |
446 | case ACPI_PROCESSOR_NOTIFY_THROTTLING: |
447 | acpi_processor_tstate_has_changed(pr); | |
14e04fb3 | 448 | acpi_bus_generate_proc_event(device, event, 0); |
962ce8ca | 449 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
0794469d | 450 | dev_name(&device->dev), event, 0); |
1da177e4 LT |
451 | default: |
452 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 453 | "Unsupported event [0x%x]\n", event)); |
1da177e4 LT |
454 | break; |
455 | } | |
456 | ||
d550d98d | 457 | return; |
1da177e4 LT |
458 | } |
459 | ||
729c6ba3 VP |
460 | static int acpi_cpu_soft_notify(struct notifier_block *nfb, |
461 | unsigned long action, void *hcpu) | |
462 | { | |
463 | unsigned int cpu = (unsigned long)hcpu; | |
706546d0 | 464 | struct acpi_processor *pr = per_cpu(processors, cpu); |
729c6ba3 VP |
465 | |
466 | if (action == CPU_ONLINE && pr) { | |
d81c45e1 | 467 | acpi_processor_ppc_has_changed(pr, 0); |
729c6ba3 VP |
468 | acpi_processor_cst_has_changed(pr); |
469 | acpi_processor_tstate_has_changed(pr); | |
470 | } | |
471 | return NOTIFY_OK; | |
472 | } | |
473 | ||
474 | static struct notifier_block acpi_cpu_notifier = | |
475 | { | |
476 | .notifier_call = acpi_cpu_soft_notify, | |
477 | }; | |
478 | ||
941b10fa | 479 | static int __cpuinit acpi_processor_add(struct acpi_device *device) |
1da177e4 | 480 | { |
4be44fcd | 481 | struct acpi_processor *pr = NULL; |
970b0492 BH |
482 | int result = 0; |
483 | struct sys_device *sysdev; | |
1da177e4 | 484 | |
36bcbec7 | 485 | pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); |
1da177e4 | 486 | if (!pr) |
d550d98d | 487 | return -ENOMEM; |
1da177e4 | 488 | |
eaa95840 | 489 | if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) { |
2fdf66b4 RR |
490 | kfree(pr); |
491 | return -ENOMEM; | |
492 | } | |
493 | ||
1da177e4 LT |
494 | pr->handle = device->handle; |
495 | strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME); | |
496 | strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS); | |
db89b4f0 | 497 | device->driver_data = pr; |
1da177e4 | 498 | |
b26e9286 | 499 | result = acpi_processor_get_info(device); |
1da177e4 LT |
500 | if (result) { |
501 | /* Processor is physically not present */ | |
d550d98d | 502 | return 0; |
1da177e4 LT |
503 | } |
504 | ||
75cbfb97 TR |
505 | #ifdef CONFIG_SMP |
506 | if (pr->id >= setup_max_cpus && pr->id != 0) | |
507 | return 0; | |
508 | #endif | |
509 | ||
fbb43ab0 | 510 | BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0)); |
1da177e4 | 511 | |
cd8e2b48 VP |
512 | /* |
513 | * Buggy BIOS check | |
514 | * ACPI id of processors can be reported wrongly by the BIOS. | |
515 | * Don't trust it blindly | |
516 | */ | |
706546d0 MT |
517 | if (per_cpu(processor_device_array, pr->id) != NULL && |
518 | per_cpu(processor_device_array, pr->id) != device) { | |
4fdb2a05 | 519 | printk(KERN_WARNING "BIOS reported wrong ACPI id " |
0eacee58 | 520 | "for the processor\n"); |
970b0492 BH |
521 | result = -ENODEV; |
522 | goto err_free_cpumask; | |
cd8e2b48 | 523 | } |
706546d0 | 524 | per_cpu(processor_device_array, pr->id) = device; |
cd8e2b48 | 525 | |
706546d0 | 526 | per_cpu(processors, pr->id) = pr; |
1da177e4 LT |
527 | |
528 | result = acpi_processor_add_fs(device); | |
529 | if (result) | |
970b0492 | 530 | goto err_free_cpumask; |
1da177e4 | 531 | |
9f1eb99c | 532 | sysdev = get_cpu_sysdev(pr->id); |
d4e05261 BH |
533 | if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) { |
534 | result = -EFAULT; | |
535 | goto err_remove_fs; | |
536 | } | |
9f1eb99c | 537 | |
0ac3c571 | 538 | #ifdef CONFIG_CPU_FREQ |
d81c45e1 | 539 | acpi_processor_ppc_has_changed(pr, 0); |
0ac3c571 ZY |
540 | #endif |
541 | acpi_processor_get_throttling_info(pr); | |
542 | acpi_processor_get_limit_info(pr); | |
543 | ||
05131ecc | 544 | |
541adf7c LB |
545 | if (cpuidle_get_driver() == &acpi_idle_driver) |
546 | acpi_processor_power_init(pr, device); | |
1da177e4 | 547 | |
d9460fd2 ZR |
548 | pr->cdev = thermal_cooling_device_register("Processor", device, |
549 | &processor_cooling_ops); | |
d76628c6 TS |
550 | if (IS_ERR(pr->cdev)) { |
551 | result = PTR_ERR(pr->cdev); | |
d4e05261 | 552 | goto err_power_exit; |
d76628c6 | 553 | } |
9030062f | 554 | |
13c41157 | 555 | dev_dbg(&device->dev, "registered as cooling_device%d\n", |
fc3a8828 | 556 | pr->cdev->id); |
9030062f JL |
557 | |
558 | result = sysfs_create_link(&device->dev.kobj, | |
559 | &pr->cdev->device.kobj, | |
560 | "thermal_cooling"); | |
d4e05261 | 561 | if (result) { |
9030062f | 562 | printk(KERN_ERR PREFIX "Create sysfs link\n"); |
d4e05261 BH |
563 | goto err_thermal_unregister; |
564 | } | |
9030062f JL |
565 | result = sysfs_create_link(&pr->cdev->device.kobj, |
566 | &device->dev.kobj, | |
567 | "device"); | |
d4e05261 | 568 | if (result) { |
9030062f | 569 | printk(KERN_ERR PREFIX "Create sysfs link\n"); |
d4e05261 BH |
570 | goto err_remove_sysfs; |
571 | } | |
d9460fd2 | 572 | |
d550d98d | 573 | return 0; |
d4e05261 BH |
574 | |
575 | err_remove_sysfs: | |
576 | sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); | |
577 | err_thermal_unregister: | |
578 | thermal_cooling_device_unregister(pr->cdev); | |
579 | err_power_exit: | |
580 | acpi_processor_power_exit(pr, device); | |
581 | err_remove_fs: | |
582 | acpi_processor_remove_fs(device); | |
970b0492 BH |
583 | err_free_cpumask: |
584 | free_cpumask_var(pr->throttling.shared_cpu_map); | |
1da177e4 | 585 | |
d550d98d | 586 | return result; |
1da177e4 LT |
587 | } |
588 | ||
4be44fcd | 589 | static int acpi_processor_remove(struct acpi_device *device, int type) |
1da177e4 | 590 | { |
4be44fcd | 591 | struct acpi_processor *pr = NULL; |
1da177e4 | 592 | |
1da177e4 LT |
593 | |
594 | if (!device || !acpi_driver_data(device)) | |
d550d98d | 595 | return -EINVAL; |
1da177e4 | 596 | |
50dd0969 | 597 | pr = acpi_driver_data(device); |
1da177e4 | 598 | |
2fdf66b4 RR |
599 | if (pr->id >= nr_cpu_ids) |
600 | goto free; | |
1da177e4 LT |
601 | |
602 | if (type == ACPI_BUS_REMOVAL_EJECT) { | |
603 | if (acpi_processor_handle_eject(pr)) | |
d550d98d | 604 | return -EINVAL; |
1da177e4 LT |
605 | } |
606 | ||
607 | acpi_processor_power_exit(pr, device); | |
608 | ||
9f1eb99c ZR |
609 | sysfs_remove_link(&device->dev.kobj, "sysdev"); |
610 | ||
1da177e4 LT |
611 | acpi_processor_remove_fs(device); |
612 | ||
f28bb45e ZY |
613 | 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 | } | |
d9460fd2 | 619 | |
706546d0 MT |
620 | per_cpu(processors, pr->id) = NULL; |
621 | per_cpu(processor_device_array, pr->id) = NULL; | |
2fdf66b4 RR |
622 | |
623 | free: | |
624 | free_cpumask_var(pr->throttling.shared_cpu_map); | |
1da177e4 LT |
625 | kfree(pr); |
626 | ||
d550d98d | 627 | return 0; |
1da177e4 LT |
628 | } |
629 | ||
630 | #ifdef CONFIG_ACPI_HOTPLUG_CPU | |
631 | /**************************************************************************** | |
632 | * Acpi processor hotplug support * | |
633 | ****************************************************************************/ | |
634 | ||
4be44fcd | 635 | static int is_processor_present(acpi_handle handle) |
1da177e4 | 636 | { |
4be44fcd | 637 | acpi_status status; |
27663c58 | 638 | unsigned long long sta = 0; |
1da177e4 | 639 | |
1da177e4 LT |
640 | |
641 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); | |
cfaf3747 ZR |
642 | |
643 | if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT)) | |
644 | return 1; | |
645 | ||
d0ce46f5 ZR |
646 | /* |
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")); | |
cfaf3747 | 655 | return 0; |
1da177e4 LT |
656 | } |
657 | ||
1da177e4 | 658 | static |
4be44fcd | 659 | int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device) |
1da177e4 | 660 | { |
4be44fcd LB |
661 | acpi_handle phandle; |
662 | struct acpi_device *pdev; | |
1da177e4 | 663 | |
1da177e4 LT |
664 | |
665 | if (acpi_get_parent(handle, &phandle)) { | |
d550d98d | 666 | return -ENODEV; |
1da177e4 LT |
667 | } |
668 | ||
669 | if (acpi_bus_get_device(phandle, &pdev)) { | |
d550d98d | 670 | return -ENODEV; |
1da177e4 LT |
671 | } |
672 | ||
673 | if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) { | |
d550d98d | 674 | return -ENODEV; |
1da177e4 LT |
675 | } |
676 | ||
d550d98d | 677 | return 0; |
1da177e4 LT |
678 | } |
679 | ||
b95e9e8d SR |
680 | static void __ref acpi_processor_hotplug_notify(acpi_handle handle, |
681 | u32 event, void *data) | |
1da177e4 | 682 | { |
4be44fcd LB |
683 | struct acpi_processor *pr; |
684 | struct acpi_device *device = NULL; | |
1da177e4 LT |
685 | int result; |
686 | ||
1da177e4 LT |
687 | |
688 | switch (event) { | |
689 | case ACPI_NOTIFY_BUS_CHECK: | |
690 | case ACPI_NOTIFY_DEVICE_CHECK: | |
d6f882e1 GC |
691 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
692 | "Processor driver received %s event\n", | |
4be44fcd | 693 | (event == ACPI_NOTIFY_BUS_CHECK) ? |
d6f882e1 | 694 | "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK")); |
1da177e4 LT |
695 | |
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) | |
6468463a LB |
702 | printk(KERN_ERR PREFIX |
703 | "Unable to add the device\n"); | |
1da177e4 LT |
704 | break; |
705 | } | |
4be44fcd | 706 | break; |
1da177e4 | 707 | case ACPI_NOTIFY_EJECT_REQUEST: |
4be44fcd LB |
708 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
709 | "received ACPI_NOTIFY_EJECT_REQUEST\n")); | |
1da177e4 LT |
710 | |
711 | if (acpi_bus_get_device(handle, &device)) { | |
6468463a LB |
712 | printk(KERN_ERR PREFIX |
713 | "Device don't exist, dropping EJECT\n"); | |
1da177e4 LT |
714 | break; |
715 | } | |
716 | pr = acpi_driver_data(device); | |
717 | if (!pr) { | |
6468463a LB |
718 | printk(KERN_ERR PREFIX |
719 | "Driver data is NULL, dropping EJECT\n"); | |
d550d98d | 720 | return; |
1da177e4 | 721 | } |
1da177e4 LT |
722 | break; |
723 | default: | |
724 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 725 | "Unsupported event [0x%x]\n", event)); |
1da177e4 LT |
726 | break; |
727 | } | |
728 | ||
d550d98d | 729 | return; |
1da177e4 LT |
730 | } |
731 | ||
732 | static acpi_status | |
733 | processor_walk_namespace_cb(acpi_handle handle, | |
4be44fcd | 734 | u32 lvl, void *context, void **rv) |
1da177e4 | 735 | { |
4be44fcd | 736 | acpi_status status; |
1da177e4 | 737 | int *action = context; |
4be44fcd | 738 | acpi_object_type type = 0; |
1da177e4 LT |
739 | |
740 | status = acpi_get_type(handle, &type); | |
741 | if (ACPI_FAILURE(status)) | |
4be44fcd | 742 | return (AE_OK); |
1da177e4 LT |
743 | |
744 | if (type != ACPI_TYPE_PROCESSOR) | |
4be44fcd | 745 | return (AE_OK); |
1da177e4 | 746 | |
4be44fcd | 747 | switch (*action) { |
1da177e4 LT |
748 | case INSTALL_NOTIFY_HANDLER: |
749 | acpi_install_notify_handler(handle, | |
4be44fcd LB |
750 | ACPI_SYSTEM_NOTIFY, |
751 | acpi_processor_hotplug_notify, | |
752 | NULL); | |
1da177e4 LT |
753 | break; |
754 | case UNINSTALL_NOTIFY_HANDLER: | |
755 | acpi_remove_notify_handler(handle, | |
4be44fcd LB |
756 | ACPI_SYSTEM_NOTIFY, |
757 | acpi_processor_hotplug_notify); | |
1da177e4 LT |
758 | break; |
759 | default: | |
760 | break; | |
761 | } | |
762 | ||
4be44fcd | 763 | return (AE_OK); |
1da177e4 LT |
764 | } |
765 | ||
4be44fcd | 766 | static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu) |
1da177e4 | 767 | { |
1da177e4 LT |
768 | |
769 | if (!is_processor_present(handle)) { | |
d550d98d | 770 | return AE_ERROR; |
1da177e4 LT |
771 | } |
772 | ||
773 | if (acpi_map_lsapic(handle, p_cpu)) | |
d550d98d | 774 | return AE_ERROR; |
1da177e4 LT |
775 | |
776 | if (arch_register_cpu(*p_cpu)) { | |
777 | acpi_unmap_lsapic(*p_cpu); | |
d550d98d | 778 | return AE_ERROR; |
1da177e4 LT |
779 | } |
780 | ||
d550d98d | 781 | return AE_OK; |
1da177e4 LT |
782 | } |
783 | ||
4be44fcd | 784 | static int acpi_processor_handle_eject(struct acpi_processor *pr) |
1da177e4 | 785 | { |
b62b8ef9 ZR |
786 | if (cpu_online(pr->id)) |
787 | cpu_down(pr->id); | |
788 | ||
1da177e4 LT |
789 | arch_unregister_cpu(pr->id); |
790 | acpi_unmap_lsapic(pr->id); | |
4be44fcd | 791 | return (0); |
1da177e4 LT |
792 | } |
793 | #else | |
4be44fcd | 794 | static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu) |
1da177e4 LT |
795 | { |
796 | return AE_ERROR; | |
797 | } | |
4be44fcd | 798 | static int acpi_processor_handle_eject(struct acpi_processor *pr) |
1da177e4 | 799 | { |
4be44fcd | 800 | return (-EINVAL); |
1da177e4 LT |
801 | } |
802 | #endif | |
803 | ||
1da177e4 LT |
804 | static |
805 | void 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, | |
4be44fcd LB |
810 | ACPI_ROOT_OBJECT, |
811 | ACPI_UINT32_MAX, | |
2263576c | 812 | processor_walk_namespace_cb, NULL, &action, NULL); |
1da177e4 | 813 | #endif |
729c6ba3 | 814 | register_hotcpu_notifier(&acpi_cpu_notifier); |
1da177e4 LT |
815 | } |
816 | ||
1da177e4 LT |
817 | static |
818 | void 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, | |
4be44fcd LB |
823 | ACPI_ROOT_OBJECT, |
824 | ACPI_UINT32_MAX, | |
2263576c | 825 | processor_walk_namespace_cb, NULL, &action, NULL); |
1da177e4 | 826 | #endif |
729c6ba3 | 827 | unregister_hotcpu_notifier(&acpi_cpu_notifier); |
1da177e4 LT |
828 | } |
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 | ||
4be44fcd | 836 | static int __init acpi_processor_init(void) |
1da177e4 | 837 | { |
4be44fcd | 838 | int result = 0; |
1da177e4 | 839 | |
ce8442b5 YL |
840 | if (acpi_disabled) |
841 | return 0; | |
842 | ||
1da177e4 LT |
843 | memset(&errata, 0, sizeof(errata)); |
844 | ||
845 | acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); | |
846 | if (!acpi_processor_dir) | |
83822fc9 | 847 | return -ENOMEM; |
541adf7c | 848 | |
26717172 | 849 | if (!cpuidle_register_driver(&acpi_idle_driver)) { |
541adf7c LB |
850 | printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n", |
851 | acpi_idle_driver.name); | |
26717172 | 852 | } else { |
e9a64ed4 | 853 | printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s\n", |
26717172 LB |
854 | cpuidle_get_driver()->name); |
855 | } | |
4f86d3a8 | 856 | |
1da177e4 | 857 | result = acpi_bus_register_driver(&acpi_processor_driver); |
4f86d3a8 LB |
858 | if (result < 0) |
859 | goto out_cpuidle; | |
1da177e4 LT |
860 | |
861 | acpi_processor_install_hotplug_notify(); | |
862 | ||
863 | acpi_thermal_cpufreq_init(); | |
864 | ||
865 | acpi_processor_ppc_init(); | |
866 | ||
1180509f ZY |
867 | acpi_processor_throttling_init(); |
868 | ||
d550d98d | 869 | return 0; |
4f86d3a8 LB |
870 | |
871 | out_cpuidle: | |
872 | cpuidle_unregister_driver(&acpi_idle_driver); | |
873 | ||
4f86d3a8 LB |
874 | remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); |
875 | ||
876 | return result; | |
1da177e4 LT |
877 | } |
878 | ||
4be44fcd | 879 | static void __exit acpi_processor_exit(void) |
1da177e4 | 880 | { |
ce8442b5 YL |
881 | if (acpi_disabled) |
882 | return; | |
883 | ||
1da177e4 LT |
884 | 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 | ||
4f86d3a8 LB |
892 | cpuidle_unregister_driver(&acpi_idle_driver); |
893 | ||
1da177e4 LT |
894 | remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); |
895 | ||
d550d98d | 896 | return; |
1da177e4 LT |
897 | } |
898 | ||
1da177e4 LT |
899 | module_init(acpi_processor_init); |
900 | module_exit(acpi_processor_exit); | |
901 | ||
902 | EXPORT_SYMBOL(acpi_processor_set_thermal_limit); | |
903 | ||
904 | MODULE_ALIAS("processor"); |