xref: /illumos-gate/usr/src/uts/common/sys/cpu_pm.h (revision 7d1e83948cb684521e72cab96020be241508f449)
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  * Utilization events delivered by the dispatcher.
69  */
70 typedef enum cpupm_util_event {
71 	CPUPM_DOM_BUSY_FROM_IDLE,
72 	CPUPM_DOM_IDLE_FROM_BUSY,
73 	CPUPM_DOM_REMAIN_BUSY
74 } cpupm_util_event_t;
75 
76 typedef uintptr_t	cpupm_handle_t;	/* Platform handle */
77 
78 /*
79  * CPU Power Domain State
80  */
81 typedef struct cpupm_state {
82 	uint32_t	cps_speed;
83 	cpupm_handle_t	cps_handle;
84 } cpupm_state_t;
85 
86 /*
87  * CPU Power Domain
88  */
89 typedef struct cpupm_domain {
90 	id_t			cpd_id;		/* Domain ID */
91 	cpupm_dtype_t		cpd_type;	/* Active or Idle */
92 	cpupm_state_t		*cpd_states;	/* Available Power States */
93 	cpupm_state_t		*cpd_state;	/* Current State */
94 	uint_t			cpd_nstates;	/* Number of States */
95 	cpupm_state_t		*cpd_named_states[CPUPM_STATE_NAMES];
96 	hrtime_t		cpd_last_raise;	/* Last raise request time */
97 	hrtime_t		cpd_last_lower;	/* last lower request time */
98 	int			cpd_tw;		/* transient work history */
99 	int			cpd_ti;		/* transient idle history */
100 	boolean_t		cpd_ti_governed; /* transient idle governor */
101 	boolean_t		cpd_tw_governed; /* transient work governor */
102 	struct cpupm_domain	*cpd_next;
103 } cpupm_domain_t;
104 
105 #define	CPUPM_NO_DOMAIN ((id_t)-1)
106 
107 /*
108  * CPU power manager domain management interfaces
109  */
110 cpupm_domain_t		*cpupm_domain_init(struct cpu *, cpupm_dtype_t);
111 id_t			cpupm_domain_id(struct cpu *, cpupm_dtype_t);
112 int			cpupm_change_state(struct cpu *, cpupm_domain_t *,
113     cpupm_state_t *);
114 extern void		cpupm_redefine_max_activepwr_state(struct cpu *, int);
115 
116 /*
117  * CPU power manager policy engine interfaces
118  */
119 int			cpupm_set_policy(cpupm_policy_t);
120 cpupm_policy_t		cpupm_get_policy(void);
121 void			cpupm_utilization_event(struct cpu *, hrtime_t,
122 			    cpupm_domain_t *, cpupm_util_event_t);
123 
124 /*
125  * CPU power platform driver interfaces
126  */
127 id_t	cpupm_plat_domain_id(struct cpu *, cpupm_dtype_t);
128 uint_t	cpupm_plat_state_enumerate(struct cpu *, cpupm_dtype_t,
129     cpupm_state_t *);
130 int	cpupm_plat_change_state(struct cpu *, cpupm_state_t *);
131 
132 
133 #endif	/* !_KERNEL && !_KMEMUSER */
134 
135 #ifdef	__cplusplus
136 }
137 #endif
138 
139 #endif /* _CPU_PM_H */
140