xref: /titanic_52/usr/src/uts/i86pc/sys/cpudrv_mach.h (revision 59d2da88ef75ee90d89de8d98edf0521bea61f8d)
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  * Redefine the topspeed.
68  */
69 #define	CPUDRV_REDEFINE_TOPSPEED(dip) cpudrv_redefine_topspeed(dip)
70 
71 /*
72  * Set callbacks so that PPM can callback into CPUDRV
73  */
74 #define	CPUDRV_SET_PPM_CALLBACKS() { \
75 	cpupm_get_topspeed_callb = cpudrv_get_topspeed; \
76 	cpupm_set_topspeed_callb = cpudrv_set_topspeed; \
77 }
78 
79 /*
80  * ACPI provides the supported speeds.
81  */
82 #define	CPUDRV_GET_SPEEDS(cpudsp, speeds, nspeeds) \
83 	nspeeds = cpudrv_get_speeds(cpudsp, &speeds);
84 #define	CPUDRV_FREE_SPEEDS(speeds, nspeeds) \
85 	cpudrv_free_speeds(speeds, nspeeds);
86 
87 /*
88  * ACPI provides the supported C-states.
89  */
90 #define	CPUDRV_GET_MAX_CSTATES(handle) \
91 	cpu_acpi_get_max_cstates(handle);
92 
93 /*
94  * Compute the idle cnt percentage for a given speed.
95  */
96 #define	CPUDRV_IDLE_CNT_PERCENT(hwm, speeds, i) \
97 	(100 - (((100 - hwm) * speeds[0]) / speeds[i]))
98 
99 /*
100  * Compute the user cnt percentage for a given speed.
101  */
102 #define	CPUDRV_USER_CNT_PERCENT(hwm, speeds, i) \
103 	((hwm * speeds[i]) / speeds[i - 1]);
104 
105 /*
106  * pm-components property defintions for this machine type.
107  *
108  * Fully constructed pm-components property should be an array of
109  * strings that look something like:
110  *
111  * pmc[0] = "NAME=CPU Speed"
112  * pmc[1] = "1=2800MHz"
113  * pmc[2] = "2=3200MHz"
114  *
115  * The amount of memory needed for each string is:
116  * 	digits for power level + '=' +  digits for freq + 'MHz' + '\0'
117  */
118 #define	CPUDRV_COMP_SIZE() \
119 	(CPUDRV_COMP_MAX_DIG + 1 + CPUDRV_COMP_MAX_DIG + 3 + 1);
120 #define	CPUDRV_COMP_SPEED(cpupm, cur_spd) cur_spd->speed;
121 #define	CPUDRV_COMP_SPRINT(pmc, cpupm, cur_spd, comp_spd) \
122 	(void) sprintf(pmc, "%d=%dMHz", cur_spd->pm_level, comp_spd);
123 
124 extern void cpudrv_set_topspeed(void *, int);
125 extern int cpudrv_get_topspeed(void *);
126 extern int cpudrv_get_topthrottle(cpu_t *);
127 extern void cpudrv_manage_throttling(void *);
128 extern void cpudrv_install_notify_handler(cpudrv_devstate_t *);
129 extern void cpudrv_redefine_topspeed(void *);
130 extern uint_t cpudrv_get_speeds(cpudrv_devstate_t *, int **);
131 extern void cpudrv_free_speeds(int *, uint_t);
132 
133 #ifdef  __cplusplus
134 }
135 #endif
136 
137 #endif /* _SYS_CPUDRV_MACH_H */
138