2 * acpi_processor.c - ACPI Processor Driver ($Revision: 69 $)
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 * 1. Make # power/performance states dynamic.
26 * 2. Support duty_cycle values that span bit 4.
27 * 3. Optimize by having scheduler determine business instead of
28 * having us try to calculate it here.
29 * 4. Need C1 timing -- must modify kernel (IRQ handler) to get this.
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/pci.h>
39 #include <asm/system.h>
40 #include <asm/delay.h>
41 #include <linux/compatmac.h>
42 #include <linux/proc_fs.h>
43 #include <acpi/acpi_bus.h>
44 #include <acpi/acpi_drivers.h>
47 #define _COMPONENT ACPI_PROCESSOR_COMPONENT
48 ACPI_MODULE_NAME ("acpi_processor")
50 MODULE_AUTHOR("Paul Diefenbaugh");
51 MODULE_DESCRIPTION(ACPI_PROCESSOR_DRIVER_NAME);
52 MODULE_LICENSE("GPL");
54 #define PREFIX "ACPI: "
56 #define US_TO_PM_TIMER_TICKS(t) ((t * (PM_TIMER_FREQUENCY/1000)) / 1000)
57 #define C2_OVERHEAD 4 /* 1us (3.579 ticks per us) */
58 #define C3_OVERHEAD 4 /* 1us (3.579 ticks per us) */
60 #define ACPI_PROCESSOR_BUSY_METRIC 10
62 #define ACPI_PROCESSOR_MAX_POWER ACPI_C_STATE_COUNT
63 #define ACPI_PROCESSOR_MAX_C2_LATENCY 100
64 #define ACPI_PROCESSOR_MAX_C3_LATENCY 1000
66 #define ACPI_PROCESSOR_MAX_PERFORMANCE 8
68 #define ACPI_PROCESSOR_MAX_THROTTLING 16
69 #define ACPI_PROCESSOR_MAX_THROTTLE 250 /* 25% */
70 #define ACPI_PROCESSOR_MAX_DUTY_WIDTH 4
72 #define ACPI_PROCESSOR_LIMIT_USER 0
73 #define ACPI_PROCESSOR_LIMIT_THERMAL 1
75 static int acpi_processor_add (struct acpi_device *device);
76 static int acpi_processor_remove (struct acpi_device *device, int type);
78 static struct acpi_driver acpi_processor_driver = {
79 .name = ACPI_PROCESSOR_DRIVER_NAME,
80 .class = ACPI_PROCESSOR_CLASS,
81 .ids = ACPI_PROCESSOR_HID,
83 .add = acpi_processor_add,
84 .remove = acpi_processor_remove,
88 /* Power Management */
90 struct acpi_processor_cx_policy {
101 struct acpi_processor_cx {
108 struct acpi_processor_cx_policy promotion;
109 struct acpi_processor_cx_policy demotion;
112 struct acpi_processor_power {
116 struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
119 /* Performance Management */
121 struct acpi_pct_register {
129 } __attribute__ ((packed));
131 struct acpi_processor_px {
132 acpi_integer core_frequency; /* megahertz */
133 acpi_integer power; /* milliWatts */
134 acpi_integer transition_latency; /* microseconds */
135 acpi_integer bus_master_latency; /* microseconds */
136 acpi_integer control; /* control value */
137 acpi_integer status; /* success indicator */
140 struct acpi_processor_performance {
143 u16 control_register;
145 u8 control_register_bit_width;
146 u8 status_register_bit_width;
148 struct acpi_processor_px states[ACPI_PROCESSOR_MAX_PERFORMANCE];
152 /* Throttling Control */
154 struct acpi_processor_tx {
159 struct acpi_processor_throttling {
165 struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING];
168 /* Limit Interface */
170 struct acpi_processor_lx {
171 int px; /* performace state */
172 int tx; /* throttle level */
175 struct acpi_processor_limit {
176 struct acpi_processor_lx state; /* current limit */
177 struct acpi_processor_lx thermal; /* thermal limit */
178 struct acpi_processor_lx user; /* user limit */
182 struct acpi_processor_flags {
192 struct acpi_processor {
196 struct acpi_processor_flags flags;
197 struct acpi_processor_power power;
198 struct acpi_processor_performance performance;
199 struct acpi_processor_throttling throttling;
200 struct acpi_processor_limit limit;
203 struct acpi_processor_errata {
213 static struct acpi_processor *processors[NR_CPUS];
214 static struct acpi_processor_errata errata;
215 static void (*pm_idle_save)(void);
218 /* --------------------------------------------------------------------------
220 -------------------------------------------------------------------------- */
223 acpi_processor_errata_piix4 (
230 ACPI_FUNCTION_TRACE("acpi_processor_errata_piix4");
233 return_VALUE(-EINVAL);
236 * Note that 'dev' references the PIIX4 ACPI Controller.
239 pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
243 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
246 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n"));
249 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n"));
252 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n"));
255 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n"));
261 case 0: /* PIIX4 A-step */
262 case 1: /* PIIX4 B-step */
264 * See specification changes #13 ("Manual Throttle Duty Cycle")
265 * and #14 ("Enabling and Disabling Manual Throttle"), plus
266 * erratum #5 ("STPCLK# Deassertion Time") from the January
267 * 2002 PIIX4 specification update. Applies to only older
270 errata.piix4.throttle = 1;
275 * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
276 * Livelock") from the January 2002 PIIX4 specification update.
277 * Applies to all PIIX4 models.
283 * Find the PIIX4 IDE Controller and get the Bus Master IDE
284 * Status register address. We'll use this later to read
285 * each IDE controller's DMA status to make sure we catch all
288 dev = pci_find_subsys(PCI_VENDOR_ID_INTEL,
289 PCI_DEVICE_ID_INTEL_82371AB,
290 PCI_ANY_ID, PCI_ANY_ID, NULL);
292 errata.piix4.bmisx = pci_resource_start(dev, 4);
297 * Find the PIIX4 ISA Controller and read the Motherboard
298 * DMA controller's status to see if Type-F (Fast) DMA mode
299 * is enabled (bit 7) on either channel. Note that we'll
300 * disable C3 support if this is enabled, as some legacy
301 * devices won't operate well if fast DMA is disabled.
303 dev = pci_find_subsys(PCI_VENDOR_ID_INTEL,
304 PCI_DEVICE_ID_INTEL_82371AB_0,
305 PCI_ANY_ID, PCI_ANY_ID, NULL);
307 pci_read_config_byte(dev, 0x76, &value1);
308 pci_read_config_byte(dev, 0x77, &value2);
309 if ((value1 & 0x80) || (value2 & 0x80))
310 errata.piix4.fdma = 1;
316 if (errata.piix4.bmisx)
317 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
318 "Bus master activity detection (BM-IDE) erratum enabled\n"));
319 if (errata.piix4.fdma)
320 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
321 "Type-F DMA livelock erratum (C3 disabled)\n"));
328 acpi_processor_errata (
329 struct acpi_processor *pr)
332 struct pci_dev *dev = NULL;
334 ACPI_FUNCTION_TRACE("acpi_processor_errata");
337 return_VALUE(-EINVAL);
342 dev = pci_find_subsys(PCI_VENDOR_ID_INTEL,
343 PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID, PCI_ANY_ID, NULL);
345 result = acpi_processor_errata_piix4(dev);
347 return_VALUE(result);
351 /* --------------------------------------------------------------------------
353 -------------------------------------------------------------------------- */
362 else if (!acpi_fadt.tmr_val_ext)
363 return (((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
365 return ((0xFFFFFFFF - t1) + t2);
370 acpi_processor_power_activate (
371 struct acpi_processor *pr,
377 pr->power.states[pr->power.state].promotion.count = 0;
378 pr->power.states[pr->power.state].demotion.count = 0;
380 /* Cleanup from old state. */
381 switch (pr->power.state) {
383 /* Disable bus master reload */
384 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0, ACPI_MTX_DO_NOT_LOCK);
388 /* Prepare to use new state. */
391 /* Enable bus master reload */
392 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1, ACPI_MTX_DO_NOT_LOCK);
396 pr->power.state = state;
403 acpi_processor_idle (void)
405 struct acpi_processor *pr = NULL;
406 struct acpi_processor_cx *cx = NULL;
411 pr = processors[smp_processor_id()];
416 * Interrupts must be disabled during bus mastering calculations and
417 * for C2/C3 transitions.
421 cx = &(pr->power.states[pr->power.state]);
426 * Check for bus mastering activity (if required), record, and check
429 if (pr->flags.bm_check) {
432 pr->power.bm_activity <<= 1;
434 acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS,
435 &bm_status, ACPI_MTX_DO_NOT_LOCK);
437 pr->power.bm_activity++;
438 acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS,
439 1, ACPI_MTX_DO_NOT_LOCK);
442 * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
443 * the true state of bus mastering activity; forcing us to
444 * manually check the BMIDEA bit of each IDE channel.
446 else if (errata.piix4.bmisx) {
447 if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
448 || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
449 pr->power.bm_activity++;
452 * Apply bus mastering demotion policy. Automatically demote
453 * to avoid a faulty transition. Note that the processor
454 * won't enter a low-power state during this call (to this
455 * funciton) but should upon the next.
457 * TBD: A better policy might be to fallback to the demotion
458 * state (use it for this quantum only) istead of
459 * demoting -- and rely on duration as our sole demotion
460 * qualification. This may, however, introduce DMA
461 * issues (e.g. floppy DMA transfer overrun/underrun).
463 if (pr->power.bm_activity & cx->demotion.threshold.bm) {
465 next_state = cx->demotion.state;
475 * Invoke the current Cx state to put the processor to sleep.
477 switch (pr->power.state) {
483 * TBD: Can't get time duration while in C1, as resumes
484 * go to an ISR rather than here. Need to instrument
485 * base interrupt handler.
487 sleep_ticks = 0xFFFFFFFF;
491 /* Get start time (ticks) */
492 t1 = inl(acpi_fadt.xpm_tmr_blk.address);
494 inb(pr->power.states[ACPI_STATE_C2].address);
495 /* Dummy op - must do something useless after P_LVL2 read */
496 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
497 /* Get end time (ticks) */
498 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
499 /* Re-enable interrupts */
501 /* Compute time (ticks) that we were actually asleep */
502 sleep_ticks = ticks_elapsed(t1, t2) - cx->latency_ticks - C2_OVERHEAD;
506 /* Disable bus master arbitration */
507 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1, ACPI_MTX_DO_NOT_LOCK);
508 /* Get start time (ticks) */
509 t1 = inl(acpi_fadt.xpm_tmr_blk.address);
511 inb(pr->power.states[ACPI_STATE_C3].address);
512 /* Dummy op - must do something useless after P_LVL3 read */
513 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
514 /* Get end time (ticks) */
515 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
516 /* Enable bus master arbitration */
517 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_DO_NOT_LOCK);
518 /* Re-enable interrupts */
520 /* Compute time (ticks) that we were actually asleep */
521 sleep_ticks = ticks_elapsed(t1, t2) - cx->latency_ticks - C3_OVERHEAD;
529 next_state = pr->power.state;
534 * Track the number of longs (time asleep is greater than threshold)
535 * and promote when the count threshold is reached. Note that bus
536 * mastering activity may prevent promotions.
538 if (cx->promotion.state) {
539 if (sleep_ticks > cx->promotion.threshold.ticks) {
540 cx->promotion.count++;
541 cx->demotion.count = 0;
542 if (cx->promotion.count >= cx->promotion.threshold.count) {
543 if (pr->flags.bm_check) {
544 if (!(pr->power.bm_activity & cx->promotion.threshold.bm)) {
545 next_state = cx->promotion.state;
550 next_state = cx->promotion.state;
560 * Track the number of shorts (time asleep is less than time threshold)
561 * and demote when the usage threshold is reached.
563 if (cx->demotion.state) {
564 if (sleep_ticks < cx->demotion.threshold.ticks) {
565 cx->demotion.count++;
566 cx->promotion.count = 0;
567 if (cx->demotion.count >= cx->demotion.threshold.count) {
568 next_state = cx->demotion.state;
578 * If we're going to start using a new Cx state we must clean up
579 * from the previous and prepare to use the new.
581 if (next_state != pr->power.state)
582 acpi_processor_power_activate(pr, next_state);
589 acpi_processor_set_power_policy (
590 struct acpi_processor *pr)
592 ACPI_FUNCTION_TRACE("acpi_processor_set_power_policy");
595 * This function sets the default Cx state policy (OS idle handler).
596 * Our scheme is to promote quickly to C2 but more conservatively
597 * to C3. We're favoring C2 for its characteristics of low latency
598 * (quick response), good power savings, and ability to allow bus
599 * mastering activity. Note that the Cx state policy is completely
600 * customizable and can be altered dynamically.
604 return_VALUE(-EINVAL);
610 pr->power.state = ACPI_STATE_C1;
611 pr->power.default_state = ACPI_STATE_C1;
616 * Set the default C1 promotion and C2 demotion policies, where we
617 * promote from C1 to C2 after several (10) successive C1 transitions,
618 * as we cannot (currently) measure the time spent in C1. Demote from
619 * C2 to C1 anytime we experience a 'short' (time spent in C2 is less
620 * than the C2 transtion latency). Note the simplifying assumption
621 * that the 'cost' of a transition is amortized when we sleep for at
622 * least as long as the transition's latency (thus the total transition
623 * time is two times the latency).
625 * TBD: Measure C1 sleep times by instrumenting the core IRQ handler.
626 * TBD: Demote to default C-State after long periods of activity.
627 * TBD: Investigate policy's use of CPU utilization -vs- sleep duration.
629 if (pr->power.states[ACPI_STATE_C2].valid) {
630 pr->power.states[ACPI_STATE_C1].promotion.threshold.count = 10;
631 pr->power.states[ACPI_STATE_C1].promotion.threshold.ticks =
632 pr->power.states[ACPI_STATE_C2].latency_ticks;
633 pr->power.states[ACPI_STATE_C1].promotion.state = ACPI_STATE_C2;
635 pr->power.states[ACPI_STATE_C2].demotion.threshold.count = 1;
636 pr->power.states[ACPI_STATE_C2].demotion.threshold.ticks =
637 pr->power.states[ACPI_STATE_C2].latency_ticks;
638 pr->power.states[ACPI_STATE_C2].demotion.state = ACPI_STATE_C1;
644 * Set default C2 promotion and C3 demotion policies, where we promote
645 * from C2 to C3 after several (4) cycles of no bus mastering activity
646 * while maintaining sleep time criteria. Demote immediately on a
647 * short or whenever bus mastering activity occurs.
649 if ((pr->power.states[ACPI_STATE_C2].valid) &&
650 (pr->power.states[ACPI_STATE_C3].valid)) {
651 pr->power.states[ACPI_STATE_C2].promotion.threshold.count = 4;
652 pr->power.states[ACPI_STATE_C2].promotion.threshold.ticks =
653 pr->power.states[ACPI_STATE_C3].latency_ticks;
654 pr->power.states[ACPI_STATE_C2].promotion.threshold.bm = 0x0F;
655 pr->power.states[ACPI_STATE_C2].promotion.state = ACPI_STATE_C3;
657 pr->power.states[ACPI_STATE_C3].demotion.threshold.count = 1;
658 pr->power.states[ACPI_STATE_C3].demotion.threshold.ticks =
659 pr->power.states[ACPI_STATE_C3].latency_ticks;
660 pr->power.states[ACPI_STATE_C3].demotion.threshold.bm = 0x0F;
661 pr->power.states[ACPI_STATE_C3].demotion.state = ACPI_STATE_C2;
669 acpi_processor_get_power_info (
670 struct acpi_processor *pr)
674 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info");
677 return_VALUE(-EINVAL);
679 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
680 "lvl2[0x%08x] lvl3[0x%08x]\n",
681 pr->power.states[ACPI_STATE_C2].address,
682 pr->power.states[ACPI_STATE_C3].address));
684 /* TBD: Support ACPI 2.0 objects */
689 * This state exists only as filler in our array.
691 pr->power.states[ACPI_STATE_C0].valid = 1;
696 * ACPI requires C1 support for all processors.
698 * TBD: What about PROC_C1?
700 pr->power.states[ACPI_STATE_C1].valid = 1;
705 * We're (currently) only supporting C2 on UP systems.
707 * TBD: Support for C2 on MP (P_LVL2_UP).
709 if (pr->power.states[ACPI_STATE_C2].address) {
711 pr->power.states[ACPI_STATE_C2].latency = acpi_fadt.plvl2_lat;
714 * C2 latency must be less than or equal to 100 microseconds.
716 if (acpi_fadt.plvl2_lat > ACPI_PROCESSOR_MAX_C2_LATENCY)
717 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
718 "C2 latency too large [%d]\n",
719 acpi_fadt.plvl2_lat));
721 * Only support C2 on UP systems (see TBD above).
724 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
725 "C2 not supported in SMP mode\n"));
727 * Otherwise we've met all of our C2 requirements.
728 * Normalize the C2 latency to expidite policy.
731 pr->power.states[ACPI_STATE_C2].valid = 1;
732 pr->power.states[ACPI_STATE_C2].latency_ticks =
733 US_TO_PM_TIMER_TICKS(acpi_fadt.plvl2_lat);
740 * TBD: Investigate use of WBINVD on UP/SMP system in absence of
743 if (pr->power.states[ACPI_STATE_C3].address) {
745 pr->power.states[ACPI_STATE_C3].latency = acpi_fadt.plvl3_lat;
748 * C3 latency must be less than or equal to 1000 microseconds.
750 if (acpi_fadt.plvl3_lat > ACPI_PROCESSOR_MAX_C3_LATENCY)
751 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
752 "C3 latency too large [%d]\n",
753 acpi_fadt.plvl3_lat));
755 * Only support C3 when bus mastering arbitration control
756 * is present (able to disable bus mastering to maintain
757 * cache coherency while in C3).
759 else if (!pr->flags.bm_control)
760 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
761 "C3 support requires bus mastering control\n"));
763 * Only support C3 on UP systems, as bm_control is only viable
764 * on a UP system and flushing caches (e.g. WBINVD) is simply
765 * too costly (at this time).
768 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
769 "C3 not supported in SMP mode\n"));
771 * PIIX4 Erratum #18: We don't support C3 when Type-F (fast)
772 * DMA transfers are used by any ISA device to avoid livelock.
773 * Note that we could disable Type-F DMA (as recommended by
774 * the erratum), but this is known to disrupt certain ISA
775 * devices thus we take the conservative approach.
777 else if (errata.piix4.fdma) {
778 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
779 "C3 not supported on PIIX4 with Type-F DMA\n"));
782 * Otherwise we've met all of our C3 requirements.
783 * Normalize the C2 latency to expidite policy. Enable
784 * checking of bus mastering status (bm_check) so we can
785 * use this in our C3 policy.
788 pr->power.states[ACPI_STATE_C3].valid = 1;
789 pr->power.states[ACPI_STATE_C3].latency_ticks =
790 US_TO_PM_TIMER_TICKS(acpi_fadt.plvl3_lat);
791 pr->flags.bm_check = 1;
798 * Now that we know which state are supported, set the default
799 * policy. Note that this policy can be changed dynamically
800 * (e.g. encourage deeper sleeps to conserve battery life when
803 result = acpi_processor_set_power_policy(pr);
805 return_VALUE(result);
808 * If this processor supports C2 or C3 we denote it as being 'power
809 * manageable'. Note that there's really no policy involved for
810 * when only C1 is supported.
812 if (pr->power.states[ACPI_STATE_C2].valid
813 || pr->power.states[ACPI_STATE_C3].valid)
820 /* --------------------------------------------------------------------------
821 Performance Management
822 -------------------------------------------------------------------------- */
825 acpi_processor_get_platform_limit (
826 struct acpi_processor* pr)
828 acpi_status status = 0;
829 unsigned long ppc = 0;
831 ACPI_FUNCTION_TRACE("acpi_processor_get_platform_limit");
834 return_VALUE(-EINVAL);
837 * _PPC indicates the maximum state currently supported by the platform
838 * (e.g. 0 = states 0..n; 1 = states 1..n; etc.
840 status = acpi_evaluate_integer(pr->handle, "_PPC", NULL, &ppc);
841 if(ACPI_FAILURE(status)) {
842 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PPC\n"));
843 return_VALUE(-ENODEV);
846 pr->performance.platform_limit = (int) ppc;
853 acpi_processor_get_performance_control (
854 struct acpi_processor *pr)
857 acpi_status status = 0;
858 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
859 union acpi_object *pct = NULL;
860 union acpi_object obj = {0};
861 struct acpi_pct_register *reg = NULL;
863 ACPI_FUNCTION_TRACE("acpi_processor_get_performance_control");
865 status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer);
866 if(ACPI_FAILURE(status)) {
867 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PCT\n"));
868 return_VALUE(-ENODEV);
871 pct = (union acpi_object *) buffer.pointer;
872 if (!pct || (pct->type != ACPI_TYPE_PACKAGE)
873 || (pct->package.count != 2)) {
874 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PCT data\n"));
883 obj = pct->package.elements[0];
885 if ((obj.type != ACPI_TYPE_BUFFER)
886 || (obj.buffer.length < sizeof(struct acpi_pct_register))
887 || (obj.buffer.pointer == NULL)) {
888 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
889 "Invalid _PCT data (control_register)\n"));
894 reg = (struct acpi_pct_register *) (obj.buffer.pointer);
896 if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO) {
897 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
898 "Unsupported address space [%d] (control_register)\n",
899 (u32) reg->space_id));
904 pr->performance.control_register = (u16) reg->address;
905 pr->performance.control_register_bit_width = reg->bit_width;
910 obj = pct->package.elements[1];
912 if ((obj.type != ACPI_TYPE_BUFFER)
913 || (obj.buffer.length < sizeof(struct acpi_pct_register))
914 || (obj.buffer.pointer == NULL)) {
915 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
916 "Invalid _PCT data (status_register)\n"));
921 reg = (struct acpi_pct_register *) (obj.buffer.pointer);
923 if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO) {
924 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
925 "Unsupported address space [%d] (status_register)\n",
926 (u32) reg->space_id));
931 pr->performance.status_register = (u16) reg->address;
932 pr->performance.status_register_bit_width = reg->bit_width;
934 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
935 "control_register[0x%04x] status_register[0x%04x]\n",
936 pr->performance.control_register,
937 pr->performance.status_register));
940 acpi_os_free(buffer.pointer);
942 return_VALUE(result);
947 acpi_processor_get_performance_states (
948 struct acpi_processor* pr)
951 acpi_status status = AE_OK;
952 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
953 struct acpi_buffer format = {sizeof("NNNNNN"), "NNNNNN"};
954 struct acpi_buffer state = {0, NULL};
955 union acpi_object *pss = NULL;
958 ACPI_FUNCTION_TRACE("acpi_processor_get_performance_states");
960 status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer);
961 if(ACPI_FAILURE(status)) {
962 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PSS\n"));
963 return_VALUE(-ENODEV);
966 pss = (union acpi_object *) buffer.pointer;
967 if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) {
968 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSS data\n"));
973 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d performance states\n",
974 pss->package.count));
976 if (pss->package.count > ACPI_PROCESSOR_MAX_PERFORMANCE) {
977 pr->performance.state_count = ACPI_PROCESSOR_MAX_PERFORMANCE;
978 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
979 "Limiting number of states to max (%d)\n",
980 ACPI_PROCESSOR_MAX_PERFORMANCE));
983 pr->performance.state_count = pss->package.count;
985 if (pr->performance.state_count > 1)
986 pr->flags.performance = 1;
988 for (i = 0; i < pr->performance.state_count; i++) {
990 struct acpi_processor_px *px = &(pr->performance.states[i]);
992 state.length = sizeof(struct acpi_processor_px);
995 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i));
997 status = acpi_extract_package(&(pss->package.elements[i]),
999 if (ACPI_FAILURE(status)) {
1000 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSS data\n"));
1005 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1006 "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n",
1008 (u32) px->core_frequency,
1010 (u32) px->transition_latency,
1011 (u32) px->bus_master_latency,
1017 acpi_os_free(buffer.pointer);
1019 return_VALUE(result);
1023 acpi_processor_write_port(
1028 if (bit_width <= 8) {
1030 } else if (bit_width <= 16) {
1032 } else if (bit_width <= 32) {
1041 acpi_processor_read_port(
1047 if (bit_width <= 8) {
1049 } else if (bit_width <= 16) {
1051 } else if (bit_width <= 32) {
1060 acpi_processor_set_performance (
1061 struct acpi_processor *pr,
1070 ACPI_FUNCTION_TRACE("acpi_processor_set_performance");
1073 return_VALUE(-EINVAL);
1075 if (!pr->flags.performance)
1076 return_VALUE(-ENODEV);
1078 if (state >= pr->performance.state_count) {
1079 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
1080 "Invalid target state (P%d)\n", state));
1081 return_VALUE(-ENODEV);
1084 if (state < pr->performance.platform_limit) {
1085 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
1086 "Platform limit (P%d) overrides target state (P%d)\n",
1087 pr->performance.platform_limit, state));
1088 return_VALUE(-ENODEV);
1091 if (state == pr->performance.state) {
1092 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1093 "Already at target state (P%d)\n", state));
1097 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Transitioning from P%d to P%d\n",
1098 pr->performance.state, state));
1101 * First we write the target state's 'control' value to the
1105 port = pr->performance.control_register;
1106 value = (u32) pr->performance.states[state].control;
1107 bit_width = pr->performance.control_register_bit_width;
1109 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1110 "Writing 0x%08x to port 0x%04x\n", value, port));
1112 ret = acpi_processor_write_port(port, bit_width, value);
1114 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
1115 "Invalid port width 0x%04x\n", bit_width));
1120 * Then we read the 'status_register' and compare the value with the
1121 * target state's 'status' to make sure the transition was successful.
1122 * Note that we'll poll for up to 1ms (100 cycles of 10us) before
1126 port = pr->performance.status_register;
1127 bit_width = pr->performance.status_register_bit_width;
1129 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1130 "Looking for 0x%08x from port 0x%04x\n",
1131 (u32) pr->performance.states[state].status, port));
1133 for (i=0; i<100; i++) {
1134 ret = acpi_processor_read_port(port, bit_width, &value);
1136 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
1137 "Invalid port width 0x%04x\n", bit_width));
1140 if (value == (u32) pr->performance.states[state].status)
1145 if (value != (u32) pr->performance.states[state].status) {
1146 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Transition failed\n"));
1147 return_VALUE(-ENODEV);
1150 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1151 "Transition successful after %d microseconds\n",
1154 pr->performance.state = state;
1161 acpi_processor_get_performance_info (
1162 struct acpi_processor *pr)
1165 acpi_status status = AE_OK;
1166 acpi_handle handle = NULL;
1168 ACPI_FUNCTION_TRACE("acpi_processor_get_performance_info");
1171 return_VALUE(-EINVAL);
1173 status = acpi_get_handle(pr->handle, "_PCT", &handle);
1174 if (ACPI_FAILURE(status)) {
1175 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1176 "ACPI-based processor performance control unavailable\n"));
1180 result = acpi_processor_get_performance_control(pr);
1182 return_VALUE(result);
1184 result = acpi_processor_get_performance_states(pr);
1186 return_VALUE(result);
1188 result = acpi_processor_get_platform_limit(pr);
1190 return_VALUE(result);
1193 * TBD: Don't trust the latency values we get from BIOS, but rather
1194 * measure the latencies during run-time (e.g. get_latencies).
1201 /* --------------------------------------------------------------------------
1203 -------------------------------------------------------------------------- */
1206 acpi_processor_get_throttling (
1207 struct acpi_processor *pr)
1214 ACPI_FUNCTION_TRACE("acpi_processor_get_throttling");
1217 return_VALUE(-EINVAL);
1219 if (!pr->flags.throttling)
1220 return_VALUE(-ENODEV);
1222 pr->throttling.state = 0;
1226 duty_mask = pr->throttling.state_count - 1;
1228 duty_mask <<= pr->throttling.duty_offset;
1230 value = inl(pr->throttling.address);
1233 * Compute the current throttling state when throttling is enabled
1237 duty_value = value & duty_mask;
1238 duty_value >>= pr->throttling.duty_offset;
1241 state = pr->throttling.state_count-duty_value;
1244 pr->throttling.state = state;
1248 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1249 "Throttling state is T%d (%d%% throttling applied)\n",
1250 state, pr->throttling.states[state].performance));
1257 acpi_processor_set_throttling (
1258 struct acpi_processor *pr,
1265 ACPI_FUNCTION_TRACE("acpi_processor_set_throttling");
1268 return_VALUE(-EINVAL);
1270 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
1271 return_VALUE(-EINVAL);
1273 if (!pr->flags.throttling)
1274 return_VALUE(-ENODEV);
1276 if (state == pr->throttling.state)
1282 * Calculate the duty_value and duty_mask.
1285 duty_value = pr->throttling.state_count - state;
1287 duty_value <<= pr->throttling.duty_offset;
1289 /* Used to clear all duty_value bits */
1290 duty_mask = pr->throttling.state_count - 1;
1292 duty_mask <<= acpi_fadt.duty_offset;
1293 duty_mask = ~duty_mask;
1297 * Disable throttling by writing a 0 to bit 4. Note that we must
1298 * turn it off before you can change the duty_value.
1300 value = inl(pr->throttling.address);
1302 value &= 0xFFFFFFEF;
1303 outl(value, pr->throttling.address);
1307 * Write the new duty_value and then enable throttling. Note
1308 * that a state value of 0 leaves throttling disabled.
1312 value |= duty_value;
1313 outl(value, pr->throttling.address);
1315 value |= 0x00000010;
1316 outl(value, pr->throttling.address);
1319 pr->throttling.state = state;
1323 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1324 "Throttling state set to T%d (%d%%)\n", state,
1325 (pr->throttling.states[state].performance?pr->throttling.states[state].performance/10:0)));
1332 acpi_processor_get_throttling_info (
1333 struct acpi_processor *pr)
1339 ACPI_FUNCTION_TRACE("acpi_processor_get_throttling_info");
1341 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1342 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
1343 pr->throttling.address,
1344 pr->throttling.duty_offset,
1345 pr->throttling.duty_width));
1348 return_VALUE(-EINVAL);
1350 /* TBD: Support ACPI 2.0 objects */
1352 if (!pr->throttling.address) {
1353 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
1356 else if (!pr->throttling.duty_width) {
1357 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n"));
1360 /* TBD: Support duty_cycle values that span bit 4. */
1361 else if ((pr->throttling.duty_offset
1362 + pr->throttling.duty_width) > 4) {
1363 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "duty_cycle spans bit 4\n"));
1368 * PIIX4 Errata: We don't support throttling on the original PIIX4.
1369 * This shouldn't be an issue as few (if any) mobile systems ever
1372 if (errata.piix4.throttle) {
1373 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1374 "Throttling not supported on PIIX4 A- or B-step\n"));
1378 pr->throttling.state_count = 1 << acpi_fadt.duty_width;
1381 * Compute state values. Note that throttling displays a linear power/
1382 * performance relationship (at 50% performance the CPU will consume
1383 * 50% power). Values are in 1/10th of a percent to preserve accuracy.
1386 step = (1000 / pr->throttling.state_count);
1388 for (i=0; i<pr->throttling.state_count; i++) {
1389 pr->throttling.states[i].performance = step * i;
1390 pr->throttling.states[i].power = step * i;
1393 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
1394 pr->throttling.state_count));
1396 pr->flags.throttling = 1;
1399 * Disable throttling (if enabled). We'll let subsequent policy (e.g.
1400 * thermal) decide to lower performance if it so chooses, but for now
1401 * we'll crank up the speed.
1404 result = acpi_processor_get_throttling(pr);
1408 if (pr->throttling.state) {
1409 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabling throttling (was T%d)\n",
1410 pr->throttling.state));
1411 result = acpi_processor_set_throttling(pr, 0);
1418 pr->flags.throttling = 0;
1420 return_VALUE(result);
1424 /* --------------------------------------------------------------------------
1426 -------------------------------------------------------------------------- */
1429 acpi_processor_apply_limit (
1430 struct acpi_processor* pr)
1436 ACPI_FUNCTION_TRACE("acpi_processor_apply_limit");
1439 return_VALUE(-EINVAL);
1441 if (!pr->flags.limit)
1442 return_VALUE(-ENODEV);
1444 if (pr->flags.performance) {
1445 px = pr->performance.platform_limit;
1446 if (pr->limit.user.px > px)
1447 px = pr->limit.user.px;
1448 if (pr->limit.thermal.px > px)
1449 px = pr->limit.thermal.px;
1451 result = acpi_processor_set_performance(pr, px);
1456 if (pr->flags.throttling) {
1457 if (pr->limit.user.tx > tx)
1458 tx = pr->limit.user.tx;
1459 if (pr->limit.thermal.tx > tx)
1460 tx = pr->limit.thermal.tx;
1462 result = acpi_processor_set_throttling(pr, tx);
1467 pr->limit.state.px = px;
1468 pr->limit.state.tx = tx;
1470 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d] limit set to (P%d:T%d)\n",
1473 pr->limit.state.tx));
1477 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to set limit\n"));
1479 return_VALUE(result);
1484 acpi_processor_set_thermal_limit (
1489 struct acpi_processor *pr = NULL;
1490 struct acpi_device *device = NULL;
1494 ACPI_FUNCTION_TRACE("acpi_processor_set_thermal_limit");
1496 if ((type < ACPI_PROCESSOR_LIMIT_NONE)
1497 || (type > ACPI_PROCESSOR_LIMIT_DECREMENT))
1498 return_VALUE(-EINVAL);
1500 result = acpi_bus_get_device(handle, &device);
1502 return_VALUE(result);
1504 pr = (struct acpi_processor *) acpi_driver_data(device);
1506 return_VALUE(-ENODEV);
1508 if (!pr->flags.limit)
1509 return_VALUE(-ENODEV);
1511 /* Thermal limits are always relative to the current Px/Tx state. */
1512 if (pr->flags.performance)
1513 pr->limit.thermal.px = pr->performance.state;
1514 if (pr->flags.throttling)
1515 pr->limit.thermal.tx = pr->throttling.state;
1518 * Our default policy is to only use throttling at the lowest
1519 * performance state.
1522 px = pr->limit.thermal.px;
1523 tx = pr->limit.thermal.tx;
1527 case ACPI_PROCESSOR_LIMIT_NONE:
1532 case ACPI_PROCESSOR_LIMIT_INCREMENT:
1533 if (pr->flags.performance) {
1534 if (px == (pr->performance.state_count - 1))
1535 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1536 "At maximum performance state\n"));
1542 if (pr->flags.throttling) {
1543 if (tx == (pr->throttling.state_count - 1))
1544 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1545 "At maximum throttling state\n"));
1551 case ACPI_PROCESSOR_LIMIT_DECREMENT:
1552 if (pr->flags.performance) {
1553 if (px == pr->performance.platform_limit)
1554 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1555 "At minimum performance state\n"));
1561 if (pr->flags.throttling) {
1563 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1564 "At minimum throttling state\n"));
1572 pr->limit.thermal.px = px;
1573 pr->limit.thermal.tx = tx;
1575 result = acpi_processor_apply_limit(pr);
1577 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1578 "Unable to set thermal limit\n"));
1580 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Thermal limit now (P%d:T%d)\n",
1581 pr->limit.thermal.px,
1582 pr->limit.thermal.tx));
1584 return_VALUE(result);
1589 acpi_processor_get_limit_info (
1590 struct acpi_processor *pr)
1592 ACPI_FUNCTION_TRACE("acpi_processor_get_limit_info");
1595 return_VALUE(-EINVAL);
1597 if (pr->flags.performance || pr->flags.throttling)
1598 pr->flags.limit = 1;
1604 /* --------------------------------------------------------------------------
1605 FS Interface (/proc)
1606 -------------------------------------------------------------------------- */
1608 struct proc_dir_entry *acpi_processor_dir = NULL;
1611 acpi_processor_read_info (
1619 struct acpi_processor *pr = (struct acpi_processor *) data;
1623 ACPI_FUNCTION_TRACE("acpi_processor_read_info");
1625 if (!pr || (off != 0))
1628 p += sprintf(p, "processor id: %d\n",
1631 p += sprintf(p, "acpi id: %d\n",
1634 p += sprintf(p, "bus mastering control: %s\n",
1635 pr->flags.bm_control ? "yes" : "no");
1637 p += sprintf(p, "power management: %s\n",
1638 pr->flags.power ? "yes" : "no");
1640 p += sprintf(p, "throttling control: %s\n",
1641 pr->flags.throttling ? "yes" : "no");
1643 p += sprintf(p, "performance management: %s\n",
1644 pr->flags.performance ? "yes" : "no");
1646 p += sprintf(p, "limit interface: %s\n",
1647 pr->flags.limit ? "yes" : "no");
1651 if (len <= off+count) *eof = 1;
1652 *start = page + off;
1654 if (len>count) len = count;
1662 acpi_processor_read_power (
1670 struct acpi_processor *pr = (struct acpi_processor *) data;
1675 ACPI_FUNCTION_TRACE("acpi_processor_read_power");
1677 if (!pr || (off != 0))
1680 p += sprintf(p, "active state: C%d\n",
1683 p += sprintf(p, "default state: C%d\n",
1684 pr->power.default_state);
1686 p += sprintf(p, "bus master activity: %08x\n",
1687 pr->power.bm_activity);
1689 p += sprintf(p, "states:\n");
1691 for (i=1; i<ACPI_C_STATE_COUNT; i++) {
1693 p += sprintf(p, " %cC%d: ",
1694 (i == pr->power.state?'*':' '), i);
1696 if (!pr->power.states[i].valid) {
1697 p += sprintf(p, "<not supported>\n");
1701 if (pr->power.states[i].promotion.state)
1702 p += sprintf(p, "promotion[C%d] ",
1703 pr->power.states[i].promotion.state);
1705 p += sprintf(p, "promotion[--] ");
1707 if (pr->power.states[i].demotion.state)
1708 p += sprintf(p, "demotion[C%d] ",
1709 pr->power.states[i].demotion.state);
1711 p += sprintf(p, "demotion[--] ");
1713 p += sprintf(p, "latency[%03d] usage[%08d]\n",
1714 pr->power.states[i].latency,
1715 pr->power.states[i].usage);
1720 if (len <= off+count) *eof = 1;
1721 *start = page + off;
1723 if (len>count) len = count;
1731 acpi_processor_read_performance (
1739 struct acpi_processor *pr = (struct acpi_processor *) data;
1744 ACPI_FUNCTION_TRACE("acpi_processor_read_performance");
1746 if (!pr || (off != 0))
1749 if (!pr->flags.performance) {
1750 p += sprintf(p, "<not supported>\n");
1754 p += sprintf(p, "state count: %d\n",
1755 pr->performance.state_count);
1757 p += sprintf(p, "active state: P%d\n",
1758 pr->performance.state);
1760 p += sprintf(p, "states:\n");
1762 for (i=0; i<pr->performance.state_count; i++)
1763 p += sprintf(p, " %cP%d: %d MHz, %d mW, %d uS\n",
1764 (i == pr->performance.state?'*':' '), i,
1765 (u32) pr->performance.states[i].core_frequency,
1766 (u32) pr->performance.states[i].power,
1767 (u32) pr->performance.states[i].transition_latency);
1771 if (len <= off+count) *eof = 1;
1772 *start = page + off;
1774 if (len>count) len = count;
1782 acpi_processor_write_performance (
1785 unsigned long count,
1789 struct acpi_processor *pr = (struct acpi_processor *) data;
1790 char state_string[12] = {'\0'};
1792 ACPI_FUNCTION_TRACE("acpi_processor_write_performance");
1794 if (!pr || (count > sizeof(state_string) - 1))
1795 return_VALUE(-EINVAL);
1797 if (copy_from_user(state_string, buffer, count))
1798 return_VALUE(-EFAULT);
1800 state_string[count] = '\0';
1802 result = acpi_processor_set_performance(pr,
1803 simple_strtoul(state_string, NULL, 0));
1805 return_VALUE(result);
1807 return_VALUE(count);
1812 acpi_processor_read_throttling (
1820 struct acpi_processor *pr = (struct acpi_processor *) data;
1826 ACPI_FUNCTION_TRACE("acpi_processor_read_throttling");
1828 if (!pr || (off != 0))
1831 if (!(pr->throttling.state_count > 0)) {
1832 p += sprintf(p, "<not supported>\n");
1836 result = acpi_processor_get_throttling(pr);
1839 p += sprintf(p, "Could not determine current throttling state.\n");
1843 p += sprintf(p, "state count: %d\n",
1844 pr->throttling.state_count);
1846 p += sprintf(p, "active state: T%d\n",
1847 pr->throttling.state);
1849 p += sprintf(p, "states:\n");
1851 for (i=0; i<pr->throttling.state_count; i++)
1852 p += sprintf(p, " %cT%d: %02d%%\n",
1853 (i == pr->throttling.state?'*':' '), i,
1854 (pr->throttling.states[i].performance?pr->throttling.states[i].performance/10:0));
1858 if (len <= off+count) *eof = 1;
1859 *start = page + off;
1861 if (len>count) len = count;
1869 acpi_processor_write_throttling (
1872 unsigned long count,
1876 struct acpi_processor *pr = (struct acpi_processor *) data;
1877 char state_string[12] = {'\0'};
1879 ACPI_FUNCTION_TRACE("acpi_processor_write_throttling");
1881 if (!pr || (count > sizeof(state_string) - 1))
1882 return_VALUE(-EINVAL);
1884 if (copy_from_user(state_string, buffer, count))
1885 return_VALUE(-EFAULT);
1887 state_string[count] = '\0';
1889 result = acpi_processor_set_throttling(pr,
1890 simple_strtoul(state_string, NULL, 0));
1892 return_VALUE(result);
1894 return_VALUE(count);
1899 acpi_processor_read_limit (
1907 struct acpi_processor *pr = (struct acpi_processor *) data;
1911 ACPI_FUNCTION_TRACE("acpi_processor_read_limit");
1913 if (!pr || (off != 0))
1916 if (!pr->flags.limit) {
1917 p += sprintf(p, "<not supported>\n");
1921 p += sprintf(p, "active limit: P%d:T%d\n",
1922 pr->limit.state.px, pr->limit.state.tx);
1924 p += sprintf(p, "platform limit: P%d:T0\n",
1925 pr->flags.performance?pr->performance.platform_limit:0);
1927 p += sprintf(p, "user limit: P%d:T%d\n",
1928 pr->limit.user.px, pr->limit.user.tx);
1930 p += sprintf(p, "thermal limit: P%d:T%d\n",
1931 pr->limit.thermal.px, pr->limit.thermal.tx);
1935 if (len <= off+count) *eof = 1;
1936 *start = page + off;
1938 if (len>count) len = count;
1946 acpi_processor_write_limit (
1949 unsigned long count,
1953 struct acpi_processor *pr = (struct acpi_processor *) data;
1954 char limit_string[25] = {'\0'};
1958 ACPI_FUNCTION_TRACE("acpi_processor_write_limit");
1960 if (!pr || (count > sizeof(limit_string) - 1)) {
1961 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument\n"));
1962 return_VALUE(-EINVAL);
1965 if (copy_from_user(limit_string, buffer, count)) {
1966 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data\n"));
1967 return_VALUE(-EFAULT);
1970 limit_string[count] = '\0';
1972 if (sscanf(limit_string, "%d:%d", &px, &tx) != 2) {
1973 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data format\n"));
1974 return_VALUE(-EINVAL);
1977 if (pr->flags.performance) {
1978 if ((px < pr->performance.platform_limit)
1979 || (px > (pr->performance.state_count - 1))) {
1980 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid px\n"));
1981 return_VALUE(-EINVAL);
1983 pr->limit.user.px = px;
1986 if (pr->flags.throttling) {
1987 if ((tx < 0) || (tx > (pr->throttling.state_count - 1))) {
1988 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid tx\n"));
1989 return_VALUE(-EINVAL);
1991 pr->limit.user.tx = tx;
1994 result = acpi_processor_apply_limit(pr);
1996 return_VALUE(count);
2001 acpi_processor_add_fs (
2002 struct acpi_device *device)
2004 struct proc_dir_entry *entry = NULL;
2006 ACPI_FUNCTION_TRACE("acpi_processor_add_fs");
2008 if (!acpi_device_dir(device)) {
2009 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
2010 acpi_processor_dir);
2011 if (!acpi_device_dir(device))
2012 return_VALUE(-ENODEV);
2014 acpi_device_dir(device)->owner = THIS_MODULE;
2017 entry = create_proc_entry(ACPI_PROCESSOR_FILE_INFO,
2018 S_IRUGO, acpi_device_dir(device));
2020 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2021 "Unable to create '%s' fs entry\n",
2022 ACPI_PROCESSOR_FILE_INFO));
2024 entry->read_proc = acpi_processor_read_info;
2025 entry->data = acpi_driver_data(device);
2026 entry->owner = THIS_MODULE;
2030 entry = create_proc_entry(ACPI_PROCESSOR_FILE_POWER,
2031 S_IRUGO, acpi_device_dir(device));
2033 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2034 "Unable to create '%s' fs entry\n",
2035 ACPI_PROCESSOR_FILE_POWER));
2037 entry->read_proc = acpi_processor_read_power;
2038 entry->data = acpi_driver_data(device);
2039 entry->owner = THIS_MODULE;
2042 /* 'performance' [R/W] */
2043 entry = create_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE,
2044 S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
2046 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2047 "Unable to create '%s' fs entry\n",
2048 ACPI_PROCESSOR_FILE_PERFORMANCE));
2050 entry->read_proc = acpi_processor_read_performance;
2051 entry->write_proc = acpi_processor_write_performance;
2052 entry->data = acpi_driver_data(device);
2053 entry->owner = THIS_MODULE;
2056 /* 'throttling' [R/W] */
2057 entry = create_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
2058 S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
2060 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2061 "Unable to create '%s' fs entry\n",
2062 ACPI_PROCESSOR_FILE_THROTTLING));
2064 entry->read_proc = acpi_processor_read_throttling;
2065 entry->write_proc = acpi_processor_write_throttling;
2066 entry->data = acpi_driver_data(device);
2067 entry->owner = THIS_MODULE;
2071 entry = create_proc_entry(ACPI_PROCESSOR_FILE_LIMIT,
2072 S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
2074 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2075 "Unable to create '%s' fs entry\n",
2076 ACPI_PROCESSOR_FILE_LIMIT));
2078 entry->read_proc = acpi_processor_read_limit;
2079 entry->write_proc = acpi_processor_write_limit;
2080 entry->data = acpi_driver_data(device);
2081 entry->owner = THIS_MODULE;
2089 acpi_processor_remove_fs (
2090 struct acpi_device *device)
2092 ACPI_FUNCTION_TRACE("acpi_processor_remove_fs");
2094 if (acpi_device_dir(device)) {
2095 remove_proc_entry(acpi_device_bid(device), acpi_processor_dir);
2096 acpi_device_dir(device) = NULL;
2103 /* --------------------------------------------------------------------------
2105 -------------------------------------------------------------------------- */
2108 acpi_processor_get_info (
2109 struct acpi_processor *pr)
2111 acpi_status status = 0;
2112 union acpi_object object = {0};
2113 struct acpi_buffer buffer = {sizeof(union acpi_object), &object};
2114 static int cpu_index = 0;
2116 ACPI_FUNCTION_TRACE("acpi_processor_get_info");
2119 return_VALUE(-EINVAL);
2122 if (smp_num_cpus > 1)
2123 errata.smp = smp_num_cpus;
2126 * Extra Processor objects may be enumerated on MP systems with
2127 * less than the max # of CPUs. They should be ignored.
2129 if ((cpu_index + 1) > smp_num_cpus)
2130 return_VALUE(-ENODEV);
2133 acpi_processor_errata(pr);
2136 * Check to see if we have bus mastering arbitration control. This
2137 * is required for proper C3 usage (to maintain cache coherency).
2139 if (acpi_fadt.V1_pm2_cnt_blk && acpi_fadt.pm2_cnt_len) {
2140 pr->flags.bm_control = 1;
2141 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2142 "Bus mastering arbitration control present\n"));
2145 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2146 "No bus mastering arbitration control\n"));
2149 * Evalute the processor object. Note that it is common on SMP to
2150 * have the first (boot) processor with a valid PBLK address while
2151 * all others have a NULL address.
2153 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
2154 if (ACPI_FAILURE(status)) {
2155 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2156 "Error evaluating processor object\n"));
2157 return_VALUE(-ENODEV);
2161 * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
2162 * >>> 'acpi_get_processor_id(acpi_id, &id)' in arch/xxx/acpi.c
2164 pr->id = cpu_index++;
2165 pr->acpi_id = object.processor.proc_id;
2167 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
2170 if (!object.processor.pblk_address)
2171 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
2172 else if (object.processor.pblk_length != 6)
2173 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid PBLK length [%d]\n",
2174 object.processor.pblk_length));
2176 pr->throttling.address = object.processor.pblk_address;
2177 pr->throttling.duty_offset = acpi_fadt.duty_offset;
2178 pr->throttling.duty_width = acpi_fadt.duty_width;
2179 pr->power.states[ACPI_STATE_C2].address =
2180 object.processor.pblk_address + 4;
2181 pr->power.states[ACPI_STATE_C3].address =
2182 object.processor.pblk_address + 5;
2185 acpi_processor_get_power_info(pr);
2186 acpi_processor_get_performance_info(pr);
2187 acpi_processor_get_throttling_info(pr);
2188 acpi_processor_get_limit_info(pr);
2195 acpi_processor_notify (
2201 struct acpi_processor *pr = (struct acpi_processor *) data;
2202 struct acpi_device *device = NULL;
2204 ACPI_FUNCTION_TRACE("acpi_processor_notify");
2209 if (acpi_bus_get_device(pr->handle, &device))
2213 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
2214 result = acpi_processor_get_platform_limit(pr);
2216 acpi_processor_apply_limit(pr);
2218 acpi_bus_generate_event(device, event,
2219 pr->performance.platform_limit);
2221 case ACPI_PROCESSOR_NOTIFY_POWER:
2223 acpi_bus_generate_event(device, event, 0);
2226 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2227 "Unsupported event [0x%x]\n", event));
2236 acpi_processor_add (
2237 struct acpi_device *device)
2240 acpi_status status = AE_OK;
2241 struct acpi_processor *pr = NULL;
2244 ACPI_FUNCTION_TRACE("acpi_processor_add");
2247 return_VALUE(-EINVAL);
2249 pr = kmalloc(sizeof(struct acpi_processor), GFP_KERNEL);
2251 return_VALUE(-ENOMEM);
2252 memset(pr, 0, sizeof(struct acpi_processor));
2254 pr->handle = device->handle;
2255 sprintf(acpi_device_name(device), "%s", ACPI_PROCESSOR_DEVICE_NAME);
2256 sprintf(acpi_device_class(device), "%s", ACPI_PROCESSOR_CLASS);
2257 acpi_driver_data(device) = pr;
2259 result = acpi_processor_get_info(pr);
2263 result = acpi_processor_add_fs(device);
2267 status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
2268 acpi_processor_notify, pr);
2269 if (ACPI_FAILURE(status)) {
2270 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2271 "Error installing notify handler\n"));
2276 processors[pr->id] = pr;
2279 * Install the idle handler if processor power management is supported.
2280 * Note that the default idle handler (default_idle) will be used on
2281 * platforms that only support C1.
2283 if ((pr->id == 0) && (pr->flags.power)) {
2284 pm_idle_save = pm_idle;
2285 pm_idle = acpi_processor_idle;
2288 printk(KERN_INFO PREFIX "%s [%s] (supports",
2289 acpi_device_name(device), acpi_device_bid(device));
2290 for (i=1; i<ACPI_C_STATE_COUNT; i++)
2291 if (pr->power.states[i].valid)
2293 if (pr->flags.performance)
2294 printk(", %d performance states", pr->performance.state_count);
2295 if (pr->flags.throttling)
2296 printk(", %d throttling states", pr->throttling.state_count);
2301 acpi_processor_remove_fs(device);
2305 return_VALUE(result);
2310 acpi_processor_remove (
2311 struct acpi_device *device,
2314 acpi_status status = AE_OK;
2315 struct acpi_processor *pr = NULL;
2317 ACPI_FUNCTION_TRACE("acpi_processor_remove");
2319 if (!device || !acpi_driver_data(device))
2320 return_VALUE(-EINVAL);
2322 pr = (struct acpi_processor *) acpi_driver_data(device);
2324 /* Unregister the idle handler when processor #0 is removed. */
2326 pm_idle = pm_idle_save;
2328 status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
2329 acpi_processor_notify);
2330 if (ACPI_FAILURE(status)) {
2331 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2332 "Error removing notify handler\n"));
2335 acpi_processor_remove_fs(device);
2337 processors[pr->id] = NULL;
2346 acpi_processor_init (void)
2350 ACPI_FUNCTION_TRACE("acpi_processor_init");
2352 memset(&processors, 0, sizeof(processors));
2353 memset(&errata, 0, sizeof(errata));
2355 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
2356 if (!acpi_processor_dir)
2357 return_VALUE(-ENODEV);
2358 acpi_processor_dir->owner = THIS_MODULE;
2360 result = acpi_bus_register_driver(&acpi_processor_driver);
2362 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
2363 return_VALUE(-ENODEV);
2371 acpi_processor_exit (void)
2373 ACPI_FUNCTION_TRACE("acpi_processor_exit");
2375 acpi_bus_unregister_driver(&acpi_processor_driver);
2377 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
2383 module_init(acpi_processor_init);
2384 module_exit(acpi_processor_exit);
2386 EXPORT_SYMBOL(acpi_processor_set_thermal_limit);