processor_core.c 28 KB

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