processor_core.c 29 KB

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