xref: /titanic_52/usr/src/uts/sun4u/sys/cpudrv_mach.h (revision 0bb073995ac5a95bd35f2dd790df1ea3d8c2d507)
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  * There is no notion of changing topspeed on sun4u.
67  */
68 #define	CPUDRV_PM_REDEFINE_TOPSPEED(dip)
69 
70 /*
71  * There are no PPM callbacks for sun4u.
72  */
73 #define	CPUDRV_PM_SET_PPM_CALLBACKS()
74 
75 /*
76  * clock-divisors property tells the supported speeds
77  * as divisors of the normal speed. Divisors are in increasing
78  * order starting with 1 (for normal speed). For example, a
79  * property value of "1, 2, 32" represents full, 1/2 and 1/32
80  * speeds.
81  */
82 #define	CPUDRV_PM_GET_SPEEDS(cpudsp, speeds, nspeeds) { \
83 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, cpudsp->dip, \
84 	    DDI_PROP_DONTPASS, "clock-divisors", &speeds, \
85 	    &nspeeds) != DDI_PROP_SUCCESS) { \
86 		DPRINTF(D_PM_INIT, ("cpudrv_pm_init: instance %d: " \
87 		    "clock-divisors property not defined\n", \
88 				    ddi_get_instance(cpudsp->dip))); \
89 		return (DDI_FAILURE); \
90 	} \
91 }
92 #define	CPUDRV_PM_FREE_SPEEDS(speeds, unused) ddi_prop_free(speeds);
93 
94 /*
95  * Convert speed to Hz.
96  */
97 #define	CPUDRV_PM_SPEED_HZ(mhz, divisor) (((uint64_t)mhz * 1000000) / divisor)
98 
99 /*
100  * Compute the idle cnt percentage for a given speed.
101  */
102 #define	CPUDRV_PM_IDLE_CNT_PERCENT(hwm, speeds, i) \
103 	(100 - ((100 - hwm) * speeds[i]))
104 
105 /*
106  * Compute the user cnt percentage for a given speed.
107  */
108 #define	CPUDRV_PM_USER_CNT_PERCENT(hwm, speeds, i) \
109 	((hwm * speeds[i - 1]) / speeds[i])
110 
111 /*
112  * pm-components property defintions for sun4u.
113  *
114  * Fully constructed pm-components property should be an array of
115  * strings that look something like:
116  *
117  * pmc[0] = "NAME=CPU Speed"
118  * pmc[1] = "1=1/32 of Normal"
119  * pmc[2] = "2=1/2 of Normal"
120  * pmc[3] = "3=Normal"
121  *
122  * The amount of memory needed for each string is:
123  *      digits for power level + '=' + '1/' + digits for speed +
124  *      description text + '\0'
125  */
126 #define	CPUDRV_PM_COMP_NORMAL "Normal"
127 #define	CPUDRV_PM_COMP_OTHER " of Normal"
128 #define	CPUDRV_PM_COMP_SIZE() \
129 	(CPUDRV_PM_COMP_MAX_DIG + 1 + 2 + CPUDRV_PM_COMP_MAX_DIG + \
130 	    sizeof (CPUDRV_PM_COMP_OTHER) + 1);
131 #define	CPUDRV_PM_COMP_SPEED(cpupm, cur_spd) \
132 	((cur_spd == cpupm->head_spd) ? cur_spd->pm_level : cur_spd->speed)
133 #define	CPUDRV_PM_COMP_SPRINT(pmc, cpupm, cur_spd, comp_spd) { \
134 	if (cur_spd == cpupm->head_spd) \
135 		(void) sprintf(pmc, "%d=%s", comp_spd, CPUDRV_PM_COMP_NORMAL);\
136 	else \
137 		(void) sprintf(pmc, "%d=1/%d%s", cur_spd->pm_level, \
138 		    comp_spd, CPUDRV_PM_COMP_OTHER); \
139 }
140 
141 extern boolean_t cpudrv_pm_enabled(void);
142 
143 #ifdef  __cplusplus
144 }
145 #endif
146 
147 #endif /* _SYS_CPUDRV_MACH_H */
148