xref: /illumos-gate/usr/src/uts/i86pc/sys/cpudrv_mach.h (revision 1f5207b7604fb44407eb4342aff613f7c4508508)
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 2009 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/cpuvar.h>
30 #include <sys/cpupm.h>
31 #include <sys/cpu_acpi.h>
32 #include <sys/cpudrv.h>
33 #include <sys/ksynch.h>
34 
35 #ifdef  __cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * We currently refuse to power manage if the CPU in not ready to
41  * take cross calls (cross calls fail silently if CPU is not ready
42  * for it).
43  */
44 extern cpuset_t cpu_ready_set;
45 #define	CPUDRV_XCALL_IS_READY(cpuid) CPU_IN_SET(cpu_ready_set, (cpuid))
46 
47 /*
48  * We're about to exit the _PPC thread so reset tag.
49  */
50 #define	CPUDRV_RESET_GOVERNOR_THREAD(cpupm) { \
51 	if (curthread == cpupm->pm_governor_thread) \
52 		cpupm->pm_governor_thread = NULL; \
53 }
54 
55 /*
56  * The current top speed as defined by the _PPC.
57  */
58 #define	CPUDRV_TOPSPEED(cpupm)	(cpupm)->top_spd
59 
60 /*
61  * Install a _PPC/_TPC change notification handler.
62  */
63 #define	CPUDRV_INSTALL_MAX_CHANGE_HANDLER(cpudsp) \
64 	cpudrv_install_notify_handler(cpudsp);
65 
66 /*
67  * Uninstall _PPC/_TPC change notification handler.
68  */
69 #define	CPUDRV_UNINSTALL_MAX_CHANGE_HANDLER(cpudsp) \
70 	cpudrv_uninstall_notify_handler(cpudsp);
71 
72 /*
73  * Redefine the topspeed.
74  */
75 #define	CPUDRV_REDEFINE_TOPSPEED(dip) cpudrv_redefine_topspeed(dip)
76 
77 /*
78  * Set callbacks so that PPM can callback into CPUDRV
79  */
80 #define	CPUDRV_SET_PPM_CALLBACKS() { \
81 	cpupm_get_topspeed_callb = cpudrv_get_topspeed; \
82 	cpupm_set_topspeed_callb = cpudrv_set_topspeed; \
83 }
84 
85 /*
86  * ACPI provides the supported speeds.
87  */
88 #define	CPUDRV_GET_SPEEDS(cpudsp, speeds, nspeeds) \
89 	nspeeds = cpudrv_get_speeds(cpudsp, &speeds);
90 #define	CPUDRV_FREE_SPEEDS(speeds, nspeeds) \
91 	cpudrv_free_speeds(speeds, nspeeds);
92 
93 /*
94  * ACPI provides the supported C-states.
95  */
96 #define	CPUDRV_GET_MAX_CSTATES(handle) \
97 	cpu_acpi_get_max_cstates(handle);
98 
99 /*
100  * Compute the idle cnt percentage for a given speed.
101  */
102 #define	CPUDRV_IDLE_CNT_PERCENT(hwm, speeds, i) \
103 	(100 - (((100 - hwm) * speeds[0]) / speeds[i]))
104 
105 /*
106  * Compute the user cnt percentage for a given speed.
107  */
108 #define	CPUDRV_USER_CNT_PERCENT(hwm, speeds, i) \
109 	((hwm * speeds[i]) / speeds[i - 1]);
110 
111 /*
112  * pm-components property defintions for this machine type.
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=2800MHz"
119  * pmc[2] = "2=3200MHz"
120  *
121  * The amount of memory needed for each string is:
122  * 	digits for power level + '=' +  digits for freq + 'MHz' + '\0'
123  */
124 #define	CPUDRV_COMP_SIZE() \
125 	(CPUDRV_COMP_MAX_DIG + 1 + CPUDRV_COMP_MAX_DIG + 3 + 1);
126 #define	CPUDRV_COMP_SPEED(cpupm, cur_spd) cur_spd->speed;
127 #define	CPUDRV_COMP_SPRINT(pmc, cpupm, cur_spd, comp_spd) \
128 	(void) sprintf(pmc, "%d=%dMHz", cur_spd->pm_level, comp_spd);
129 
130 extern void cpudrv_set_topspeed(void *, int);
131 extern int cpudrv_get_topspeed(void *);
132 extern int cpudrv_get_topthrottle(cpu_t *);
133 extern void cpudrv_manage_throttling(void *);
134 extern void cpudrv_install_notify_handler(cpudrv_devstate_t *);
135 extern void cpudrv_uninstall_notify_handler(cpudrv_devstate_t *);
136 extern void cpudrv_redefine_topspeed(void *);
137 extern uint_t cpudrv_get_speeds(cpudrv_devstate_t *, int **);
138 extern void cpudrv_free_speeds(int *, uint_t);
139 
140 #ifdef  __cplusplus
141 }
142 #endif
143 
144 #endif /* _SYS_CPUDRV_MACH_H */
145