18906SEric.Saxe@Sun.COM /*
28906SEric.Saxe@Sun.COM * CDDL HEADER START
38906SEric.Saxe@Sun.COM *
48906SEric.Saxe@Sun.COM * The contents of this file are subject to the terms of the
58906SEric.Saxe@Sun.COM * Common Development and Distribution License (the "License").
68906SEric.Saxe@Sun.COM * You may not use this file except in compliance with the License.
78906SEric.Saxe@Sun.COM *
88906SEric.Saxe@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98906SEric.Saxe@Sun.COM * or http://www.opensolaris.org/os/licensing.
108906SEric.Saxe@Sun.COM * See the License for the specific language governing permissions
118906SEric.Saxe@Sun.COM * and limitations under the License.
128906SEric.Saxe@Sun.COM *
138906SEric.Saxe@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
148906SEric.Saxe@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
158906SEric.Saxe@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
168906SEric.Saxe@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
178906SEric.Saxe@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
188906SEric.Saxe@Sun.COM *
198906SEric.Saxe@Sun.COM * CDDL HEADER END
208906SEric.Saxe@Sun.COM */
218906SEric.Saxe@Sun.COM /*
228906SEric.Saxe@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
238906SEric.Saxe@Sun.COM * Use is subject to license terms.
248906SEric.Saxe@Sun.COM */
258906SEric.Saxe@Sun.COM
268906SEric.Saxe@Sun.COM #include <sys/x86_archext.h>
278906SEric.Saxe@Sun.COM #include <sys/machsystm.h>
288906SEric.Saxe@Sun.COM #include <sys/x_call.h>
298906SEric.Saxe@Sun.COM #include <sys/cpu_acpi.h>
308906SEric.Saxe@Sun.COM #include <sys/cpupm_throttle.h>
318906SEric.Saxe@Sun.COM #include <sys/dtrace.h>
328906SEric.Saxe@Sun.COM #include <sys/sdt.h>
338906SEric.Saxe@Sun.COM
348906SEric.Saxe@Sun.COM static int cpupm_throttle_init(cpu_t *);
358906SEric.Saxe@Sun.COM static void cpupm_throttle_fini(cpu_t *);
368906SEric.Saxe@Sun.COM static void cpupm_throttle(cpuset_t, uint32_t);
37*10488SMark.Haywood@Sun.COM static void cpupm_throttle_stop(cpu_t *);
388906SEric.Saxe@Sun.COM
398906SEric.Saxe@Sun.COM cpupm_state_ops_t cpupm_throttle_ops = {
408906SEric.Saxe@Sun.COM "Generic ACPI T-state Support",
418906SEric.Saxe@Sun.COM cpupm_throttle_init,
428906SEric.Saxe@Sun.COM cpupm_throttle_fini,
43*10488SMark.Haywood@Sun.COM cpupm_throttle,
44*10488SMark.Haywood@Sun.COM cpupm_throttle_stop
458906SEric.Saxe@Sun.COM };
468906SEric.Saxe@Sun.COM
478906SEric.Saxe@Sun.COM /*
488906SEric.Saxe@Sun.COM * Error returns
498906SEric.Saxe@Sun.COM */
508906SEric.Saxe@Sun.COM #define THROTTLE_RET_SUCCESS 0x00
518906SEric.Saxe@Sun.COM #define THROTTLE_RET_INCOMPLETE_DATA 0x01
528906SEric.Saxe@Sun.COM #define THROTTLE_RET_UNSUP_STATE 0x02
538906SEric.Saxe@Sun.COM #define THROTTLE_RET_TRANS_INCOMPLETE 0x03
548906SEric.Saxe@Sun.COM
558906SEric.Saxe@Sun.COM #define THROTTLE_LATENCY_WAIT 1
568906SEric.Saxe@Sun.COM
578906SEric.Saxe@Sun.COM /*
588906SEric.Saxe@Sun.COM * MSR register for clock modulation
598906SEric.Saxe@Sun.COM */
608906SEric.Saxe@Sun.COM #define IA32_CLOCK_MODULATION_MSR 0x19A
618906SEric.Saxe@Sun.COM
628906SEric.Saxe@Sun.COM /*
638906SEric.Saxe@Sun.COM * Debugging support
648906SEric.Saxe@Sun.COM */
658906SEric.Saxe@Sun.COM #ifdef DEBUG
668906SEric.Saxe@Sun.COM volatile int cpupm_throttle_debug = 0;
678906SEric.Saxe@Sun.COM #define CTDEBUG(arglist) if (cpupm_throttle_debug) printf arglist;
688906SEric.Saxe@Sun.COM #else
698906SEric.Saxe@Sun.COM #define CTDEBUG(arglist)
708906SEric.Saxe@Sun.COM #endif
718906SEric.Saxe@Sun.COM
728906SEric.Saxe@Sun.COM /*
738906SEric.Saxe@Sun.COM * Write the _PTC ctrl register. How it is written, depends upon the _PTC
748906SEric.Saxe@Sun.COM * APCI object value.
758906SEric.Saxe@Sun.COM */
768906SEric.Saxe@Sun.COM static int
write_ctrl(cpu_acpi_handle_t handle,uint32_t ctrl)778906SEric.Saxe@Sun.COM write_ctrl(cpu_acpi_handle_t handle, uint32_t ctrl)
788906SEric.Saxe@Sun.COM {
798906SEric.Saxe@Sun.COM cpu_acpi_ptc_t *ptc_ctrl;
808906SEric.Saxe@Sun.COM uint64_t reg;
818906SEric.Saxe@Sun.COM int ret = 0;
828906SEric.Saxe@Sun.COM
838906SEric.Saxe@Sun.COM ptc_ctrl = CPU_ACPI_PTC_CTRL(handle);
848906SEric.Saxe@Sun.COM
858906SEric.Saxe@Sun.COM switch (ptc_ctrl->cr_addrspace_id) {
868906SEric.Saxe@Sun.COM case ACPI_ADR_SPACE_FIXED_HARDWARE:
878906SEric.Saxe@Sun.COM /*
888906SEric.Saxe@Sun.COM * Read current thermal state because reserved bits must be
898906SEric.Saxe@Sun.COM * preserved, compose new value, and write it.The writable
908906SEric.Saxe@Sun.COM * bits are 4:1 (1 to 4).
918906SEric.Saxe@Sun.COM * Bits 3:1 => On-Demand Clock Modulation Duty Cycle
928906SEric.Saxe@Sun.COM * Bit 4 => On-Demand Clock Modulation Enable
938906SEric.Saxe@Sun.COM * Left shift ctrl by 1 to allign with bits 1-4 of MSR
948906SEric.Saxe@Sun.COM */
958906SEric.Saxe@Sun.COM reg = rdmsr(IA32_CLOCK_MODULATION_MSR);
968906SEric.Saxe@Sun.COM reg &= ~((uint64_t)0x1E);
978906SEric.Saxe@Sun.COM reg |= ctrl;
988906SEric.Saxe@Sun.COM wrmsr(IA32_CLOCK_MODULATION_MSR, reg);
998906SEric.Saxe@Sun.COM break;
1008906SEric.Saxe@Sun.COM
1018906SEric.Saxe@Sun.COM case ACPI_ADR_SPACE_SYSTEM_IO:
1028906SEric.Saxe@Sun.COM ret = cpu_acpi_write_port(ptc_ctrl->cr_address, ctrl,
1038906SEric.Saxe@Sun.COM ptc_ctrl->cr_width);
1048906SEric.Saxe@Sun.COM break;
1058906SEric.Saxe@Sun.COM
1068906SEric.Saxe@Sun.COM default:
1078906SEric.Saxe@Sun.COM DTRACE_PROBE1(throttle_ctrl_unsupported_type, uint8_t,
1088906SEric.Saxe@Sun.COM ptc_ctrl->cr_addrspace_id);
1098906SEric.Saxe@Sun.COM
1108906SEric.Saxe@Sun.COM ret = -1;
1118906SEric.Saxe@Sun.COM }
1128906SEric.Saxe@Sun.COM
1138906SEric.Saxe@Sun.COM DTRACE_PROBE1(throttle_ctrl_write, uint32_t, ctrl);
1148906SEric.Saxe@Sun.COM DTRACE_PROBE1(throttle_ctrl_write_err, int, ret);
1158906SEric.Saxe@Sun.COM
1168906SEric.Saxe@Sun.COM return (ret);
1178906SEric.Saxe@Sun.COM }
1188906SEric.Saxe@Sun.COM
1198906SEric.Saxe@Sun.COM static int
read_status(cpu_acpi_handle_t handle,uint32_t * stat)1208906SEric.Saxe@Sun.COM read_status(cpu_acpi_handle_t handle, uint32_t *stat)
1218906SEric.Saxe@Sun.COM {
1228906SEric.Saxe@Sun.COM cpu_acpi_ptc_t *ptc_stat;
1238906SEric.Saxe@Sun.COM uint64_t reg;
1248906SEric.Saxe@Sun.COM int ret = 0;
1258906SEric.Saxe@Sun.COM
1268906SEric.Saxe@Sun.COM ptc_stat = CPU_ACPI_PTC_STATUS(handle);
1278906SEric.Saxe@Sun.COM
1288906SEric.Saxe@Sun.COM switch (ptc_stat->cr_addrspace_id) {
1298906SEric.Saxe@Sun.COM case ACPI_ADR_SPACE_FIXED_HARDWARE:
1308906SEric.Saxe@Sun.COM reg = rdmsr(IA32_CLOCK_MODULATION_MSR);
1318906SEric.Saxe@Sun.COM *stat = reg & 0x1E;
1328906SEric.Saxe@Sun.COM ret = 0;
1338906SEric.Saxe@Sun.COM break;
1348906SEric.Saxe@Sun.COM
1358906SEric.Saxe@Sun.COM case ACPI_ADR_SPACE_SYSTEM_IO:
1368906SEric.Saxe@Sun.COM ret = cpu_acpi_read_port(ptc_stat->cr_address, stat,
1378906SEric.Saxe@Sun.COM ptc_stat->cr_width);
1388906SEric.Saxe@Sun.COM break;
1398906SEric.Saxe@Sun.COM
1408906SEric.Saxe@Sun.COM default:
1418906SEric.Saxe@Sun.COM DTRACE_PROBE1(throttle_status_unsupported_type, uint8_t,
1428906SEric.Saxe@Sun.COM ptc_stat->cr_addrspace_id);
1438906SEric.Saxe@Sun.COM
1448906SEric.Saxe@Sun.COM return (-1);
1458906SEric.Saxe@Sun.COM }
1468906SEric.Saxe@Sun.COM
1478906SEric.Saxe@Sun.COM DTRACE_PROBE1(throttle_status_read, uint32_t, *stat);
1488906SEric.Saxe@Sun.COM DTRACE_PROBE1(throttle_status_read_err, int, ret);
1498906SEric.Saxe@Sun.COM
1508906SEric.Saxe@Sun.COM return (ret);
1518906SEric.Saxe@Sun.COM }
1528906SEric.Saxe@Sun.COM
1538906SEric.Saxe@Sun.COM /*
1548906SEric.Saxe@Sun.COM * Transition the current processor to the requested throttling state.
1558906SEric.Saxe@Sun.COM */
1568906SEric.Saxe@Sun.COM static void
cpupm_tstate_transition(uint32_t req_state)1578906SEric.Saxe@Sun.COM cpupm_tstate_transition(uint32_t req_state)
1588906SEric.Saxe@Sun.COM {
1598906SEric.Saxe@Sun.COM cpupm_mach_state_t *mach_state =
1608906SEric.Saxe@Sun.COM (cpupm_mach_state_t *)CPU->cpu_m.mcpu_pm_mach_state;
1618906SEric.Saxe@Sun.COM cpu_acpi_handle_t handle = mach_state->ms_acpi_handle;
1628906SEric.Saxe@Sun.COM cpu_acpi_tstate_t *req_tstate;
1638906SEric.Saxe@Sun.COM uint32_t ctrl;
1648906SEric.Saxe@Sun.COM uint32_t stat;
1658906SEric.Saxe@Sun.COM int i;
1668906SEric.Saxe@Sun.COM
1678906SEric.Saxe@Sun.COM req_tstate = (cpu_acpi_tstate_t *)CPU_ACPI_TSTATES(handle);
1688906SEric.Saxe@Sun.COM req_tstate += req_state;
1698906SEric.Saxe@Sun.COM DTRACE_PROBE1(throttle_transition, uint32_t,
1708906SEric.Saxe@Sun.COM CPU_ACPI_FREQPER(req_tstate));
1718906SEric.Saxe@Sun.COM
1728906SEric.Saxe@Sun.COM /*
1738906SEric.Saxe@Sun.COM * Initiate the processor t-state change.
1748906SEric.Saxe@Sun.COM */
1758906SEric.Saxe@Sun.COM ctrl = CPU_ACPI_TSTATE_CTRL(req_tstate);
1768906SEric.Saxe@Sun.COM if (write_ctrl(handle, ctrl) != 0) {
1778906SEric.Saxe@Sun.COM return;
1788906SEric.Saxe@Sun.COM }
1798906SEric.Saxe@Sun.COM
1808906SEric.Saxe@Sun.COM /*
1818906SEric.Saxe@Sun.COM * If status is zero, then transition is synchronous and
1828906SEric.Saxe@Sun.COM * no status value comparison is required.
1838906SEric.Saxe@Sun.COM */
1848906SEric.Saxe@Sun.COM if (CPU_ACPI_TSTATE_STAT(req_tstate) == 0) {
1858906SEric.Saxe@Sun.COM return;
1868906SEric.Saxe@Sun.COM }
1878906SEric.Saxe@Sun.COM
1888906SEric.Saxe@Sun.COM /* Wait until switch is complete, but bound the loop just in case. */
1898906SEric.Saxe@Sun.COM for (i = CPU_ACPI_TSTATE_TRANSLAT(req_tstate) * 2; i >= 0;
1908906SEric.Saxe@Sun.COM i -= THROTTLE_LATENCY_WAIT) {
1918906SEric.Saxe@Sun.COM if (read_status(handle, &stat) == 0 &&
1928906SEric.Saxe@Sun.COM CPU_ACPI_TSTATE_STAT(req_tstate) == stat)
1938906SEric.Saxe@Sun.COM break;
1948906SEric.Saxe@Sun.COM drv_usecwait(THROTTLE_LATENCY_WAIT);
1958906SEric.Saxe@Sun.COM }
1968906SEric.Saxe@Sun.COM
1978906SEric.Saxe@Sun.COM if (CPU_ACPI_TSTATE_STAT(req_tstate) != stat) {
1988906SEric.Saxe@Sun.COM DTRACE_PROBE(throttle_transition_incomplete);
1998906SEric.Saxe@Sun.COM }
2008906SEric.Saxe@Sun.COM }
2018906SEric.Saxe@Sun.COM
2028906SEric.Saxe@Sun.COM static void
cpupm_throttle(cpuset_t set,uint32_t throtl_lvl)2038906SEric.Saxe@Sun.COM cpupm_throttle(cpuset_t set, uint32_t throtl_lvl)
2048906SEric.Saxe@Sun.COM {
2058906SEric.Saxe@Sun.COM /*
2068906SEric.Saxe@Sun.COM * If thread is already running on target CPU then just
2078906SEric.Saxe@Sun.COM * make the transition request. Otherwise, we'll need to
2088906SEric.Saxe@Sun.COM * make a cross-call.
2098906SEric.Saxe@Sun.COM */
2108906SEric.Saxe@Sun.COM kpreempt_disable();
2118906SEric.Saxe@Sun.COM if (CPU_IN_SET(set, CPU->cpu_id)) {
2128906SEric.Saxe@Sun.COM cpupm_tstate_transition(throtl_lvl);
2138906SEric.Saxe@Sun.COM CPUSET_DEL(set, CPU->cpu_id);
2148906SEric.Saxe@Sun.COM }
2158906SEric.Saxe@Sun.COM if (!CPUSET_ISNULL(set)) {
2169489SJoe.Bonasera@sun.com xc_call((xc_arg_t)throtl_lvl, NULL, NULL,
2179489SJoe.Bonasera@sun.com CPUSET2BV(set), (xc_func_t)cpupm_tstate_transition);
2188906SEric.Saxe@Sun.COM }
2198906SEric.Saxe@Sun.COM kpreempt_enable();
2208906SEric.Saxe@Sun.COM }
2218906SEric.Saxe@Sun.COM
2228906SEric.Saxe@Sun.COM static int
cpupm_throttle_init(cpu_t * cp)2238906SEric.Saxe@Sun.COM cpupm_throttle_init(cpu_t *cp)
2248906SEric.Saxe@Sun.COM {
2258906SEric.Saxe@Sun.COM cpupm_mach_state_t *mach_state =
2268906SEric.Saxe@Sun.COM (cpupm_mach_state_t *)cp->cpu_m.mcpu_pm_mach_state;
2278906SEric.Saxe@Sun.COM cpu_acpi_handle_t handle = mach_state->ms_acpi_handle;
2288906SEric.Saxe@Sun.COM cpu_acpi_ptc_t *ptc_stat;
22910075SMark.Haywood@Sun.COM int ret;
2308906SEric.Saxe@Sun.COM
23110075SMark.Haywood@Sun.COM if ((ret = cpu_acpi_cache_tstate_data(handle)) != 0) {
23210075SMark.Haywood@Sun.COM if (ret < 0)
23310075SMark.Haywood@Sun.COM cmn_err(CE_NOTE,
23410075SMark.Haywood@Sun.COM "!Support for CPU throttling is being "
23510075SMark.Haywood@Sun.COM "disabled due to errors parsing ACPI T-state "
23610075SMark.Haywood@Sun.COM "objects exported by BIOS.");
2378906SEric.Saxe@Sun.COM cpupm_throttle_fini(cp);
2388906SEric.Saxe@Sun.COM return (THROTTLE_RET_INCOMPLETE_DATA);
2398906SEric.Saxe@Sun.COM }
2408906SEric.Saxe@Sun.COM
2418906SEric.Saxe@Sun.COM /*
2428906SEric.Saxe@Sun.COM * Check the address space used for transitions
2438906SEric.Saxe@Sun.COM */
2448906SEric.Saxe@Sun.COM ptc_stat = CPU_ACPI_PTC_STATUS(handle);
2458906SEric.Saxe@Sun.COM switch (ptc_stat->cr_addrspace_id) {
2468906SEric.Saxe@Sun.COM case ACPI_ADR_SPACE_FIXED_HARDWARE:
2478906SEric.Saxe@Sun.COM CTDEBUG(("T-State transitions will use fixed hardware\n"));
2488906SEric.Saxe@Sun.COM break;
2498906SEric.Saxe@Sun.COM case ACPI_ADR_SPACE_SYSTEM_IO:
2508906SEric.Saxe@Sun.COM CTDEBUG(("T-State transitions will use System IO\n"));
2518906SEric.Saxe@Sun.COM break;
2528906SEric.Saxe@Sun.COM default:
25310075SMark.Haywood@Sun.COM cmn_err(CE_NOTE, "!_PTC configured for unsupported "
2548906SEric.Saxe@Sun.COM "address space type = %d.", ptc_stat->cr_addrspace_id);
2558906SEric.Saxe@Sun.COM return (THROTTLE_RET_INCOMPLETE_DATA);
2568906SEric.Saxe@Sun.COM }
2578906SEric.Saxe@Sun.COM
2588906SEric.Saxe@Sun.COM cpupm_alloc_domains(cp, CPUPM_T_STATES);
2598906SEric.Saxe@Sun.COM
2608906SEric.Saxe@Sun.COM return (THROTTLE_RET_SUCCESS);
2618906SEric.Saxe@Sun.COM }
2628906SEric.Saxe@Sun.COM
2638906SEric.Saxe@Sun.COM static void
cpupm_throttle_fini(cpu_t * cp)2648906SEric.Saxe@Sun.COM cpupm_throttle_fini(cpu_t *cp)
2658906SEric.Saxe@Sun.COM {
2668906SEric.Saxe@Sun.COM cpupm_mach_state_t *mach_state =
2678906SEric.Saxe@Sun.COM (cpupm_mach_state_t *)cp->cpu_m.mcpu_pm_mach_state;
2688906SEric.Saxe@Sun.COM cpu_acpi_handle_t handle = mach_state->ms_acpi_handle;
2698906SEric.Saxe@Sun.COM
2708906SEric.Saxe@Sun.COM cpupm_free_domains(&cpupm_tstate_domains);
2718906SEric.Saxe@Sun.COM cpu_acpi_free_tstate_data(handle);
2728906SEric.Saxe@Sun.COM }
2738906SEric.Saxe@Sun.COM
274*10488SMark.Haywood@Sun.COM static void
cpupm_throttle_stop(cpu_t * cp)275*10488SMark.Haywood@Sun.COM cpupm_throttle_stop(cpu_t *cp)
276*10488SMark.Haywood@Sun.COM {
277*10488SMark.Haywood@Sun.COM cpupm_mach_state_t *mach_state =
278*10488SMark.Haywood@Sun.COM (cpupm_mach_state_t *)cp->cpu_m.mcpu_pm_mach_state;
279*10488SMark.Haywood@Sun.COM cpu_acpi_handle_t handle = mach_state->ms_acpi_handle;
280*10488SMark.Haywood@Sun.COM
281*10488SMark.Haywood@Sun.COM cpupm_remove_domains(cp, CPUPM_T_STATES, &cpupm_tstate_domains);
282*10488SMark.Haywood@Sun.COM cpu_acpi_free_tstate_data(handle);
283*10488SMark.Haywood@Sun.COM }
284*10488SMark.Haywood@Sun.COM
2858906SEric.Saxe@Sun.COM /*
2868906SEric.Saxe@Sun.COM * This routine reads the ACPI _TPC object. It's accessed as a callback
2878906SEric.Saxe@Sun.COM * by the cpu driver whenever a _TPC change notification is received.
2888906SEric.Saxe@Sun.COM */
2898906SEric.Saxe@Sun.COM static int
cpupm_throttle_get_max(processorid_t cpu_id)2908906SEric.Saxe@Sun.COM cpupm_throttle_get_max(processorid_t cpu_id)
2918906SEric.Saxe@Sun.COM {
2928906SEric.Saxe@Sun.COM cpu_t *cp = cpu[cpu_id];
2938906SEric.Saxe@Sun.COM cpupm_mach_state_t *mach_state =
2948906SEric.Saxe@Sun.COM (cpupm_mach_state_t *)(cp->cpu_m.mcpu_pm_mach_state);
2958906SEric.Saxe@Sun.COM cpu_acpi_handle_t handle;
2968906SEric.Saxe@Sun.COM int throtl_level;
2978906SEric.Saxe@Sun.COM int max_throttle_lvl;
2988906SEric.Saxe@Sun.COM uint_t num_throtl;
2998906SEric.Saxe@Sun.COM
3008906SEric.Saxe@Sun.COM if (mach_state == NULL) {
3018906SEric.Saxe@Sun.COM return (-1);
3028906SEric.Saxe@Sun.COM }
3038906SEric.Saxe@Sun.COM
3048906SEric.Saxe@Sun.COM handle = mach_state->ms_acpi_handle;
3058906SEric.Saxe@Sun.COM ASSERT(handle != NULL);
3068906SEric.Saxe@Sun.COM
3078906SEric.Saxe@Sun.COM cpu_acpi_cache_tpc(handle);
3088906SEric.Saxe@Sun.COM throtl_level = CPU_ACPI_TPC(handle);
3098906SEric.Saxe@Sun.COM
3108906SEric.Saxe@Sun.COM num_throtl = CPU_ACPI_TSTATES_COUNT(handle);
3118906SEric.Saxe@Sun.COM
3128906SEric.Saxe@Sun.COM max_throttle_lvl = num_throtl - 1;
3138906SEric.Saxe@Sun.COM if ((throtl_level < 0) || (throtl_level > max_throttle_lvl)) {
3148906SEric.Saxe@Sun.COM cmn_err(CE_NOTE, "!cpupm_throttle_get_max: CPU %d: "
3158906SEric.Saxe@Sun.COM "_TPC out of range %d", cp->cpu_id, throtl_level);
3168906SEric.Saxe@Sun.COM throtl_level = 0;
3178906SEric.Saxe@Sun.COM }
3188906SEric.Saxe@Sun.COM
3198906SEric.Saxe@Sun.COM return (throtl_level);
3208906SEric.Saxe@Sun.COM }
3218906SEric.Saxe@Sun.COM
3228906SEric.Saxe@Sun.COM /*
3238906SEric.Saxe@Sun.COM * Take care of CPU throttling when _TPC notification arrives
3248906SEric.Saxe@Sun.COM */
3258906SEric.Saxe@Sun.COM void
cpupm_throttle_manage_notification(void * ctx)3268906SEric.Saxe@Sun.COM cpupm_throttle_manage_notification(void *ctx)
3278906SEric.Saxe@Sun.COM {
3288906SEric.Saxe@Sun.COM cpu_t *cp = ctx;
3298906SEric.Saxe@Sun.COM processorid_t cpu_id = cp->cpu_id;
3308906SEric.Saxe@Sun.COM cpupm_mach_state_t *mach_state =
3318906SEric.Saxe@Sun.COM (cpupm_mach_state_t *)cp->cpu_m.mcpu_pm_mach_state;
3328906SEric.Saxe@Sun.COM boolean_t is_ready;
3338906SEric.Saxe@Sun.COM int new_level;
3348906SEric.Saxe@Sun.COM
3358906SEric.Saxe@Sun.COM if (mach_state == NULL) {
3368906SEric.Saxe@Sun.COM return;
3378906SEric.Saxe@Sun.COM }
3388906SEric.Saxe@Sun.COM
3398906SEric.Saxe@Sun.COM /*
3408906SEric.Saxe@Sun.COM * We currently refuse to power-manage if the CPU is not ready to
3418906SEric.Saxe@Sun.COM * take cross calls (cross calls fail silently if CPU is not ready
3428906SEric.Saxe@Sun.COM * for it).
3438906SEric.Saxe@Sun.COM *
344*10488SMark.Haywood@Sun.COM * Additionally, for x86 platforms we cannot power-manage an instance,
345*10488SMark.Haywood@Sun.COM * until it has been initialized.
3468906SEric.Saxe@Sun.COM */
347*10488SMark.Haywood@Sun.COM is_ready = (cp->cpu_flags & CPU_READY) && cpupm_throttle_ready(cp);
3488906SEric.Saxe@Sun.COM if (!is_ready)
3498906SEric.Saxe@Sun.COM return;
3508906SEric.Saxe@Sun.COM
3518906SEric.Saxe@Sun.COM if (!(mach_state->ms_caps & CPUPM_T_STATES))
3528906SEric.Saxe@Sun.COM return;
3538906SEric.Saxe@Sun.COM ASSERT(mach_state->ms_tstate.cma_ops != NULL);
3548906SEric.Saxe@Sun.COM
3558906SEric.Saxe@Sun.COM /*
3568906SEric.Saxe@Sun.COM * Get the new T-State support level
3578906SEric.Saxe@Sun.COM */
3588906SEric.Saxe@Sun.COM new_level = cpupm_throttle_get_max(cpu_id);
3598906SEric.Saxe@Sun.COM
3608906SEric.Saxe@Sun.COM cpupm_state_change(cp, new_level, CPUPM_T_STATES);
3618906SEric.Saxe@Sun.COM }
362