processor_core.c 26 KB

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