processor_core.c 28 KB

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