xref: /titanic_41/usr/src/uts/common/sys/cpu_pm.h (revision 5203bc321053fb87d7073c7640548fab73634793)
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	_CPU_PM_H
27 #define	_CPU_PM_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #if (defined(_KERNEL) || defined(_KMEMUSER))
34 #include <sys/cpuvar.h>
35 #include <sys/processor.h>
36 #include <sys/types.h>
37 #include <sys/kstat.h>
38 #include <sys/cmt.h>
39 
40 /*
41  * CPU Power Manager Policies
42  */
43 typedef enum cpupm_policy {
44 	CPUPM_POLICY_ELASTIC,
45 	CPUPM_POLICY_DISABLED,
46 	CPUPM_NUM_POLICIES
47 } cpupm_policy_t;
48 
49 /*
50  * Power Managable CPU Domain Types
51  */
52 typedef enum cpupm_dtype {
53 	CPUPM_DTYPE_ACTIVE,	/* Active Power Domain */
54 	CPUPM_DTYPE_IDLE	/* Idle Power Domain */
55 } cpupm_dtype_t;
56 
57 /*
58  * CPUPM state names for policy implementation.
59  * The last element is used to size the enumeration.
60  */
61 typedef enum cpupm_state_name {
62 	CPUPM_STATE_LOW_POWER,
63 	CPUPM_STATE_MAX_PERF,
64 	CPUPM_STATE_NAMES
65 } cpupm_state_name_t;
66 
67 /*
68  * Possible states for the domain's transience governor
69  */
70 typedef enum cpupm_gov_state_t {
71 	CPUPM_GOV_DISENGAGED,
72 	CPUPM_GOV_TRANS_IDLE,	/* Transient idleness, lowerings disabled */
73 	CPUPM_GOV_TRANS_WORK	/* Transient work, raises disabled */
74 } cpupm_gov_state_t;
75 
76 /*
77  * Utilization events delivered by the dispatcher.
78  */
79 typedef enum cpupm_util_event {
80 	CPUPM_DOM_BUSY_FROM_IDLE,
81 	CPUPM_DOM_IDLE_FROM_BUSY,
82 	CPUPM_DOM_REMAIN_BUSY
83 } cpupm_util_event_t;
84 
85 typedef uintptr_t	cpupm_handle_t;	/* Platform handle */
86 
87 /*
88  * CPU Power Domain State
89  */
90 typedef struct cpupm_state {
91 	uint32_t	cps_speed;
92 	cpupm_handle_t	cps_handle;
93 } cpupm_state_t;
94 
95 /*
96  * CPU Power Domain
97  */
98 typedef struct cpupm_domain {
99 	id_t			cpd_id;		/* Domain ID */
100 	cpupm_dtype_t		cpd_type;	/* Active or Idle */
101 	cpupm_state_t		*cpd_states;	/* Available Power States */
102 	cpupm_state_t		*cpd_state;	/* Current State */
103 	uint_t			cpd_nstates;	/* Number of States */
104 	cpupm_state_t		*cpd_named_states[CPUPM_STATE_NAMES];
105 	hrtime_t		cpd_last_raise;	/* Last raise request time */
106 	hrtime_t		cpd_last_lower;	/* last lower request time */
107 	int			cpd_ti;		/* transient idle history */
108 	int			cpd_tw;		/* transient work history */
109 	cpupm_gov_state_t	cpd_governor;   /* transience governor */
110 	struct cpupm_domain	*cpd_next;
111 } cpupm_domain_t;
112 
113 #define	CPUPM_NO_DOMAIN ((id_t)-1)
114 
115 /*
116  * CPU power manager domain management interfaces
117  */
118 cpupm_domain_t		*cpupm_domain_init(struct cpu *, cpupm_dtype_t);
119 id_t			cpupm_domain_id(struct cpu *, cpupm_dtype_t);
120 int			cpupm_change_state(struct cpu *, cpupm_domain_t *,
121     cpupm_state_t *);
122 extern void		cpupm_redefine_max_activepwr_state(struct cpu *, int);
123 
124 /*
125  * CPU power manager policy engine interfaces
126  */
127 int			cpupm_set_policy(cpupm_policy_t);
128 cpupm_policy_t		cpupm_get_policy(void);
129 void			cpupm_utilization_event(struct cpu *, hrtime_t,
130 			    cpupm_domain_t *, cpupm_util_event_t);
131 
132 /*
133  * CPU power platform driver interfaces
134  */
135 id_t	cpupm_plat_domain_id(struct cpu *, cpupm_dtype_t);
136 uint_t	cpupm_plat_state_enumerate(struct cpu *, cpupm_dtype_t,
137     cpupm_state_t *);
138 int	cpupm_plat_change_state(struct cpu *, cpupm_state_t *);
139 
140 
141 #endif	/* !_KERNEL && !_KMEMUSER */
142 
143 #ifdef	__cplusplus
144 }
145 #endif
146 
147 #endif /* _CPU_PM_H */
148