processor_core.c 26 KB

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