Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
| 47 | |
| 48 | #include <asm/io.h> |
| 49 | #include <asm/system.h> |
| 50 | #include <asm/cpu.h> |
| 51 | #include <asm/delay.h> |
| 52 | #include <asm/uaccess.h> |
| 53 | #include <asm/processor.h> |
| 54 | #include <asm/smp.h> |
| 55 | #include <asm/acpi.h> |
| 56 | |
| 57 | #include <acpi/acpi_bus.h> |
| 58 | #include <acpi/acpi_drivers.h> |
| 59 | #include <acpi/processor.h> |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #define ACPI_PROCESSOR_COMPONENT 0x01000000 |
| 62 | #define ACPI_PROCESSOR_CLASS "processor" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #define ACPI_PROCESSOR_DEVICE_NAME "Processor" |
| 64 | #define ACPI_PROCESSOR_FILE_INFO "info" |
| 65 | #define ACPI_PROCESSOR_FILE_THROTTLING "throttling" |
| 66 | #define ACPI_PROCESSOR_FILE_LIMIT "limit" |
| 67 | #define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80 |
| 68 | #define ACPI_PROCESSOR_NOTIFY_POWER 0x81 |
| 69 | |
| 70 | #define ACPI_PROCESSOR_LIMIT_USER 0 |
| 71 | #define ACPI_PROCESSOR_LIMIT_THERMAL 1 |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 74 | ACPI_MODULE_NAME("processor_core"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 76 | MODULE_AUTHOR("Paul Diefenbaugh"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 77 | MODULE_DESCRIPTION("ACPI Processor Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | MODULE_LICENSE("GPL"); |
| 79 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | static int acpi_processor_add(struct acpi_device *device); |
| 81 | static int acpi_processor_start(struct acpi_device *device); |
| 82 | static int acpi_processor_remove(struct acpi_device *device, int type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | static int acpi_processor_info_open_fs(struct inode *inode, struct file *file); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | static void acpi_processor_notify(acpi_handle handle, u32 event, void *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu); |
| 86 | static int acpi_processor_handle_eject(struct acpi_processor *pr); |
| 87 | |
| 88 | static struct acpi_driver acpi_processor_driver = { |
Len Brown | c2b6705b | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 89 | .name = "processor", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | .class = ACPI_PROCESSOR_CLASS, |
| 91 | .ids = ACPI_PROCESSOR_HID, |
| 92 | .ops = { |
| 93 | .add = acpi_processor_add, |
| 94 | .remove = acpi_processor_remove, |
| 95 | .start = acpi_processor_start, |
| 96 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | #define INSTALL_NOTIFY_HANDLER 1 |
| 100 | #define UNINSTALL_NOTIFY_HANDLER 2 |
| 101 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 102 | static const struct file_operations acpi_processor_info_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 103 | .open = acpi_processor_info_open_fs, |
| 104 | .read = seq_read, |
| 105 | .llseek = seq_lseek, |
| 106 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | struct acpi_processor *processors[NR_CPUS]; |
Andreas Mohr | 9f22271 | 2006-06-23 02:04:27 -0700 | [diff] [blame] | 110 | struct acpi_processor_errata errata __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /* -------------------------------------------------------------------------- |
| 113 | Errata Handling |
| 114 | -------------------------------------------------------------------------- */ |
| 115 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 116 | static int acpi_processor_errata_piix4(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 118 | u8 value1 = 0; |
| 119 | u8 value2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | if (!dev) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 123 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | /* |
| 126 | * Note that 'dev' references the PIIX4 ACPI Controller. |
| 127 | */ |
| 128 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame^] | 129 | switch (dev->revision) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | case 0: |
| 131 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n")); |
| 132 | break; |
| 133 | case 1: |
| 134 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n")); |
| 135 | break; |
| 136 | case 2: |
| 137 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n")); |
| 138 | break; |
| 139 | case 3: |
| 140 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n")); |
| 141 | break; |
| 142 | default: |
| 143 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n")); |
| 144 | break; |
| 145 | } |
| 146 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame^] | 147 | switch (dev->revision) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | case 0: /* PIIX4 A-step */ |
| 150 | case 1: /* PIIX4 B-step */ |
| 151 | /* |
| 152 | * See specification changes #13 ("Manual Throttle Duty Cycle") |
| 153 | * and #14 ("Enabling and Disabling Manual Throttle"), plus |
| 154 | * erratum #5 ("STPCLK# Deassertion Time") from the January |
| 155 | * 2002 PIIX4 specification update. Applies to only older |
| 156 | * PIIX4 models. |
| 157 | */ |
| 158 | errata.piix4.throttle = 1; |
| 159 | |
| 160 | case 2: /* PIIX4E */ |
| 161 | case 3: /* PIIX4M */ |
| 162 | /* |
| 163 | * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA |
| 164 | * Livelock") from the January 2002 PIIX4 specification update. |
| 165 | * Applies to all PIIX4 models. |
| 166 | */ |
| 167 | |
| 168 | /* |
| 169 | * BM-IDE |
| 170 | * ------ |
| 171 | * Find the PIIX4 IDE Controller and get the Bus Master IDE |
| 172 | * Status register address. We'll use this later to read |
| 173 | * each IDE controller's DMA status to make sure we catch all |
| 174 | * DMA activity. |
| 175 | */ |
| 176 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | PCI_DEVICE_ID_INTEL_82371AB, |
| 178 | PCI_ANY_ID, PCI_ANY_ID, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | if (dev) { |
| 180 | errata.piix4.bmisx = pci_resource_start(dev, 4); |
| 181 | pci_dev_put(dev); |
| 182 | } |
| 183 | |
| 184 | /* |
| 185 | * Type-F DMA |
| 186 | * ---------- |
| 187 | * Find the PIIX4 ISA Controller and read the Motherboard |
| 188 | * DMA controller's status to see if Type-F (Fast) DMA mode |
| 189 | * is enabled (bit 7) on either channel. Note that we'll |
| 190 | * disable C3 support if this is enabled, as some legacy |
| 191 | * devices won't operate well if fast DMA is disabled. |
| 192 | */ |
| 193 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | PCI_DEVICE_ID_INTEL_82371AB_0, |
| 195 | PCI_ANY_ID, PCI_ANY_ID, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | if (dev) { |
| 197 | pci_read_config_byte(dev, 0x76, &value1); |
| 198 | pci_read_config_byte(dev, 0x77, &value2); |
| 199 | if ((value1 & 0x80) || (value2 & 0x80)) |
| 200 | errata.piix4.fdma = 1; |
| 201 | pci_dev_put(dev); |
| 202 | } |
| 203 | |
| 204 | break; |
| 205 | } |
| 206 | |
| 207 | if (errata.piix4.bmisx) |
| 208 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | "Bus master activity detection (BM-IDE) erratum enabled\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | if (errata.piix4.fdma) |
| 211 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | "Type-F DMA livelock erratum (C3 disabled)\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 214 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Adrian Bunk | 8713cbe | 2005-09-02 17:16:48 -0400 | [diff] [blame] | 217 | static int acpi_processor_errata(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | int result = 0; |
| 220 | struct pci_dev *dev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
| 223 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 224 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | /* |
| 227 | * PIIX4 |
| 228 | */ |
| 229 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID, |
| 231 | PCI_ANY_ID, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | if (dev) { |
| 233 | result = acpi_processor_errata_piix4(dev); |
| 234 | pci_dev_put(dev); |
| 235 | } |
| 236 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 237 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | /* -------------------------------------------------------------------------- |
Akinobu Mita | 0b28002 | 2006-03-26 01:38:58 -0800 | [diff] [blame] | 241 | Common ACPI processor functions |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 242 | -------------------------------------------------------------------------- */ |
| 243 | |
| 244 | /* |
| 245 | * _PDC is required for a BIOS-OS handshake for most of the newer |
| 246 | * ACPI processor features. |
| 247 | */ |
Venkatesh Pallipadi | 05131ec | 2005-10-23 16:31:00 -0400 | [diff] [blame] | 248 | static int acpi_processor_set_pdc(struct acpi_processor *pr) |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 249 | { |
Venkatesh Pallipadi | 05131ec | 2005-10-23 16:31:00 -0400 | [diff] [blame] | 250 | struct acpi_object_list *pdc_in = pr->pdc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 251 | acpi_status status = AE_OK; |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 252 | |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 253 | |
Venkatesh Pallipadi | 05131ec | 2005-10-23 16:31:00 -0400 | [diff] [blame] | 254 | if (!pdc_in) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 255 | return status; |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 256 | |
Venkatesh Pallipadi | 05131ec | 2005-10-23 16:31:00 -0400 | [diff] [blame] | 257 | status = acpi_evaluate_object(pr->handle, "_PDC", pdc_in, NULL); |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 258 | |
Venkatesh Pallipadi | 05131ec | 2005-10-23 16:31:00 -0400 | [diff] [blame] | 259 | if (ACPI_FAILURE(status)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 260 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Venkatesh Pallipadi | 05131ec | 2005-10-23 16:31:00 -0400 | [diff] [blame] | 261 | "Could not evaluate _PDC, using legacy perf. control...\n")); |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 262 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 263 | return status; |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 264 | } |
| 265 | |
Venkatesh Pallipadi | 02df8b9 | 2005-04-15 15:07:10 -0400 | [diff] [blame] | 266 | /* -------------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | FS Interface (/proc) |
| 268 | -------------------------------------------------------------------------- */ |
| 269 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | static struct proc_dir_entry *acpi_processor_dir = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset) |
| 273 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 274 | struct acpi_processor *pr = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | if (!pr) |
| 278 | goto end; |
| 279 | |
| 280 | seq_printf(seq, "processor id: %d\n" |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 281 | "acpi id: %d\n" |
| 282 | "bus mastering control: %s\n" |
| 283 | "power management: %s\n" |
| 284 | "throttling control: %s\n" |
| 285 | "limit interface: %s\n", |
| 286 | pr->id, |
| 287 | pr->acpi_id, |
| 288 | pr->flags.bm_control ? "yes" : "no", |
| 289 | pr->flags.power ? "yes" : "no", |
| 290 | pr->flags.throttling ? "yes" : "no", |
| 291 | pr->flags.limit ? "yes" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 294 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static int acpi_processor_info_open_fs(struct inode *inode, struct file *file) |
| 298 | { |
| 299 | return single_open(file, acpi_processor_info_seq_show, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 300 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 303 | static int acpi_processor_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 305 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
| 308 | if (!acpi_device_dir(device)) { |
| 309 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 310 | acpi_processor_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (!acpi_device_dir(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 312 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | acpi_device_dir(device)->owner = THIS_MODULE; |
| 315 | |
| 316 | /* 'info' [R] */ |
| 317 | entry = create_proc_entry(ACPI_PROCESSOR_FILE_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 318 | S_IRUGO, acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 320 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | else { |
| 322 | entry->proc_fops = &acpi_processor_info_fops; |
| 323 | entry->data = acpi_driver_data(device); |
| 324 | entry->owner = THIS_MODULE; |
| 325 | } |
| 326 | |
| 327 | /* 'throttling' [R/W] */ |
| 328 | entry = create_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | S_IFREG | S_IRUGO | S_IWUSR, |
| 330 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 332 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | else { |
| 334 | entry->proc_fops = &acpi_processor_throttling_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | entry->data = acpi_driver_data(device); |
| 336 | entry->owner = THIS_MODULE; |
| 337 | } |
| 338 | |
| 339 | /* 'limit' [R/W] */ |
| 340 | entry = create_proc_entry(ACPI_PROCESSOR_FILE_LIMIT, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 341 | S_IFREG | S_IRUGO | S_IWUSR, |
| 342 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 344 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | else { |
| 346 | entry->proc_fops = &acpi_processor_limit_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | entry->data = acpi_driver_data(device); |
| 348 | entry->owner = THIS_MODULE; |
| 349 | } |
| 350 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 351 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 354 | static int acpi_processor_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | if (acpi_device_dir(device)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 358 | remove_proc_entry(ACPI_PROCESSOR_FILE_INFO, |
| 359 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 361 | acpi_device_dir(device)); |
| 362 | remove_proc_entry(ACPI_PROCESSOR_FILE_LIMIT, |
| 363 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | remove_proc_entry(acpi_device_bid(device), acpi_processor_dir); |
| 365 | acpi_device_dir(device) = NULL; |
| 366 | } |
| 367 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 368 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /* Use the acpiid in MADT to map cpus in case of SMP */ |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | #ifndef CONFIG_SMP |
Alexey Starikovskiy | 11bf04c | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 374 | static int get_cpu_id(acpi_handle handle, u32 acpi_id) {return -1;} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | #else |
| 376 | |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 377 | static struct acpi_table_madt *madt; |
| 378 | |
| 379 | static int map_lapic_id(struct acpi_subtable_header *entry, |
| 380 | u32 acpi_id, int *apic_id) |
| 381 | { |
| 382 | struct acpi_madt_local_apic *lapic = |
| 383 | (struct acpi_madt_local_apic *)entry; |
| 384 | if ((lapic->lapic_flags & ACPI_MADT_ENABLED) && |
| 385 | lapic->processor_id == acpi_id) { |
| 386 | *apic_id = lapic->id; |
| 387 | return 1; |
| 388 | } |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static int map_lsapic_id(struct acpi_subtable_header *entry, |
| 393 | u32 acpi_id, int *apic_id) |
| 394 | { |
| 395 | struct acpi_madt_local_sapic *lsapic = |
| 396 | (struct acpi_madt_local_sapic *)entry; |
| 397 | /* Only check enabled APICs*/ |
| 398 | if (lsapic->lapic_flags & ACPI_MADT_ENABLED) { |
| 399 | /* First check against id */ |
| 400 | if (lsapic->processor_id == acpi_id) { |
Alexey Starikovskiy | 615d5f2 | 2007-02-12 10:51:23 -0500 | [diff] [blame] | 401 | *apic_id = (lsapic->id << 8) | lsapic->eid; |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 402 | return 1; |
| 403 | /* Check against optional uid */ |
| 404 | } else if (entry->length >= 16 && |
| 405 | lsapic->uid == acpi_id) { |
| 406 | *apic_id = lsapic->uid; |
| 407 | return 1; |
| 408 | } |
| 409 | } |
| 410 | return 0; |
| 411 | } |
| 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | #ifdef CONFIG_IA64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | #define arch_cpu_to_apicid ia64_cpu_to_sapicid |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | #define arch_cpu_to_apicid x86_cpu_to_apicid |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | #endif |
| 418 | |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 419 | static int map_madt_entry(u32 acpi_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 421 | unsigned long madt_end, entry; |
| 422 | int apic_id = -1; |
| 423 | |
| 424 | if (!madt) |
| 425 | return apic_id; |
| 426 | |
| 427 | entry = (unsigned long)madt; |
| 428 | madt_end = entry + madt->header.length; |
| 429 | |
| 430 | /* Parse all entries looking for a match. */ |
| 431 | |
| 432 | entry += sizeof(struct acpi_table_madt); |
| 433 | while (entry + sizeof(struct acpi_subtable_header) < madt_end) { |
| 434 | struct acpi_subtable_header *header = |
| 435 | (struct acpi_subtable_header *)entry; |
| 436 | if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) { |
| 437 | if (map_lapic_id(header, acpi_id, &apic_id)) |
| 438 | break; |
| 439 | } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) { |
| 440 | if (map_lsapic_id(header, acpi_id, &apic_id)) |
| 441 | break; |
| 442 | } |
| 443 | entry += header->length; |
| 444 | } |
| 445 | return apic_id; |
| 446 | } |
| 447 | |
| 448 | static int map_mat_entry(acpi_handle handle, u32 acpi_id) |
| 449 | { |
| 450 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 451 | union acpi_object *obj; |
| 452 | struct acpi_subtable_header *header; |
| 453 | int apic_id = -1; |
| 454 | |
| 455 | if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer))) |
| 456 | goto exit; |
| 457 | |
| 458 | if (!buffer.length || !buffer.pointer) |
| 459 | goto exit; |
| 460 | |
| 461 | obj = buffer.pointer; |
| 462 | if (obj->type != ACPI_TYPE_BUFFER || |
| 463 | obj->buffer.length < sizeof(struct acpi_subtable_header)) { |
| 464 | goto exit; |
| 465 | } |
| 466 | |
| 467 | header = (struct acpi_subtable_header *)obj->buffer.pointer; |
| 468 | if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) { |
| 469 | map_lapic_id(header, acpi_id, &apic_id); |
| 470 | } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) { |
| 471 | map_lsapic_id(header, acpi_id, &apic_id); |
| 472 | } |
| 473 | |
| 474 | exit: |
| 475 | if (buffer.pointer) |
| 476 | kfree(buffer.pointer); |
| 477 | return apic_id; |
| 478 | } |
| 479 | |
Alexey Starikovskiy | 11bf04c | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 480 | static int get_cpu_id(acpi_handle handle, u32 acpi_id) |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 481 | { |
Len Brown | 4a35a46 | 2005-09-03 12:40:06 -0400 | [diff] [blame] | 482 | int i; |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 483 | int apic_id = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 485 | apic_id = map_mat_entry(handle, acpi_id); |
| 486 | if (apic_id == -1) |
| 487 | apic_id = map_madt_entry(acpi_id); |
| 488 | if (apic_id == -1) |
| 489 | return apic_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 491 | for (i = 0; i < NR_CPUS; ++i) { |
Len Brown | 4a35a46 | 2005-09-03 12:40:06 -0400 | [diff] [blame] | 492 | if (arch_cpu_to_apicid[i] == apic_id) |
| 493 | return i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
| 495 | return -1; |
| 496 | } |
| 497 | #endif |
| 498 | |
| 499 | /* -------------------------------------------------------------------------- |
| 500 | Driver Interface |
| 501 | -------------------------------------------------------------------------- */ |
| 502 | |
Alexey Starikovskiy | 11bf04c | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 503 | static int acpi_processor_get_info(struct acpi_processor *pr, unsigned has_uid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 505 | acpi_status status = 0; |
| 506 | union acpi_object object = { 0 }; |
| 507 | struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; |
Ashok Raj | df42baa | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 508 | int cpu_index; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 509 | static int cpu0_initialized; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
| 512 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 513 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | if (num_online_cpus() > 1) |
| 516 | errata.smp = TRUE; |
| 517 | |
| 518 | acpi_processor_errata(pr); |
| 519 | |
| 520 | /* |
| 521 | * Check to see if we have bus mastering arbitration control. This |
| 522 | * is required for proper C3 usage (to maintain cache coherency). |
| 523 | */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 524 | if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | pr->flags.bm_control = 1; |
| 526 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 527 | "Bus mastering arbitration control present\n")); |
| 528 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 530 | "No bus mastering arbitration control\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Alexey Starikovskiy | 11bf04c | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 532 | /* Check if it is a Device with HID and UID */ |
| 533 | if (has_uid) { |
| 534 | unsigned long value; |
| 535 | status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID, |
| 536 | NULL, &value); |
| 537 | if (ACPI_FAILURE(status)) { |
| 538 | printk(KERN_ERR PREFIX "Evaluating processor _UID\n"); |
| 539 | return -ENODEV; |
| 540 | } |
| 541 | pr->acpi_id = value; |
| 542 | } else { |
| 543 | /* |
| 544 | * Evalute the processor object. Note that it is common on SMP to |
| 545 | * have the first (boot) processor with a valid PBLK address while |
| 546 | * all others have a NULL address. |
| 547 | */ |
| 548 | status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer); |
| 549 | if (ACPI_FAILURE(status)) { |
| 550 | printk(KERN_ERR PREFIX "Evaluating processor object\n"); |
| 551 | return -ENODEV; |
| 552 | } |
| 553 | |
| 554 | /* |
| 555 | * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP. |
| 556 | * >>> 'acpi_get_processor_id(acpi_id, &id)' in arch/xxx/acpi.c |
| 557 | */ |
| 558 | pr->acpi_id = object.processor.proc_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
Alexey Starikovskiy | 11bf04c | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 560 | cpu_index = get_cpu_id(pr->handle, pr->acpi_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 562 | /* Handle UP system running SMP kernel, with no LAPIC in MADT */ |
Ashok Raj | df42baa | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 563 | if (!cpu0_initialized && (cpu_index == -1) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 564 | (num_online_cpus() == 1)) { |
| 565 | cpu_index = 0; |
| 566 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 568 | cpu0_initialized = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 570 | pr->id = cpu_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 572 | /* |
| 573 | * Extra Processor objects may be enumerated on MP systems with |
| 574 | * less than the max # of CPUs. They should be ignored _iff |
| 575 | * they are physically not present. |
| 576 | */ |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 577 | if (pr->id == -1) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 578 | if (ACPI_FAILURE |
| 579 | (acpi_processor_hotadd_init(pr->handle, &pr->id))) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 580 | return -ENODEV; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 581 | } |
| 582 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
| 584 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 585 | pr->acpi_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
| 587 | if (!object.processor.pblk_address) |
| 588 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n")); |
| 589 | else if (object.processor.pblk_length != 6) |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 590 | printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n", |
| 591 | object.processor.pblk_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | else { |
| 593 | pr->throttling.address = object.processor.pblk_address; |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 594 | pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset; |
| 595 | pr->throttling.duty_width = acpi_gbl_FADT.duty_width; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
| 597 | pr->pblk = object.processor.pblk_address; |
| 598 | |
| 599 | /* |
| 600 | * We don't care about error returns - we just try to mark |
| 601 | * these reserved so that nobody else is confused into thinking |
| 602 | * that this region might be unused.. |
| 603 | * |
| 604 | * (In particular, allocating the IO range for Cardbus) |
| 605 | */ |
| 606 | request_region(pr->throttling.address, 6, "ACPI CPU throttle"); |
| 607 | } |
| 608 | |
| 609 | #ifdef CONFIG_CPU_FREQ |
| 610 | acpi_processor_ppc_has_changed(pr); |
| 611 | #endif |
| 612 | acpi_processor_get_throttling_info(pr); |
| 613 | acpi_processor_get_limit_info(pr); |
| 614 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 615 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Venkatesh Pallipadi | cd8e2b4 | 2005-10-21 19:22:00 -0400 | [diff] [blame] | 618 | static void *processor_device_array[NR_CPUS]; |
| 619 | |
Pierre Ossman | 7af8b66 | 2006-10-10 14:20:31 -0700 | [diff] [blame] | 620 | static int __cpuinit acpi_processor_start(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 622 | int result = 0; |
| 623 | acpi_status status = AE_OK; |
| 624 | struct acpi_processor *pr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
| 627 | pr = acpi_driver_data(device); |
| 628 | |
Alexey Starikovskiy | 11bf04c | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 629 | result = acpi_processor_get_info(pr, device->flags.unique_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | if (result) { |
| 631 | /* Processor is physically not present */ |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 632 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | BUG_ON((pr->id >= NR_CPUS) || (pr->id < 0)); |
| 636 | |
Venkatesh Pallipadi | cd8e2b4 | 2005-10-21 19:22:00 -0400 | [diff] [blame] | 637 | /* |
| 638 | * Buggy BIOS check |
| 639 | * ACPI id of processors can be reported wrongly by the BIOS. |
| 640 | * Don't trust it blindly |
| 641 | */ |
| 642 | if (processor_device_array[pr->id] != NULL && |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 643 | processor_device_array[pr->id] != device) { |
Len Brown | 0eacee5 | 2006-03-31 00:37:23 -0500 | [diff] [blame] | 644 | printk(KERN_WARNING "BIOS reported wrong ACPI id" |
| 645 | "for the processor\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 646 | return -ENODEV; |
Venkatesh Pallipadi | cd8e2b4 | 2005-10-21 19:22:00 -0400 | [diff] [blame] | 647 | } |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 648 | processor_device_array[pr->id] = device; |
Venkatesh Pallipadi | cd8e2b4 | 2005-10-21 19:22:00 -0400 | [diff] [blame] | 649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | processors[pr->id] = pr; |
| 651 | |
| 652 | result = acpi_processor_add_fs(device); |
| 653 | if (result) |
| 654 | goto end; |
| 655 | |
| 656 | status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 657 | acpi_processor_notify, pr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
Venkatesh Pallipadi | 05131ec | 2005-10-23 16:31:00 -0400 | [diff] [blame] | 659 | /* _PDC call should be done before doing anything else (if reqd.). */ |
| 660 | arch_acpi_processor_init_pdc(pr); |
| 661 | acpi_processor_set_pdc(pr); |
| 662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | acpi_processor_power_init(pr, device); |
| 664 | |
| 665 | if (pr->flags.throttling) { |
| 666 | printk(KERN_INFO PREFIX "%s [%s] (supports", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 667 | acpi_device_name(device), acpi_device_bid(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | printk(" %d throttling states", pr->throttling.state_count); |
| 669 | printk(")\n"); |
| 670 | } |
| 671 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 672 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 674 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 677 | static void acpi_processor_notify(acpi_handle handle, u32 event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 679 | struct acpi_processor *pr = data; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 680 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
| 683 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 684 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
| 686 | if (acpi_bus_get_device(pr->handle, &device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 687 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
| 689 | switch (event) { |
| 690 | case ACPI_PROCESSOR_NOTIFY_PERFORMANCE: |
| 691 | acpi_processor_ppc_has_changed(pr); |
| 692 | acpi_bus_generate_event(device, event, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 693 | pr->performance_platform_limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | break; |
| 695 | case ACPI_PROCESSOR_NOTIFY_POWER: |
| 696 | acpi_processor_cst_has_changed(pr); |
| 697 | acpi_bus_generate_event(device, event, 0); |
| 698 | break; |
| 699 | default: |
| 700 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 701 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | break; |
| 703 | } |
| 704 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 705 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 708 | static int acpi_processor_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 710 | struct acpi_processor *pr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
| 713 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 714 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 716 | pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 718 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
| 720 | pr->handle = device->handle; |
| 721 | strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME); |
| 722 | strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS); |
| 723 | acpi_driver_data(device) = pr; |
| 724 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 725 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 728 | static int acpi_processor_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 730 | acpi_status status = AE_OK; |
| 731 | struct acpi_processor *pr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
| 734 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 735 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 737 | pr = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
| 739 | if (pr->id >= NR_CPUS) { |
| 740 | kfree(pr); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 741 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | if (type == ACPI_BUS_REMOVAL_EJECT) { |
| 745 | if (acpi_processor_handle_eject(pr)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 746 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | acpi_processor_power_exit(pr, device); |
| 750 | |
| 751 | status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 752 | acpi_processor_notify); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
| 754 | acpi_processor_remove_fs(device); |
| 755 | |
| 756 | processors[pr->id] = NULL; |
| 757 | |
| 758 | kfree(pr); |
| 759 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 760 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | #ifdef CONFIG_ACPI_HOTPLUG_CPU |
| 764 | /**************************************************************************** |
| 765 | * Acpi processor hotplug support * |
| 766 | ****************************************************************************/ |
| 767 | |
| 768 | static int is_processor_present(acpi_handle handle); |
| 769 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 770 | static int is_processor_present(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 772 | acpi_status status; |
| 773 | unsigned long sta = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
| 776 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); |
Bjorn Helgaas | a0bd4ac | 2007-04-25 14:17:39 -0400 | [diff] [blame] | 777 | if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 778 | ACPI_EXCEPTION((AE_INFO, status, "Processor Device is not present")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 779 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 781 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | static |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 785 | int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 787 | acpi_handle phandle; |
| 788 | struct acpi_device *pdev; |
| 789 | struct acpi_processor *pr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
| 792 | if (acpi_get_parent(handle, &phandle)) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 793 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | if (acpi_bus_get_device(phandle, &pdev)) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 797 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 801 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 804 | acpi_bus_start(*device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
| 806 | pr = acpi_driver_data(*device); |
| 807 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 808 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 810 | if ((pr->id >= 0) && (pr->id < NR_CPUS)) { |
Patrick Mochel | f883d9d | 2006-12-07 20:56:38 +0800 | [diff] [blame] | 811 | kobject_uevent(&(*device)->dev.kobj, KOBJ_ONLINE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 813 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 817 | acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 819 | struct acpi_processor *pr; |
| 820 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | int result; |
| 822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
| 824 | switch (event) { |
| 825 | case ACPI_NOTIFY_BUS_CHECK: |
| 826 | case ACPI_NOTIFY_DEVICE_CHECK: |
| 827 | printk("Processor driver received %s event\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 828 | (event == ACPI_NOTIFY_BUS_CHECK) ? |
| 829 | "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
| 831 | if (!is_processor_present(handle)) |
| 832 | break; |
| 833 | |
| 834 | if (acpi_bus_get_device(handle, &device)) { |
| 835 | result = acpi_processor_device_add(handle, &device); |
| 836 | if (result) |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 837 | printk(KERN_ERR PREFIX |
| 838 | "Unable to add the device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | break; |
| 840 | } |
| 841 | |
| 842 | pr = acpi_driver_data(device); |
| 843 | if (!pr) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 844 | printk(KERN_ERR PREFIX "Driver data is NULL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | break; |
| 846 | } |
| 847 | |
| 848 | if (pr->id >= 0 && (pr->id < NR_CPUS)) { |
Patrick Mochel | f883d9d | 2006-12-07 20:56:38 +0800 | [diff] [blame] | 849 | kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | break; |
| 851 | } |
| 852 | |
| 853 | result = acpi_processor_start(device); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 854 | if ((!result) && ((pr->id >= 0) && (pr->id < NR_CPUS))) { |
Patrick Mochel | f883d9d | 2006-12-07 20:56:38 +0800 | [diff] [blame] | 855 | kobject_uevent(&device->dev.kobj, KOBJ_ONLINE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | } else { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 857 | printk(KERN_ERR PREFIX "Device [%s] failed to start\n", |
| 858 | acpi_device_bid(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 860 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | case ACPI_NOTIFY_EJECT_REQUEST: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 862 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 863 | "received ACPI_NOTIFY_EJECT_REQUEST\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | |
| 865 | if (acpi_bus_get_device(handle, &device)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 866 | printk(KERN_ERR PREFIX |
| 867 | "Device don't exist, dropping EJECT\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | break; |
| 869 | } |
| 870 | pr = acpi_driver_data(device); |
| 871 | if (!pr) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 872 | printk(KERN_ERR PREFIX |
| 873 | "Driver data is NULL, dropping EJECT\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 874 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | if ((pr->id < NR_CPUS) && (cpu_present(pr->id))) |
Patrick Mochel | f883d9d | 2006-12-07 20:56:38 +0800 | [diff] [blame] | 878 | kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | break; |
| 880 | default: |
| 881 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 882 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | break; |
| 884 | } |
| 885 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 886 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | static acpi_status |
| 890 | processor_walk_namespace_cb(acpi_handle handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 891 | u32 lvl, void *context, void **rv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 893 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | int *action = context; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 895 | acpi_object_type type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
| 897 | status = acpi_get_type(handle, &type); |
| 898 | if (ACPI_FAILURE(status)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 899 | return (AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
| 901 | if (type != ACPI_TYPE_PROCESSOR) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 902 | return (AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 904 | switch (*action) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | case INSTALL_NOTIFY_HANDLER: |
| 906 | acpi_install_notify_handler(handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 907 | ACPI_SYSTEM_NOTIFY, |
| 908 | acpi_processor_hotplug_notify, |
| 909 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | break; |
| 911 | case UNINSTALL_NOTIFY_HANDLER: |
| 912 | acpi_remove_notify_handler(handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 913 | ACPI_SYSTEM_NOTIFY, |
| 914 | acpi_processor_hotplug_notify); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | break; |
| 916 | default: |
| 917 | break; |
| 918 | } |
| 919 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 920 | return (AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 923 | static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | if (!is_processor_present(handle)) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 927 | return AE_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | if (acpi_map_lsapic(handle, p_cpu)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 931 | return AE_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | |
| 933 | if (arch_register_cpu(*p_cpu)) { |
| 934 | acpi_unmap_lsapic(*p_cpu); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 935 | return AE_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | } |
| 937 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 938 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 941 | static int acpi_processor_handle_eject(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | { |
| 943 | if (cpu_online(pr->id)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 944 | return (-EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | } |
| 946 | arch_unregister_cpu(pr->id); |
| 947 | acpi_unmap_lsapic(pr->id); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 948 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | } |
| 950 | #else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 951 | static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | { |
| 953 | return AE_ERROR; |
| 954 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 955 | static int acpi_processor_handle_eject(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 957 | return (-EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | } |
| 959 | #endif |
| 960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | static |
| 962 | void acpi_processor_install_hotplug_notify(void) |
| 963 | { |
| 964 | #ifdef CONFIG_ACPI_HOTPLUG_CPU |
| 965 | int action = INSTALL_NOTIFY_HANDLER; |
| 966 | acpi_walk_namespace(ACPI_TYPE_PROCESSOR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 967 | ACPI_ROOT_OBJECT, |
| 968 | ACPI_UINT32_MAX, |
| 969 | processor_walk_namespace_cb, &action, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | #endif |
| 971 | } |
| 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | static |
| 974 | void acpi_processor_uninstall_hotplug_notify(void) |
| 975 | { |
| 976 | #ifdef CONFIG_ACPI_HOTPLUG_CPU |
| 977 | int action = UNINSTALL_NOTIFY_HANDLER; |
| 978 | acpi_walk_namespace(ACPI_TYPE_PROCESSOR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 979 | ACPI_ROOT_OBJECT, |
| 980 | ACPI_UINT32_MAX, |
| 981 | processor_walk_namespace_cb, &action, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | #endif |
| 983 | } |
| 984 | |
| 985 | /* |
| 986 | * We keep the driver loaded even when ACPI is not running. |
| 987 | * This is needed for the powernow-k8 driver, that works even without |
| 988 | * ACPI, but needs symbols from this driver |
| 989 | */ |
| 990 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 991 | static int __init acpi_processor_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 993 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
| 996 | memset(&processors, 0, sizeof(processors)); |
| 997 | memset(&errata, 0, sizeof(errata)); |
| 998 | |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 999 | #ifdef CONFIG_SMP |
| 1000 | if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0, |
| 1001 | (struct acpi_table_header **)&madt))) |
Randy Dunlap | 70c0846 | 2007-02-13 16:11:36 -0800 | [diff] [blame] | 1002 | madt = NULL; |
Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 1003 | #endif |
| 1004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); |
| 1006 | if (!acpi_processor_dir) |
Akinobu Mita | 83822fc | 2006-12-19 12:56:10 -0800 | [diff] [blame] | 1007 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | acpi_processor_dir->owner = THIS_MODULE; |
| 1009 | |
| 1010 | result = acpi_bus_register_driver(&acpi_processor_driver); |
| 1011 | if (result < 0) { |
| 1012 | remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); |
Akinobu Mita | 83822fc | 2006-12-19 12:56:10 -0800 | [diff] [blame] | 1013 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | acpi_processor_install_hotplug_notify(); |
| 1017 | |
| 1018 | acpi_thermal_cpufreq_init(); |
| 1019 | |
| 1020 | acpi_processor_ppc_init(); |
| 1021 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1022 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1025 | static void __exit acpi_processor_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
| 1028 | acpi_processor_ppc_exit(); |
| 1029 | |
| 1030 | acpi_thermal_cpufreq_exit(); |
| 1031 | |
| 1032 | acpi_processor_uninstall_hotplug_notify(); |
| 1033 | |
| 1034 | acpi_bus_unregister_driver(&acpi_processor_driver); |
| 1035 | |
| 1036 | remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); |
| 1037 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1038 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | module_init(acpi_processor_init); |
| 1042 | module_exit(acpi_processor_exit); |
| 1043 | |
| 1044 | EXPORT_SYMBOL(acpi_processor_set_thermal_limit); |
| 1045 | |
| 1046 | MODULE_ALIAS("processor"); |