processor_core.c 27 KB

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