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