| 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> | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 47 | #include <linux/cpuidle.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 48 | #include <linux/slab.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 63 | #define PREFIX "ACPI: " | 
|  | 64 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define ACPI_PROCESSOR_CLASS		"processor" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 
| Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 72 | #define ACPI_PROCESSOR_NOTIFY_THROTTLING	0x82 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 |  | 
|  | 74 | #define ACPI_PROCESSOR_LIMIT_USER	0 | 
|  | 75 | #define ACPI_PROCESSOR_LIMIT_THERMAL	1 | 
|  | 76 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #define _COMPONENT		ACPI_PROCESSOR_COMPONENT | 
| Alex Chiang | 0131aa3 | 2010-02-22 12:11:08 -0700 | [diff] [blame] | 78 | ACPI_MODULE_NAME("processor_driver"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 |  | 
| Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 80 | MODULE_AUTHOR("Paul Diefenbaugh"); | 
| Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 81 | MODULE_DESCRIPTION("ACPI Processor Driver"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | MODULE_LICENSE("GPL"); | 
|  | 83 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | static int acpi_processor_add(struct acpi_device *device); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | static int acpi_processor_remove(struct acpi_device *device, int type); | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 86 | #ifdef CONFIG_ACPI_PROCFS | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | static int acpi_processor_info_open_fs(struct inode *inode, struct file *file); | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 88 | #endif | 
| Bjorn Helgaas | 7ec0a72 | 2009-03-30 17:48:24 +0000 | [diff] [blame] | 89 | static void acpi_processor_notify(struct acpi_device *device, u32 event); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu); | 
|  | 91 | static int acpi_processor_handle_eject(struct acpi_processor *pr); | 
| Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 92 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 |  | 
| Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 94 | static const struct acpi_device_id processor_device_ids[] = { | 
| Myron Stowe | ad93a76 | 2008-11-04 14:52:55 -0700 | [diff] [blame] | 95 | {ACPI_PROCESSOR_OBJECT_HID, 0}, | 
| Bjorn Helgaas | 9eccbc2 | 2009-04-27 16:33:46 -0600 | [diff] [blame] | 96 | {"ACPI0007", 0}, | 
| Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 97 | {"", 0}, | 
|  | 98 | }; | 
|  | 99 | MODULE_DEVICE_TABLE(acpi, processor_device_ids); | 
|  | 100 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | static struct acpi_driver acpi_processor_driver = { | 
| Len Brown | c2b6705b | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 102 | .name = "processor", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 103 | .class = ACPI_PROCESSOR_CLASS, | 
| Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 104 | .ids = processor_device_ids, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | .ops = { | 
|  | 106 | .add = acpi_processor_add, | 
|  | 107 | .remove = acpi_processor_remove, | 
| Thomas Gleixner | b04e7bd | 2007-09-22 22:29:05 +0000 | [diff] [blame] | 108 | .suspend = acpi_processor_suspend, | 
|  | 109 | .resume = acpi_processor_resume, | 
| Bjorn Helgaas | 7ec0a72 | 2009-03-30 17:48:24 +0000 | [diff] [blame] | 110 | .notify = acpi_processor_notify, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | }, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | }; | 
|  | 113 |  | 
|  | 114 | #define INSTALL_NOTIFY_HANDLER		1 | 
|  | 115 | #define UNINSTALL_NOTIFY_HANDLER	2 | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 116 | #ifdef CONFIG_ACPI_PROCFS | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 117 | static const struct file_operations acpi_processor_info_fops = { | 
| Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 118 | .owner = THIS_MODULE, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | .open = acpi_processor_info_open_fs, | 
|  | 120 | .read = seq_read, | 
|  | 121 | .llseek = seq_lseek, | 
|  | 122 | .release = single_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | }; | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 124 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 |  | 
| Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 126 | DEFINE_PER_CPU(struct acpi_processor *, processors); | 
| Naga Chumbalkar | 0f1d683 | 2009-12-17 20:18:27 +0000 | [diff] [blame] | 127 | EXPORT_PER_CPU_SYMBOL(processors); | 
|  | 128 |  | 
| Andreas Mohr | 9f22271 | 2006-06-23 02:04:27 -0700 | [diff] [blame] | 129 | struct acpi_processor_errata errata __read_mostly; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | /* -------------------------------------------------------------------------- | 
|  | 132 | Errata Handling | 
|  | 133 | -------------------------------------------------------------------------- */ | 
|  | 134 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | static int acpi_processor_errata_piix4(struct pci_dev *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | u8 value1 = 0; | 
|  | 138 | u8 value2 = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 |  | 
|  | 141 | if (!dev) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 142 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 |  | 
|  | 144 | /* | 
|  | 145 | * Note that 'dev' references the PIIX4 ACPI Controller. | 
|  | 146 | */ | 
|  | 147 |  | 
| Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 148 | switch (dev->revision) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | case 0: | 
|  | 150 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n")); | 
|  | 151 | break; | 
|  | 152 | case 1: | 
|  | 153 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n")); | 
|  | 154 | break; | 
|  | 155 | case 2: | 
|  | 156 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n")); | 
|  | 157 | break; | 
|  | 158 | case 3: | 
|  | 159 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n")); | 
|  | 160 | break; | 
|  | 161 | default: | 
|  | 162 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n")); | 
|  | 163 | break; | 
|  | 164 | } | 
|  | 165 |  | 
| Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 166 | switch (dev->revision) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 |  | 
|  | 168 | case 0:		/* PIIX4 A-step */ | 
|  | 169 | case 1:		/* PIIX4 B-step */ | 
|  | 170 | /* | 
|  | 171 | * See specification changes #13 ("Manual Throttle Duty Cycle") | 
|  | 172 | * and #14 ("Enabling and Disabling Manual Throttle"), plus | 
|  | 173 | * erratum #5 ("STPCLK# Deassertion Time") from the January | 
|  | 174 | * 2002 PIIX4 specification update.  Applies to only older | 
|  | 175 | * PIIX4 models. | 
|  | 176 | */ | 
|  | 177 | errata.piix4.throttle = 1; | 
|  | 178 |  | 
|  | 179 | case 2:		/* PIIX4E */ | 
|  | 180 | case 3:		/* PIIX4M */ | 
|  | 181 | /* | 
|  | 182 | * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA | 
|  | 183 | * Livelock") from the January 2002 PIIX4 specification update. | 
|  | 184 | * Applies to all PIIX4 models. | 
|  | 185 | */ | 
|  | 186 |  | 
|  | 187 | /* | 
|  | 188 | * BM-IDE | 
|  | 189 | * ------ | 
|  | 190 | * Find the PIIX4 IDE Controller and get the Bus Master IDE | 
|  | 191 | * Status register address.  We'll use this later to read | 
|  | 192 | * each IDE controller's DMA status to make sure we catch all | 
|  | 193 | * DMA activity. | 
|  | 194 | */ | 
|  | 195 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | PCI_DEVICE_ID_INTEL_82371AB, | 
|  | 197 | PCI_ANY_ID, PCI_ANY_ID, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (dev) { | 
|  | 199 | errata.piix4.bmisx = pci_resource_start(dev, 4); | 
|  | 200 | pci_dev_put(dev); | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | /* | 
|  | 204 | * Type-F DMA | 
|  | 205 | * ---------- | 
|  | 206 | * Find the PIIX4 ISA Controller and read the Motherboard | 
|  | 207 | * DMA controller's status to see if Type-F (Fast) DMA mode | 
|  | 208 | * is enabled (bit 7) on either channel.  Note that we'll | 
|  | 209 | * disable C3 support if this is enabled, as some legacy | 
|  | 210 | * devices won't operate well if fast DMA is disabled. | 
|  | 211 | */ | 
|  | 212 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | PCI_DEVICE_ID_INTEL_82371AB_0, | 
|  | 214 | PCI_ANY_ID, PCI_ANY_ID, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | if (dev) { | 
|  | 216 | pci_read_config_byte(dev, 0x76, &value1); | 
|  | 217 | pci_read_config_byte(dev, 0x77, &value2); | 
|  | 218 | if ((value1 & 0x80) || (value2 & 0x80)) | 
|  | 219 | errata.piix4.fdma = 1; | 
|  | 220 | pci_dev_put(dev); | 
|  | 221 | } | 
|  | 222 |  | 
|  | 223 | break; | 
|  | 224 | } | 
|  | 225 |  | 
|  | 226 | if (errata.piix4.bmisx) | 
|  | 227 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 228 | "Bus master activity detection (BM-IDE) erratum enabled\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | if (errata.piix4.fdma) | 
|  | 230 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 231 | "Type-F DMA livelock erratum (C3 disabled)\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 233 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } | 
|  | 235 |  | 
| Adrian Bunk | 8713cbe | 2005-09-02 17:16:48 -0400 | [diff] [blame] | 236 | static int acpi_processor_errata(struct acpi_processor *pr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 238 | int result = 0; | 
|  | 239 | struct pci_dev *dev = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 |  | 
|  | 242 | if (!pr) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 243 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 |  | 
|  | 245 | /* | 
|  | 246 | * PIIX4 | 
|  | 247 | */ | 
|  | 248 | dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 249 | PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID, | 
|  | 250 | PCI_ANY_ID, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | if (dev) { | 
|  | 252 | result = acpi_processor_errata_piix4(dev); | 
|  | 253 | pci_dev_put(dev); | 
|  | 254 | } | 
|  | 255 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 256 | return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } | 
|  | 258 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | /* -------------------------------------------------------------------------- | 
|  | 260 | FS Interface (/proc) | 
|  | 261 | -------------------------------------------------------------------------- */ | 
|  | 262 |  | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 263 | #ifdef CONFIG_ACPI_PROCFS | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 264 | static struct proc_dir_entry *acpi_processor_dir = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 |  | 
|  | 266 | static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset) | 
|  | 267 | { | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 268 | struct acpi_processor *pr = seq->private; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 |  | 
|  | 271 | if (!pr) | 
|  | 272 | goto end; | 
|  | 273 |  | 
|  | 274 | seq_printf(seq, "processor id:            %d\n" | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 275 | "acpi id:                 %d\n" | 
|  | 276 | "bus mastering control:   %s\n" | 
|  | 277 | "power management:        %s\n" | 
|  | 278 | "throttling control:      %s\n" | 
|  | 279 | "limit interface:         %s\n", | 
|  | 280 | pr->id, | 
|  | 281 | pr->acpi_id, | 
|  | 282 | pr->flags.bm_control ? "yes" : "no", | 
|  | 283 | pr->flags.power ? "yes" : "no", | 
|  | 284 | pr->flags.throttling ? "yes" : "no", | 
|  | 285 | pr->flags.limit ? "yes" : "no"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 287 | end: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 288 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } | 
|  | 290 |  | 
|  | 291 | static int acpi_processor_info_open_fs(struct inode *inode, struct file *file) | 
|  | 292 | { | 
|  | 293 | return single_open(file, acpi_processor_info_seq_show, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | PDE(inode)->data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } | 
|  | 296 |  | 
| Thomas Renninger | bf8b454 | 2009-10-26 17:44:18 +0100 | [diff] [blame] | 297 | static int __cpuinit acpi_processor_add_fs(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | struct proc_dir_entry *entry = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 |  | 
|  | 302 | if (!acpi_device_dir(device)) { | 
|  | 303 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 304 | acpi_processor_dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | if (!acpi_device_dir(device)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 306 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 |  | 
|  | 309 | /* 'info' [R] */ | 
| Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 310 | entry = proc_create_data(ACPI_PROCESSOR_FILE_INFO, | 
|  | 311 | S_IRUGO, acpi_device_dir(device), | 
|  | 312 | &acpi_processor_info_fops, | 
|  | 313 | acpi_driver_data(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | if (!entry) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 315 | return -EIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 |  | 
|  | 317 | /* 'throttling' [R/W] */ | 
| Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 318 | entry = proc_create_data(ACPI_PROCESSOR_FILE_THROTTLING, | 
|  | 319 | S_IFREG | S_IRUGO | S_IWUSR, | 
|  | 320 | acpi_device_dir(device), | 
|  | 321 | &acpi_processor_throttling_fops, | 
|  | 322 | acpi_driver_data(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | if (!entry) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 324 | return -EIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 |  | 
|  | 326 | /* 'limit' [R/W] */ | 
| Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 327 | entry = proc_create_data(ACPI_PROCESSOR_FILE_LIMIT, | 
|  | 328 | S_IFREG | S_IRUGO | S_IWUSR, | 
|  | 329 | acpi_device_dir(device), | 
|  | 330 | &acpi_processor_limit_fops, | 
|  | 331 | acpi_driver_data(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | if (!entry) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 333 | return -EIO; | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 334 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 336 | static int acpi_processor_remove_fs(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 |  | 
|  | 339 | if (acpi_device_dir(device)) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | remove_proc_entry(ACPI_PROCESSOR_FILE_INFO, | 
|  | 341 | acpi_device_dir(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 343 | acpi_device_dir(device)); | 
|  | 344 | remove_proc_entry(ACPI_PROCESSOR_FILE_LIMIT, | 
|  | 345 | acpi_device_dir(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | remove_proc_entry(acpi_device_bid(device), acpi_processor_dir); | 
|  | 347 | acpi_device_dir(device) = NULL; | 
|  | 348 | } | 
|  | 349 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 350 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 352 | #else | 
|  | 353 | static inline int acpi_processor_add_fs(struct acpi_device *device) | 
|  | 354 | { | 
|  | 355 | return 0; | 
|  | 356 | } | 
|  | 357 | static inline int acpi_processor_remove_fs(struct acpi_device *device) | 
|  | 358 | { | 
|  | 359 | return 0; | 
|  | 360 | } | 
|  | 361 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | /* -------------------------------------------------------------------------- | 
|  | 364 | Driver Interface | 
|  | 365 | -------------------------------------------------------------------------- */ | 
|  | 366 |  | 
| Myron Stowe | b26e928 | 2008-11-04 14:53:00 -0700 | [diff] [blame] | 367 | static int acpi_processor_get_info(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 369 | acpi_status status = 0; | 
|  | 370 | union acpi_object object = { 0 }; | 
|  | 371 | struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; | 
| Myron Stowe | b26e928 | 2008-11-04 14:53:00 -0700 | [diff] [blame] | 372 | struct acpi_processor *pr; | 
|  | 373 | int cpu_index, device_declaration = 0; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | static int cpu0_initialized; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 |  | 
| Myron Stowe | b26e928 | 2008-11-04 14:53:00 -0700 | [diff] [blame] | 376 | pr = acpi_driver_data(device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | if (!pr) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 378 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 |  | 
|  | 380 | if (num_online_cpus() > 1) | 
|  | 381 | errata.smp = TRUE; | 
|  | 382 |  | 
|  | 383 | acpi_processor_errata(pr); | 
|  | 384 |  | 
|  | 385 | /* | 
|  | 386 | * Check to see if we have bus mastering arbitration control.  This | 
|  | 387 | * is required for proper C3 usage (to maintain cache coherency). | 
|  | 388 | */ | 
| Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 389 | 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] | 390 | pr->flags.bm_control = 1; | 
|  | 391 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | "Bus mastering arbitration control present\n")); | 
|  | 393 | } else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 395 | "No bus mastering arbitration control\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 |  | 
| Bjorn Helgaas | 6cc73b4 | 2009-04-27 16:33:41 -0600 | [diff] [blame] | 397 | if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) { | 
|  | 398 | /* Declared with "Processor" statement; match ProcessorID */ | 
|  | 399 | status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer); | 
|  | 400 | if (ACPI_FAILURE(status)) { | 
|  | 401 | printk(KERN_ERR PREFIX "Evaluating processor object\n"); | 
|  | 402 | return -ENODEV; | 
|  | 403 | } | 
|  | 404 |  | 
|  | 405 | /* | 
|  | 406 | * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP. | 
|  | 407 | *      >>> 'acpi_get_processor_id(acpi_id, &id)' in | 
|  | 408 | *      arch/xxx/acpi.c | 
|  | 409 | */ | 
|  | 410 | pr->acpi_id = object.processor.proc_id; | 
|  | 411 | } else { | 
| Myron Stowe | b26e928 | 2008-11-04 14:53:00 -0700 | [diff] [blame] | 412 | /* | 
|  | 413 | * Declared with "Device" statement; match _UID. | 
|  | 414 | * Note that we don't handle string _UIDs yet. | 
|  | 415 | */ | 
| Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 416 | unsigned long long value; | 
| Alexey Starikovskiy | 11bf04c | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 417 | status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID, | 
|  | 418 | NULL, &value); | 
|  | 419 | if (ACPI_FAILURE(status)) { | 
| Myron Stowe | b26e928 | 2008-11-04 14:53:00 -0700 | [diff] [blame] | 420 | printk(KERN_ERR PREFIX | 
|  | 421 | "Evaluating processor _UID [%#x]\n", status); | 
| Alexey Starikovskiy | 11bf04c | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 422 | return -ENODEV; | 
|  | 423 | } | 
| Myron Stowe | b26e928 | 2008-11-04 14:53:00 -0700 | [diff] [blame] | 424 | device_declaration = 1; | 
| Alexey Starikovskiy | 11bf04c | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 425 | pr->acpi_id = value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } | 
| Alex Chiang | 2e9d5e4 | 2010-02-22 12:11:19 -0700 | [diff] [blame] | 427 | cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 429 | /* Handle UP system running SMP kernel, with no LAPIC in MADT */ | 
| Ashok Raj | df42baa | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 430 | if (!cpu0_initialized && (cpu_index == -1) && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 431 | (num_online_cpus() == 1)) { | 
|  | 432 | cpu_index = 0; | 
|  | 433 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 435 | cpu0_initialized = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 437 | pr->id = cpu_index; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 439 | /* | 
|  | 440 | *  Extra Processor objects may be enumerated on MP systems with | 
|  | 441 | *  less than the max # of CPUs. They should be ignored _iff | 
|  | 442 | *  they are physically not present. | 
|  | 443 | */ | 
| Alexey Starikovskiy | f18c5a0 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 444 | if (pr->id == -1) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 445 | if (ACPI_FAILURE | 
|  | 446 | (acpi_processor_hotadd_init(pr->handle, &pr->id))) { | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 447 | return -ENODEV; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 448 | } | 
|  | 449 | } | 
| Zhao Yakui | 7a04b84 | 2009-06-24 11:46:44 +0800 | [diff] [blame] | 450 | /* | 
|  | 451 | * On some boxes several processors use the same processor bus id. | 
|  | 452 | * But they are located in different scope. For example: | 
|  | 453 | * \_SB.SCK0.CPU0 | 
|  | 454 | * \_SB.SCK1.CPU0 | 
|  | 455 | * Rename the processor device bus id. And the new bus id will be | 
|  | 456 | * generated as the following format: | 
|  | 457 | * CPU+CPU ID. | 
|  | 458 | */ | 
|  | 459 | sprintf(acpi_device_bid(device), "CPU%X", pr->id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 461 | pr->acpi_id)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 |  | 
|  | 463 | if (!object.processor.pblk_address) | 
|  | 464 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n")); | 
|  | 465 | else if (object.processor.pblk_length != 6) | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 466 | printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n", | 
|  | 467 | object.processor.pblk_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | else { | 
|  | 469 | pr->throttling.address = object.processor.pblk_address; | 
| Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 470 | pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset; | 
|  | 471 | pr->throttling.duty_width = acpi_gbl_FADT.duty_width; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 |  | 
|  | 473 | pr->pblk = object.processor.pblk_address; | 
|  | 474 |  | 
|  | 475 | /* | 
|  | 476 | * We don't care about error returns - we just try to mark | 
|  | 477 | * these reserved so that nobody else is confused into thinking | 
|  | 478 | * that this region might be unused.. | 
|  | 479 | * | 
|  | 480 | * (In particular, allocating the IO range for Cardbus) | 
|  | 481 | */ | 
|  | 482 | request_region(pr->throttling.address, 6, "ACPI CPU throttle"); | 
|  | 483 | } | 
|  | 484 |  | 
| Alex Chiang | fe086a7 | 2008-04-29 15:05:29 -0700 | [diff] [blame] | 485 | /* | 
|  | 486 | * If ACPI describes a slot number for this CPU, we can use it | 
|  | 487 | * ensure we get the right value in the "physical id" field | 
|  | 488 | * of /proc/cpuinfo | 
|  | 489 | */ | 
|  | 490 | status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer); | 
|  | 491 | if (ACPI_SUCCESS(status)) | 
|  | 492 | arch_fix_phys_package_id(pr->id, object.integer.value); | 
|  | 493 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 494 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } | 
|  | 496 |  | 
| Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 497 | static DEFINE_PER_CPU(void *, processor_device_array); | 
| Venkatesh Pallipadi | cd8e2b4 | 2005-10-21 19:22:00 -0400 | [diff] [blame] | 498 |  | 
| Bjorn Helgaas | 7ec0a72 | 2009-03-30 17:48:24 +0000 | [diff] [blame] | 499 | static void acpi_processor_notify(struct acpi_device *device, u32 event) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | { | 
| Bjorn Helgaas | 7ec0a72 | 2009-03-30 17:48:24 +0000 | [diff] [blame] | 501 | struct acpi_processor *pr = acpi_driver_data(device); | 
| Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 502 | int saved; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 |  | 
|  | 504 | if (!pr) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 505 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | switch (event) { | 
|  | 508 | case ACPI_PROCESSOR_NOTIFY_PERFORMANCE: | 
| Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 509 | saved = pr->performance_platform_limit; | 
| Zhao Yakui | d81c45e | 2009-10-16 09:20:41 +0800 | [diff] [blame] | 510 | acpi_processor_ppc_has_changed(pr, 1); | 
| Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 511 | if (saved == pr->performance_platform_limit) | 
|  | 512 | break; | 
| Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 513 | acpi_bus_generate_proc_event(device, event, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | pr->performance_platform_limit); | 
| Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 515 | acpi_bus_generate_netlink_event(device->pnp.device_class, | 
| Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 516 | dev_name(&device->dev), event, | 
| Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 517 | pr->performance_platform_limit); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | break; | 
|  | 519 | case ACPI_PROCESSOR_NOTIFY_POWER: | 
|  | 520 | acpi_processor_cst_has_changed(pr); | 
| Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 521 | acpi_bus_generate_proc_event(device, event, 0); | 
| Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 522 | acpi_bus_generate_netlink_event(device->pnp.device_class, | 
| Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 523 | dev_name(&device->dev), event, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | break; | 
| Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 525 | case ACPI_PROCESSOR_NOTIFY_THROTTLING: | 
|  | 526 | acpi_processor_tstate_has_changed(pr); | 
| Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 527 | acpi_bus_generate_proc_event(device, event, 0); | 
| Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 528 | acpi_bus_generate_netlink_event(device->pnp.device_class, | 
| Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 529 | dev_name(&device->dev), event, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | default: | 
|  | 531 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 532 | "Unsupported event [0x%x]\n", event)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | break; | 
|  | 534 | } | 
|  | 535 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 536 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } | 
|  | 538 |  | 
| Venkatesh Pallipadi | 729c6ba | 2007-09-16 15:36:43 +0200 | [diff] [blame] | 539 | static int acpi_cpu_soft_notify(struct notifier_block *nfb, | 
|  | 540 | unsigned long action, void *hcpu) | 
|  | 541 | { | 
|  | 542 | unsigned int cpu = (unsigned long)hcpu; | 
| Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 543 | struct acpi_processor *pr = per_cpu(processors, cpu); | 
| Venkatesh Pallipadi | 729c6ba | 2007-09-16 15:36:43 +0200 | [diff] [blame] | 544 |  | 
|  | 545 | if (action == CPU_ONLINE && pr) { | 
| Zhao Yakui | d81c45e | 2009-10-16 09:20:41 +0800 | [diff] [blame] | 546 | acpi_processor_ppc_has_changed(pr, 0); | 
| Venkatesh Pallipadi | 729c6ba | 2007-09-16 15:36:43 +0200 | [diff] [blame] | 547 | acpi_processor_cst_has_changed(pr); | 
|  | 548 | acpi_processor_tstate_has_changed(pr); | 
|  | 549 | } | 
|  | 550 | return NOTIFY_OK; | 
|  | 551 | } | 
|  | 552 |  | 
|  | 553 | static struct notifier_block acpi_cpu_notifier = | 
|  | 554 | { | 
|  | 555 | .notifier_call = acpi_cpu_soft_notify, | 
|  | 556 | }; | 
|  | 557 |  | 
| Rakib Mullick | 941b10f | 2009-11-05 16:51:40 -0500 | [diff] [blame] | 558 | static int __cpuinit acpi_processor_add(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 560 | struct acpi_processor *pr = NULL; | 
| Bjorn Helgaas | 970b049 | 2009-06-22 20:41:19 +0000 | [diff] [blame] | 561 | int result = 0; | 
|  | 562 | struct sys_device *sysdev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 |  | 
| Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 564 | pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | if (!pr) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 566 | return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 |  | 
| Yinghai Lu | eaa9584 | 2009-06-06 14:51:36 -0700 | [diff] [blame] | 568 | if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) { | 
| Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 569 | kfree(pr); | 
|  | 570 | return -ENOMEM; | 
|  | 571 | } | 
|  | 572 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | pr->handle = device->handle; | 
|  | 574 | strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME); | 
|  | 575 | strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS); | 
| Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 576 | device->driver_data = pr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | result = acpi_processor_get_info(device); | 
|  | 579 | if (result) { | 
|  | 580 | /* Processor is physically not present */ | 
|  | 581 | return 0; | 
|  | 582 | } | 
|  | 583 |  | 
|  | 584 | BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0)); | 
|  | 585 |  | 
|  | 586 | /* | 
|  | 587 | * Buggy BIOS check | 
|  | 588 | * ACPI id of processors can be reported wrongly by the BIOS. | 
|  | 589 | * Don't trust it blindly | 
|  | 590 | */ | 
|  | 591 | if (per_cpu(processor_device_array, pr->id) != NULL && | 
|  | 592 | per_cpu(processor_device_array, pr->id) != device) { | 
|  | 593 | printk(KERN_WARNING "BIOS reported wrong ACPI id " | 
|  | 594 | "for the processor\n"); | 
| Bjorn Helgaas | 970b049 | 2009-06-22 20:41:19 +0000 | [diff] [blame] | 595 | result = -ENODEV; | 
|  | 596 | goto err_free_cpumask; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } | 
|  | 598 | per_cpu(processor_device_array, pr->id) = device; | 
|  | 599 |  | 
|  | 600 | per_cpu(processors, pr->id) = pr; | 
|  | 601 |  | 
|  | 602 | result = acpi_processor_add_fs(device); | 
|  | 603 | if (result) | 
| Bjorn Helgaas | 970b049 | 2009-06-22 20:41:19 +0000 | [diff] [blame] | 604 | goto err_free_cpumask; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 |  | 
|  | 606 | sysdev = get_cpu_sysdev(pr->id); | 
| Bjorn Helgaas | d4e0526 | 2009-06-22 20:41:09 +0000 | [diff] [blame] | 607 | if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) { | 
|  | 608 | result = -EFAULT; | 
|  | 609 | goto err_remove_fs; | 
|  | 610 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | #ifdef CONFIG_CPU_FREQ | 
| Zhao Yakui | d81c45e | 2009-10-16 09:20:41 +0800 | [diff] [blame] | 613 | acpi_processor_ppc_has_changed(pr, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | #endif | 
|  | 615 | acpi_processor_get_throttling_info(pr); | 
|  | 616 | acpi_processor_get_limit_info(pr); | 
|  | 617 |  | 
|  | 618 |  | 
| Len Brown | 541adf7 | 2010-05-22 17:03:29 -0400 | [diff] [blame] | 619 | if (cpuidle_get_driver() == &acpi_idle_driver) | 
|  | 620 | acpi_processor_power_init(pr, device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 |  | 
|  | 622 | pr->cdev = thermal_cooling_device_register("Processor", device, | 
|  | 623 | &processor_cooling_ops); | 
|  | 624 | if (IS_ERR(pr->cdev)) { | 
|  | 625 | result = PTR_ERR(pr->cdev); | 
| Bjorn Helgaas | d4e0526 | 2009-06-22 20:41:09 +0000 | [diff] [blame] | 626 | goto err_power_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } | 
|  | 628 |  | 
| Mike Travis | 13c4115 | 2009-12-14 13:38:30 -0800 | [diff] [blame] | 629 | dev_dbg(&device->dev, "registered as cooling_device%d\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | pr->cdev->id); | 
|  | 631 |  | 
|  | 632 | result = sysfs_create_link(&device->dev.kobj, | 
|  | 633 | &pr->cdev->device.kobj, | 
|  | 634 | "thermal_cooling"); | 
| Bjorn Helgaas | d4e0526 | 2009-06-22 20:41:09 +0000 | [diff] [blame] | 635 | if (result) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | printk(KERN_ERR PREFIX "Create sysfs link\n"); | 
| Bjorn Helgaas | d4e0526 | 2009-06-22 20:41:09 +0000 | [diff] [blame] | 637 | goto err_thermal_unregister; | 
|  | 638 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | result = sysfs_create_link(&pr->cdev->device.kobj, | 
|  | 640 | &device->dev.kobj, | 
|  | 641 | "device"); | 
| Bjorn Helgaas | d4e0526 | 2009-06-22 20:41:09 +0000 | [diff] [blame] | 642 | if (result) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | printk(KERN_ERR PREFIX "Create sysfs link\n"); | 
| Bjorn Helgaas | d4e0526 | 2009-06-22 20:41:09 +0000 | [diff] [blame] | 644 | goto err_remove_sysfs; | 
|  | 645 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 647 | return 0; | 
| Bjorn Helgaas | d4e0526 | 2009-06-22 20:41:09 +0000 | [diff] [blame] | 648 |  | 
|  | 649 | err_remove_sysfs: | 
|  | 650 | sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); | 
|  | 651 | err_thermal_unregister: | 
|  | 652 | thermal_cooling_device_unregister(pr->cdev); | 
|  | 653 | err_power_exit: | 
|  | 654 | acpi_processor_power_exit(pr, device); | 
|  | 655 | err_remove_fs: | 
|  | 656 | acpi_processor_remove_fs(device); | 
| Bjorn Helgaas | 970b049 | 2009-06-22 20:41:19 +0000 | [diff] [blame] | 657 | err_free_cpumask: | 
|  | 658 | free_cpumask_var(pr->throttling.shared_cpu_map); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 |  | 
|  | 660 | return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } | 
|  | 662 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 663 | static int acpi_processor_remove(struct acpi_device *device, int type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 665 | struct acpi_processor *pr = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 |  | 
|  | 668 | if (!device || !acpi_driver_data(device)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 669 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 |  | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 671 | pr = acpi_driver_data(device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 |  | 
| Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 673 | if (pr->id >= nr_cpu_ids) | 
|  | 674 | goto free; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 |  | 
|  | 676 | if (type == ACPI_BUS_REMOVAL_EJECT) { | 
|  | 677 | if (acpi_processor_handle_eject(pr)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 678 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } | 
|  | 680 |  | 
|  | 681 | acpi_processor_power_exit(pr, device); | 
|  | 682 |  | 
| Zhang Rui | 9f1eb99 | 2008-04-29 02:36:07 -0400 | [diff] [blame] | 683 | sysfs_remove_link(&device->dev.kobj, "sysdev"); | 
|  | 684 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | acpi_processor_remove_fs(device); | 
|  | 686 |  | 
| Zhao Yakui | f28bb45 | 2008-02-15 08:34:37 +0800 | [diff] [blame] | 687 | if (pr->cdev) { | 
|  | 688 | sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); | 
|  | 689 | sysfs_remove_link(&pr->cdev->device.kobj, "device"); | 
|  | 690 | thermal_cooling_device_unregister(pr->cdev); | 
|  | 691 | pr->cdev = NULL; | 
|  | 692 | } | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 693 |  | 
| Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 694 | per_cpu(processors, pr->id) = NULL; | 
|  | 695 | per_cpu(processor_device_array, pr->id) = NULL; | 
| Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 696 |  | 
|  | 697 | free: | 
|  | 698 | free_cpumask_var(pr->throttling.shared_cpu_map); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | kfree(pr); | 
|  | 700 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 701 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } | 
|  | 703 |  | 
|  | 704 | #ifdef CONFIG_ACPI_HOTPLUG_CPU | 
|  | 705 | /**************************************************************************** | 
|  | 706 | * 	Acpi processor hotplug support 				       	    * | 
|  | 707 | ****************************************************************************/ | 
|  | 708 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 709 | static int is_processor_present(acpi_handle handle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 711 | acpi_status status; | 
| Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 712 | unsigned long long sta = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 |  | 
|  | 715 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); | 
| Zhang Rui | cfaf374 | 2008-01-09 02:17:47 -0500 | [diff] [blame] | 716 |  | 
|  | 717 | if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT)) | 
|  | 718 | return 1; | 
|  | 719 |  | 
| Zhang Rui | d0ce46f | 2008-02-23 01:53:09 -0500 | [diff] [blame] | 720 | /* | 
|  | 721 | * _STA is mandatory for a processor that supports hot plug | 
|  | 722 | */ | 
|  | 723 | if (status == AE_NOT_FOUND) | 
|  | 724 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 725 | "Processor does not support hot plug\n")); | 
|  | 726 | else | 
|  | 727 | ACPI_EXCEPTION((AE_INFO, status, | 
|  | 728 | "Processor Device is not present")); | 
| Zhang Rui | cfaf374 | 2008-01-09 02:17:47 -0500 | [diff] [blame] | 729 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | } | 
|  | 731 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | static | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 733 | int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 735 | acpi_handle phandle; | 
|  | 736 | struct acpi_device *pdev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 |  | 
|  | 739 | if (acpi_get_parent(handle, &phandle)) { | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 740 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } | 
|  | 742 |  | 
|  | 743 | if (acpi_bus_get_device(phandle, &pdev)) { | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 744 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | } | 
|  | 746 |  | 
|  | 747 | if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) { | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 748 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } | 
|  | 750 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 751 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } | 
|  | 753 |  | 
| Sam Ravnborg | b95e9e8 | 2008-02-17 13:22:48 +0100 | [diff] [blame] | 754 | static void __ref acpi_processor_hotplug_notify(acpi_handle handle, | 
|  | 755 | u32 event, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 757 | struct acpi_processor *pr; | 
|  | 758 | struct acpi_device *device = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | int result; | 
|  | 760 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 |  | 
|  | 762 | switch (event) { | 
|  | 763 | case ACPI_NOTIFY_BUS_CHECK: | 
|  | 764 | case ACPI_NOTIFY_DEVICE_CHECK: | 
| Glauber Costa | d6f882e | 2008-03-04 15:06:36 -0800 | [diff] [blame] | 765 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 766 | "Processor driver received %s event\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 767 | (event == ACPI_NOTIFY_BUS_CHECK) ? | 
| Glauber Costa | d6f882e | 2008-03-04 15:06:36 -0800 | [diff] [blame] | 768 | "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 |  | 
|  | 770 | if (!is_processor_present(handle)) | 
|  | 771 | break; | 
|  | 772 |  | 
|  | 773 | if (acpi_bus_get_device(handle, &device)) { | 
|  | 774 | result = acpi_processor_device_add(handle, &device); | 
|  | 775 | if (result) | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 776 | printk(KERN_ERR PREFIX | 
|  | 777 | "Unable to add the device\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | break; | 
|  | 779 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 780 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | case ACPI_NOTIFY_EJECT_REQUEST: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 782 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 783 | "received ACPI_NOTIFY_EJECT_REQUEST\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 |  | 
|  | 785 | if (acpi_bus_get_device(handle, &device)) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 786 | printk(KERN_ERR PREFIX | 
|  | 787 | "Device don't exist, dropping EJECT\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | break; | 
|  | 789 | } | 
|  | 790 | pr = acpi_driver_data(device); | 
|  | 791 | if (!pr) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 792 | printk(KERN_ERR PREFIX | 
|  | 793 | "Driver data is NULL, dropping EJECT\n"); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 794 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | break; | 
|  | 797 | default: | 
|  | 798 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 799 | "Unsupported event [0x%x]\n", event)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | break; | 
|  | 801 | } | 
|  | 802 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 803 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | } | 
|  | 805 |  | 
|  | 806 | static acpi_status | 
|  | 807 | processor_walk_namespace_cb(acpi_handle handle, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 808 | u32 lvl, void *context, void **rv) | 
| 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 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | int *action = context; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 812 | acpi_object_type type = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 |  | 
|  | 814 | status = acpi_get_type(handle, &type); | 
|  | 815 | if (ACPI_FAILURE(status)) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 816 | return (AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 |  | 
|  | 818 | if (type != ACPI_TYPE_PROCESSOR) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 819 | return (AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 821 | switch (*action) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | case INSTALL_NOTIFY_HANDLER: | 
|  | 823 | acpi_install_notify_handler(handle, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 824 | ACPI_SYSTEM_NOTIFY, | 
|  | 825 | acpi_processor_hotplug_notify, | 
|  | 826 | NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | break; | 
|  | 828 | case UNINSTALL_NOTIFY_HANDLER: | 
|  | 829 | acpi_remove_notify_handler(handle, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 830 | ACPI_SYSTEM_NOTIFY, | 
|  | 831 | acpi_processor_hotplug_notify); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | break; | 
|  | 833 | default: | 
|  | 834 | break; | 
|  | 835 | } | 
|  | 836 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 837 | return (AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | } | 
|  | 839 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 840 | 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] | 841 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 |  | 
|  | 843 | if (!is_processor_present(handle)) { | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 844 | return AE_ERROR; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | } | 
|  | 846 |  | 
|  | 847 | if (acpi_map_lsapic(handle, p_cpu)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 848 | return AE_ERROR; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 |  | 
|  | 850 | if (arch_register_cpu(*p_cpu)) { | 
|  | 851 | acpi_unmap_lsapic(*p_cpu); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 852 | return AE_ERROR; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | } | 
|  | 854 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 855 | return AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | } | 
|  | 857 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 858 | static int acpi_processor_handle_eject(struct acpi_processor *pr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | { | 
| Zhang Rui | b62b8ef | 2008-04-29 02:35:56 -0400 | [diff] [blame] | 860 | if (cpu_online(pr->id)) | 
|  | 861 | cpu_down(pr->id); | 
|  | 862 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | arch_unregister_cpu(pr->id); | 
|  | 864 | acpi_unmap_lsapic(pr->id); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 865 | return (0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | } | 
|  | 867 | #else | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 868 | 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] | 869 | { | 
|  | 870 | return AE_ERROR; | 
|  | 871 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 872 | static int acpi_processor_handle_eject(struct acpi_processor *pr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 874 | return (-EINVAL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | } | 
|  | 876 | #endif | 
|  | 877 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | static | 
|  | 879 | void acpi_processor_install_hotplug_notify(void) | 
|  | 880 | { | 
|  | 881 | #ifdef CONFIG_ACPI_HOTPLUG_CPU | 
|  | 882 | int action = INSTALL_NOTIFY_HANDLER; | 
|  | 883 | acpi_walk_namespace(ACPI_TYPE_PROCESSOR, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 884 | ACPI_ROOT_OBJECT, | 
|  | 885 | ACPI_UINT32_MAX, | 
| Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 886 | processor_walk_namespace_cb, NULL, &action, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | #endif | 
| Venkatesh Pallipadi | 729c6ba | 2007-09-16 15:36:43 +0200 | [diff] [blame] | 888 | register_hotcpu_notifier(&acpi_cpu_notifier); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | } | 
|  | 890 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | static | 
|  | 892 | void acpi_processor_uninstall_hotplug_notify(void) | 
|  | 893 | { | 
|  | 894 | #ifdef CONFIG_ACPI_HOTPLUG_CPU | 
|  | 895 | int action = UNINSTALL_NOTIFY_HANDLER; | 
|  | 896 | acpi_walk_namespace(ACPI_TYPE_PROCESSOR, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 897 | ACPI_ROOT_OBJECT, | 
|  | 898 | ACPI_UINT32_MAX, | 
| Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 899 | processor_walk_namespace_cb, NULL, &action, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | #endif | 
| Venkatesh Pallipadi | 729c6ba | 2007-09-16 15:36:43 +0200 | [diff] [blame] | 901 | unregister_hotcpu_notifier(&acpi_cpu_notifier); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | } | 
|  | 903 |  | 
|  | 904 | /* | 
|  | 905 | * We keep the driver loaded even when ACPI is not running. | 
|  | 906 | * This is needed for the powernow-k8 driver, that works even without | 
|  | 907 | * ACPI, but needs symbols from this driver | 
|  | 908 | */ | 
|  | 909 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 910 | static int __init acpi_processor_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 912 | int result = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 |  | 
| Yinghai Lu | ce8442b | 2009-08-26 14:29:26 -0700 | [diff] [blame] | 914 | if (acpi_disabled) | 
|  | 915 | return 0; | 
|  | 916 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | memset(&errata, 0, sizeof(errata)); | 
|  | 918 |  | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 919 | #ifdef CONFIG_ACPI_PROCFS | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); | 
|  | 921 | if (!acpi_processor_dir) | 
| Akinobu Mita | 83822fc | 2006-12-19 12:56:10 -0800 | [diff] [blame] | 922 | return -ENOMEM; | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 923 | #endif | 
| Len Brown | 541adf7 | 2010-05-22 17:03:29 -0400 | [diff] [blame] | 924 |  | 
| Len Brown | 2671717 | 2010-03-08 14:07:30 -0500 | [diff] [blame] | 925 | if (!cpuidle_register_driver(&acpi_idle_driver)) { | 
| Len Brown | 541adf7 | 2010-05-22 17:03:29 -0400 | [diff] [blame] | 926 | printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n", | 
|  | 927 | acpi_idle_driver.name); | 
| Len Brown | 2671717 | 2010-03-08 14:07:30 -0500 | [diff] [blame] | 928 | } else { | 
|  | 929 | printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s", | 
|  | 930 | cpuidle_get_driver()->name); | 
|  | 931 | } | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 932 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | result = acpi_bus_register_driver(&acpi_processor_driver); | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 934 | if (result < 0) | 
|  | 935 | goto out_cpuidle; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 |  | 
|  | 937 | acpi_processor_install_hotplug_notify(); | 
|  | 938 |  | 
|  | 939 | acpi_thermal_cpufreq_init(); | 
|  | 940 |  | 
|  | 941 | acpi_processor_ppc_init(); | 
|  | 942 |  | 
| Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 943 | acpi_processor_throttling_init(); | 
|  | 944 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 945 | return 0; | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 946 |  | 
|  | 947 | out_cpuidle: | 
|  | 948 | cpuidle_unregister_driver(&acpi_idle_driver); | 
|  | 949 |  | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 950 | #ifdef CONFIG_ACPI_PROCFS | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 951 | remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 952 | #endif | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 953 |  | 
|  | 954 | return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | } | 
|  | 956 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 957 | static void __exit acpi_processor_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | { | 
| Yinghai Lu | ce8442b | 2009-08-26 14:29:26 -0700 | [diff] [blame] | 959 | if (acpi_disabled) | 
|  | 960 | return; | 
|  | 961 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | acpi_processor_ppc_exit(); | 
|  | 963 |  | 
|  | 964 | acpi_thermal_cpufreq_exit(); | 
|  | 965 |  | 
|  | 966 | acpi_processor_uninstall_hotplug_notify(); | 
|  | 967 |  | 
|  | 968 | acpi_bus_unregister_driver(&acpi_processor_driver); | 
|  | 969 |  | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 970 | cpuidle_unregister_driver(&acpi_idle_driver); | 
|  | 971 |  | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 972 | #ifdef CONFIG_ACPI_PROCFS | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); | 
| Zhao Yakui | 74cad4e | 2009-06-24 11:49:49 +0800 | [diff] [blame] | 974 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 976 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | } | 
|  | 978 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | module_init(acpi_processor_init); | 
|  | 980 | module_exit(acpi_processor_exit); | 
|  | 981 |  | 
|  | 982 | EXPORT_SYMBOL(acpi_processor_set_thermal_limit); | 
|  | 983 |  | 
|  | 984 | MODULE_ALIAS("processor"); |