xref: /titanic_50/usr/src/uts/common/sys/ppmvar.h (revision 4b22b9337f359bfd063322244f5336cc7c6ffcfa)
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_PPMVAR_H
27 #define	_SYS_PPMVAR_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/epm.h>
32 #include <sys/sunldi.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 
39 typedef struct ppm_unit {
40 	dev_info_t	*dip;		/* node dev info */
41 	kmutex_t	lock;		/* global driver lock */
42 	uint_t		states;		/* driver states */
43 	timeout_id_t	led_tid;	/* timeout id for LED */
44 } ppm_unit_t;
45 
46 /*
47  * driver states
48  */
49 #define	PPM_STATE_SUSPENDED	0x1	/* driver is suspended */
50 
51 /*
52  * Check for domain operational
53  */
54 #define	PPM_DOMAIN_UP(domp)	(!(domp->dflags & PPMD_OFFLINE))
55 
56 /*
57  * LED constants
58  */
59 #define	PPM_LED_PULSE		(drv_usectohz(250000))	/* 0.25 seconds */
60 #define	PPM_LEDON_INTERVAL	(1 * PPM_LED_PULSE)
61 #define	PPM_LEDOFF_INTERVAL	(8 * PPM_LED_PULSE)
62 #define	PPM_LEDON		1	/* (s10) */
63 #define	PPM_LEDOFF		0	/* (s10) */
64 
65 /*
66  * internal form of "ppm.conf" data
67  */
68 struct ppm_db {
69 	struct ppm_db	*next;
70 	char		*name;		/* device name */
71 	int		plen;		/* strlen before wildcard(s10) */
72 	int		wccnt;		/* upto 2 '*' allowed */
73 	int		wcpos[2];	/* '*' location in pathname */
74 };
75 typedef struct ppm_db ppm_db_t;
76 
77 struct ppm_cdata {
78 	char *name;			/* property name */
79 	char **strings;			/* string array */
80 	uint_t cnt;			/* property count */
81 };
82 
83 /*
84  * ppm device info
85  */
86 struct ppm_dev {
87 	struct ppm_dev	*next;
88 	struct ppm_domain *domp;
89 	dev_info_t	*dip;
90 	char		*path;		/* OBP device pathname */
91 	int		cmpt;		/* component number */
92 	int		rplvl;		/* last requested power level */
93 	int		level;		/* actual current power level */
94 	int		lowest;		/* lowest power level for device */
95 	int		highest;	/* highest power level for device */
96 	uint_t		flags;
97 };
98 typedef struct ppm_dev ppm_dev_t;
99 
100 /*
101  * ppm_dev.flags field
102  */
103 #define	PPMDEV_PCI66_D2		0x1	/* device support D2 at pci 66mhz */
104 #define	PPMDEV_PCI_PROP_CLKPM	0x2	/* clock can be power managed */
105 #define	PPM_PM_POWEROP		0x10	/* power level change, initiated  */
106 					/* from PM is in progress.	  */
107 #define	PPM_PHC_WHILE_SET_POWER 0x20	/* power level of a device is	  */
108 					/* changed through		  */
109 					/* pm_power_has_changed path	  */
110 					/* while power level change,	  */
111 					/* initiated from PM is in	  */
112 					/* progress.			  */
113 
114 
115 /*
116  * per domain record of device _ever_ managed by ppm
117  */
118 struct ppm_owned {
119 	struct ppm_owned *next;
120 	char	*path;		/* device pathname */
121 	int	initializing;	/* initializing  flag */
122 };
123 typedef struct ppm_owned ppm_owned_t;
124 
125 
126 /*
127  * domain control data structure -
128  *   when you need to do an op for a domain, look up the op in the
129  *   cmd member of the struct, and then perform the method on the
130  *   path using iowr cmd with the args specified in val or val and
131  *   mask or the speed index.
132  */
133 struct ppm_dc {
134 	struct ppm_dc	*next;
135 	ldi_handle_t	lh;	/* layered (ldi) handle			*/
136 	char	*path;		/* control device prom pathname		*/
137 	uint_t	cmd;		/* search key: op to be performed	*/
138 	uint_t	method;		/* control method / union selector	*/
139 				/* one of PPMDC_KIO, PPMDC_I2CKIO,	*/
140 				/* PPMDC_CPUSPEEDKIO			*/
141 
142 	union {
143 		/* In each sub struct in union, the first three fields	*/
144 		/* must be .iord, .iowr and .val and in such order.	*/
145 		/* The .method field above selects a union sub struct	*/
146 		/* for a particular .cmd operation.			*/
147 		/* The association between .method and .cmd is platform	*/
148 		/* specific, therefore described in ppm.conf file.	*/
149 
150 		/* PPMDC_KIO: simple KIO 				*/
151 		struct m_kio {
152 			uint_t	iord;	/* IOCTL read cmd		*/
153 			uint_t	iowr;	/* IOCTL write cmd		*/
154 			uint_t	val;	/* ioctl arg			*/
155 			uint_t	delay;	/* total delay before this 	*/
156 					/* operation can be carried out	*/
157 			uint_t	post_delay; /* post delay, if any	*/
158 		} kio;
159 
160 		/* PPMDC_I2CKIO: KIO requires 'arg' as struct i2c_gpio	*/
161 		/*    (defined in i2c_client.h)				*/
162 		struct m_i2ckio {
163 			uint_t	iord;	/* IOCTL read cmd		*/
164 			uint_t	iowr;	/* IOCTL write cmd 		*/
165 			uint_t	val;	/* register content		*/
166 			uint_t	mask;	/* mask to select relevant bits	*/
167 					/* of register content		*/
168 			uint_t	delay;	/* total delay before this 	*/
169 					/* operation can be carried out	*/
170 			uint_t	post_delay; /* post delay, if any	*/
171 		} i2c;
172 
173 		/* PPMDC_CPUSPEEDKIO, PPMDC_VCORE: cpu estar related	*/
174 		/* simple KIO						*/
175 		struct m_cpu {
176 			uint_t	iord;	/* IOCTL read cmd 		*/
177 			uint_t	iowr;	/* IOCTL write cmd 		*/
178 			int	val;	/* new register value		*/
179 			uint_t	speeds;	/* number of speeds cpu supports */
180 			uint_t	delay;	/* microseconds post op delay	*/
181 		} cpu;
182 	} m_un;
183 };
184 typedef struct ppm_dc ppm_dc_t;
185 
186 /*
187  * ppm_dc.cmd field -
188  */
189 #define	PPMDC_CPU_NEXT		2
190 #define	PPMDC_PRE_CHNG		3
191 #define	PPMDC_CPU_GO		4
192 #define	PPMDC_POST_CHNG		5
193 #define	PPMDC_FET_ON		6
194 #define	PPMDC_FET_OFF		7
195 #define	PPMDC_LED_ON		8
196 #define	PPMDC_LED_OFF		9
197 #define	PPMDC_CLK_ON		10
198 #define	PPMDC_CLK_OFF		11
199 #define	PPMDC_PRE_PWR_OFF	12
200 #define	PPMDC_PRE_PWR_ON	13
201 #define	PPMDC_POST_PWR_ON	14
202 #define	PPMDC_PWR_OFF		15
203 #define	PPMDC_PWR_ON		16
204 #define	PPMDC_RESET_OFF		17
205 #define	PPMDC_RESET_ON		18
206 
207 /*
208  * ppm_dc.method field - select union element
209  */
210 #define	PPMDC_KIO  		1	/* simple ioctl with val as arg	*/
211 #define	PPMDC_CPUSPEEDKIO	2	/* ioctl with speed index arg	*/
212 #define	PPMDC_VCORE		3	/* CPU Vcore change operation */
213 #define	PPMDC_I2CKIO		4	/* ioctl with i2c_gpio_t as arg	*/
214 
215 /*
216  * devices that are powered by the same source
217  * are grouped by this struct as a "power domain"
218  */
219 struct ppm_domain {
220 	char		*name;		/* domain name */
221 	int		dflags;		/* domain flags */
222 	int		pwr_cnt;	/* number of powered up devices */
223 	ppm_db_t	*conflist;	/* all devices from ppm.conf file */
224 	ppm_dev_t	*devlist;	/* current attached devices */
225 	char		*propname;	/* domain property name */
226 	kmutex_t	lock;		/* domain lock */
227 	int		refcnt;		/* domain lock ref count */
228 	int		model;		/* pm model, CPU, FET or LED	*/
229 	int		status;		/* domain specific status */
230 	ppm_dc_t	*dc;		/* domain control method */
231 	ppm_owned_t	*owned;		/* list of ever owned devices */
232 	struct ppm_domain	*next;	/* a linked list */
233 	clock_t		last_off_time;	/* last time domain was off	*/
234 
235 };
236 typedef struct ppm_domain ppm_domain_t;
237 
238 
239 /*
240  * ppm_domain.model field -
241  */
242 #define	PPMD_CPU		1	/* cpu PM model */
243 #define	PPMD_FET		2	/* power FET pm model */
244 #define	PPMD_LED		3	/* LED pm model */
245 #define	PPMD_PCI		4	/* PCI pm model */
246 #define	PPMD_PCI_PROP		5	/* PCI_PROP pm model */
247 #define	PPMD_PCIE		6	/* PCI Express pm model */
248 
249 #define	PPMD_IS_PCI(model) \
250 	((model) == PPMD_PCI || (model) == PPMD_PCI_PROP)
251 
252 /*
253  * ppm_domain.status field -
254  */
255 #define	PPMD_OFF		0x0	/* FET/LED/PCI clock: off */
256 #define	PPMD_ON			0x1	/* FET/LED/PCI clock: on */
257 
258 /*
259  * ppm_domain.dflags field -
260  */
261 #define	PPMD_LOCK_ONE		0x1
262 #define	PPMD_LOCK_ALL		0x4
263 #define	PPMD_PCI33MHZ		0x1000	/* 33mhz PCI slot */
264 #define	PPMD_PCI66MHZ		0x2000	/* 66mhz PCI slot */
265 #define	PPMD_INITCHILD_CLKON	0x4000	/* clk turned on in init_child */
266 #define	PPMD_OFFLINE		0x10000	/* domain is not functional */
267 #define	PPMD_CPU_READY		0x20000	/* CPU domain can process power call */
268 
269 struct ppm_domit {
270 	char	*name;
271 	int	model;
272 	int	dflags;
273 	int	status;
274 };
275 extern struct ppm_domit ppm_domit_data[];
276 
277 /*
278  * XXppm driver-specific routines called from common code (s10)
279  */
280 struct ppm_funcs {
281 	void	(*dev_init)(ppm_dev_t *);
282 	void	(*dev_fini)(ppm_dev_t *);
283 	void	(*iocset)(uint8_t);
284 	uint8_t	(*iocget)(void);
285 };
286 
287 extern ppm_domain_t	*ppm_domain_p;
288 extern void		*ppm_statep;
289 extern int		ppm_inst;
290 extern ppm_domain_t *ppm_domains[];	/* (s10) */
291 extern struct ppm_funcs ppmf;		/* (s10) */
292 
293 extern void		ppm_dev_init(ppm_dev_t *);
294 extern void		ppm_dev_fini(ppm_dev_t *);
295 extern int		ppm_create_db(dev_info_t *);
296 extern int		ppm_claim_dev(dev_info_t *);
297 extern void		ppm_rem_dev(dev_info_t *);
298 extern ppm_dev_t	*ppm_get_dev(dev_info_t *, ppm_domain_t *);
299 extern void		ppm_init_cb(dev_info_t *);
300 extern int		ppm_init_lyr(ppm_dc_t *, dev_info_t *);
301 extern ppm_domain_t	*ppm_lookup_dev(dev_info_t *);
302 extern ppm_domain_t	*ppm_lookup_domain(char *);
303 extern ppm_dc_t		*ppm_lookup_dc(ppm_domain_t *, int);
304 extern ppm_dc_t		*ppm_lookup_hndl(int, ppm_dc_t *);
305 extern ppm_domain_t	*ppm_get_domain_by_dev(const char *);
306 extern boolean_t	ppm_none_else_holds_power(ppm_domain_t *);
307 extern ppm_owned_t	*ppm_add_owned(dev_info_t *, ppm_domain_t *);
308 extern void		ppm_lock_one(ppm_dev_t *, power_req_t *, int *);
309 extern void		ppm_lock_all(ppm_domain_t *, power_req_t *, int *);
310 extern boolean_t	ppm_manage_early_cpus(dev_info_t *, int, int *);
311 extern int		ppm_change_cpu_power(ppm_dev_t *, int);
312 extern int		ppm_revert_cpu_power(ppm_dev_t *, int);
313 extern ppm_dev_t	*ppm_add_dev(dev_info_t *, ppm_domain_t *);
314 
315 #define	PPM_GET_PRIVATE(dip) \
316     DEVI(dip)->devi_pm_ppm_private
317 #define	PPM_SET_PRIVATE(dip, datap) \
318     DEVI(dip)->devi_pm_ppm_private = datap
319 
320 #define	PPM_LOCK_DOMAIN(domp) {			\
321 	if (!MUTEX_HELD(&(domp)->lock))		\
322 		mutex_enter(&(domp)->lock);	\
323 	(domp)->refcnt++;			\
324 }
325 
326 #define	PPM_UNLOCK_DOMAIN(domp) {		\
327 	ASSERT(MUTEX_HELD(&(domp)->lock) &&	\
328 		(domp)->refcnt > 0);		\
329 	if (--(domp)->refcnt == 0)		\
330 		mutex_exit(&(domp)->lock);	\
331 }
332 
333 /*
334  * debug support
335  */
336 #ifdef DEBUG
337 #include <sys/promif.h>
338 
339 extern char	*ppm_get_ctlstr(int, uint_t);
340 extern void	ppm_print_dc(struct ppm_dc *);
341 
342 extern uint_t ppm_debug;
343 
344 #define	D_CREATEDB	0x00000001
345 #define	D_CLAIMDEV	0x00000002
346 #define	D_ADDDEV	0x00000004
347 #define	D_REMDEV	0x00000008
348 #define	D_LOWEST	0x00000010
349 #define	D_SETLVL	0x00000020
350 #define	D_GPIO		0x00000040
351 #define	D_CPU		0x00000080
352 #define	D_FET		0x00000100
353 #define	D_PCIUPA	0x00000200
354 #define	D_1394		0x00000400
355 #define	D_CTLOPS1	0x00000800
356 #define	D_CTLOPS2	0x00001000
357 #define	D_SOME		0x00002000
358 #define	D_LOCKS		0x00004000
359 #define	D_IOCTL		0x00008000
360 #define	D_ATTACH	0x00010000
361 #define	D_DETACH	0x00020000
362 #define	D_OPEN		0x00040000
363 #define	D_CLOSE		0x00080000
364 #define	D_INIT		0x00100000
365 #define	D_FINI		0x00200000
366 #define	D_ERROR		0x00400000
367 #define	D_SETPWR	0x00800000
368 #define	D_LED		0x01000000
369 #define	D_PCI		0x02000000
370 #define	D_PPMDC		0x04000000
371 #define	D_CPR		0x08000000
372 
373 #define	PPMD(level, arglist) {			\
374 	if (ppm_debug & (level)) {		\
375 		pm_log arglist;			\
376 	}					\
377 }
378 /* (s10) */
379 #define	DPRINTF		PPMD
380 
381 #else	/* DEBUG */
382 #define	PPMD(level, arglist)
383 #define	DPRINTF(flag, args)	/* (s10) */
384 #endif	/* DEBUG */
385 
386 #ifdef	__cplusplus
387 }
388 #endif
389 
390 #endif	/* _SYS_PPMVAR_H */
391