xref: /illumos-gate/usr/src/uts/sun4u/sys/cpudrv_mach.h (revision c3ea2840)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_CPUDRV_MACH_H
27 #define	_SYS_CPUDRV_MACH_H
28 
29 #include <sys/cpu_module.h>
30 #include <sys/cpudrv.h>
31 
32 #ifdef  __cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * We currently refuse to power manage if the CPU in not ready to
38  * take cross calls (cross calls fail silently if CPU is not ready
39  * for it).
40  */
41 #define	CPUDRV_PM_XCALL_IS_READY(cpuid) (CPU_XCALL_READY(cpuid))
42 
43 /*
44  * If a failure occurs during attach(), then CPU power management
45  * is disabled.
46  */
47 extern boolean_t cpudrv_enabled;
48 
49 #define	CPUDRV_PM_DISABLE() (cpudrv_enabled = B_FALSE)
50 
51 #define	CPUDRV_PM_DISABLED() (!cpudrv_enabled)
52 
53 #define	CPUDRV_PM_POWER_ENABLED(cpudsp) cpudrv_pm_enabled()
54 
55 /*
56  * Currently, there is no governor on sun4u,
57  */
58 #define	CPUDRV_PM_RESET_GOVERNOR_THREAD(cpupm)
59 
60 /*
61  * Currently, there is no need for a handler on sun4u.
62  */
63 #define	CPUDRV_PM_INSTALL_MAX_CHANGE_HANDLER(cpudsp, dip)
64 
65 /*
66  * Topspeed is always the head speed.
67  */
68 #define	CPUDRV_PM_TOPSPEED(cpupm)	(cpupm)->head_spd
69 
70 /*
71  * There is no notion of changing topspeed on sun4u.
72  */
73 #define	CPUDRV_PM_REDEFINE_TOPSPEED(dip)
74 
75 /*
76  * There are no PPM callbacks for sun4u.
77  */
78 #define	CPUDRV_PM_SET_PPM_CALLBACKS()
79 
80 /*
81  * clock-divisors property tells the supported speeds
82  * as divisors of the normal speed. Divisors are in increasing
83  * order starting with 1 (for normal speed). For example, a
84  * property value of "1, 2, 32" represents full, 1/2 and 1/32
85  * speeds.
86  */
87 #define	CPUDRV_PM_GET_SPEEDS(cpudsp, speeds, nspeeds) { \
88 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, cpudsp->dip, \
89 	    DDI_PROP_DONTPASS, "clock-divisors", &speeds, \
90 	    &nspeeds) != DDI_PROP_SUCCESS) { \
91 		DPRINTF(D_PM_INIT, ("cpudrv_pm_init: instance %d: " \
92 		    "clock-divisors property not defined\n", \
93 				    ddi_get_instance(cpudsp->dip))); \
94 		return (DDI_FAILURE); \
95 	} \
96 }
97 #define	CPUDRV_PM_FREE_SPEEDS(speeds, unused) ddi_prop_free(speeds);
98 
99 /*
100  * Convert speed to Hz.
101  */
102 #define	CPUDRV_PM_SPEED_HZ(mhz, divisor) (((uint64_t)mhz * 1000000) / divisor)
103 
104 /*
105  * Compute the idle cnt percentage for a given speed.
106  */
107 #define	CPUDRV_PM_IDLE_CNT_PERCENT(hwm, speeds, i) \
108 	(100 - ((100 - hwm) * speeds[i]))
109 
110 /*
111  * Compute the user cnt percentage for a given speed.
112  */
113 #define	CPUDRV_PM_USER_CNT_PERCENT(hwm, speeds, i) \
114 	((hwm * speeds[i - 1]) / speeds[i])
115 
116 /*
117  * pm-components property defintions for sun4u.
118  *
119  * Fully constructed pm-components property should be an array of
120  * strings that look something like:
121  *
122  * pmc[0] = "NAME=CPU Speed"
123  * pmc[1] = "1=1/32 of Normal"
124  * pmc[2] = "2=1/2 of Normal"
125  * pmc[3] = "3=Normal"
126  *
127  * The amount of memory needed for each string is:
128  *      digits for power level + '=' + '1/' + digits for speed +
129  *      description text + '\0'
130  */
131 #define	CPUDRV_PM_COMP_NORMAL "Normal"
132 #define	CPUDRV_PM_COMP_OTHER " of Normal"
133 #define	CPUDRV_PM_COMP_SIZE() \
134 	(CPUDRV_PM_COMP_MAX_DIG + 1 + 2 + CPUDRV_PM_COMP_MAX_DIG + \
135 	    sizeof (CPUDRV_PM_COMP_OTHER) + 1);
136 #define	CPUDRV_PM_COMP_SPEED(cpupm, cur_spd) \
137 	((cur_spd == cpupm->head_spd) ? cur_spd->pm_level : cur_spd->speed)
138 #define	CPUDRV_PM_COMP_SPRINT(pmc, cpupm, cur_spd, comp_spd) { \
139 	if (cur_spd == cpupm->head_spd) \
140 		(void) sprintf(pmc, "%d=%s", comp_spd, CPUDRV_PM_COMP_NORMAL);\
141 	else \
142 		(void) sprintf(pmc, "%d=1/%d%s", cur_spd->pm_level, \
143 		    comp_spd, CPUDRV_PM_COMP_OTHER); \
144 }
145 
146 extern boolean_t cpudrv_pm_enabled(void);
147 
148 #ifdef  __cplusplus
149 }
150 #endif
151 
152 #endif /* _SYS_CPUDRV_MACH_H */
153