processor_core.c 27 KB

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