processor_core.c 26 KB

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