processor_core.c 26 KB

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