xref: /titanic_53/usr/src/uts/common/sys/epm.h (revision c42872d4489d6f0fbccfabe2a62f3c976ee1e5d6)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*c42872d4Smh27603  * Common Development and Distribution License (the "License").
6*c42872d4Smh27603  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*c42872d4Smh27603  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_EPM_H
277c478bd9Sstevel@tonic-gate #define	_SYS_EPM_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/pm.h>
327c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
337c478bd9Sstevel@tonic-gate #include <sys/devops.h>
347c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
357c478bd9Sstevel@tonic-gate #include <sys/taskq.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * epm.h:	Function prototypes and data structs for kernel pm functions.
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate void e_pm_props(dev_info_t *);
487c478bd9Sstevel@tonic-gate int e_new_pm_props(dev_info_t *);
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	PM_LEVEL_UPONLY (-2)	/* only raise power level */
517c478bd9Sstevel@tonic-gate #define	PM_LEVEL_DOWNONLY (-3)	/* only lower power level */
527c478bd9Sstevel@tonic-gate #define	PM_LEVEL_EXACT (-4)	/* wants exact power level */
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Values used by e_pm_props and friends, found in devi_pm_flags
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate #define	PMC_NEEDS_SR		0x00001	/* do suspend/resume despite no "reg" */
587c478bd9Sstevel@tonic-gate #define	PMC_NO_SR		0x00002	/* don't suspend/resume despite "reg" */
597c478bd9Sstevel@tonic-gate #define	PMC_PARENTAL_SR		0x00004	/* call up tree to suspend/resume */
607c478bd9Sstevel@tonic-gate #define	PMC_WANTS_NOTIFY	0x00008	/* notify if child pwr level changes */
617c478bd9Sstevel@tonic-gate #define	PMC_BC			0x00010	/* no pm-components, backwards compat */
627c478bd9Sstevel@tonic-gate #define	PMC_COMPONENTS_DONE	0x00020 /* parsed pm-components */
637c478bd9Sstevel@tonic-gate #define	PMC_COMPONENTS_FAILED	0x00040 /* failed parsing pm-components */
647c478bd9Sstevel@tonic-gate #define	PMC_SUSPENDED		0x00080 /* device has been suspended */
657c478bd9Sstevel@tonic-gate #define	PMC_DEF_THRESH		0x00100 /* thresholds are default */
667c478bd9Sstevel@tonic-gate #define	PMC_DEV_THRESH		0x00200 /* SET_THRESHOLD ioctl seen */
677c478bd9Sstevel@tonic-gate #define	PMC_COMP_THRESH		0x00400 /* relative threshold set */
687c478bd9Sstevel@tonic-gate #define	PMC_NEXDEF_THRESH	0x00800 /* relative threshold set for nexus */
697c478bd9Sstevel@tonic-gate #define	PMC_NOPMKID		0x01000 /* non-pm'd child of pm'd parent */
707c478bd9Sstevel@tonic-gate #define	PMC_NO_INVOL		0x02000 /* no pm without driver's consent */
717c478bd9Sstevel@tonic-gate #define	PMC_VOLPMD		0x04000 /* went down voluntarily */
727c478bd9Sstevel@tonic-gate #define	PMC_SKIP_BRINGUP	0x08000 /* Skipped a dependency bringup */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * A node which is the console frame buffer, and should not be powered down
767c478bd9Sstevel@tonic-gate  * automatically because the OBP driver doesn't know how to power it back up
777c478bd9Sstevel@tonic-gate  * before using it  (can remove this when prom calls back into kernel to do
787c478bd9Sstevel@tonic-gate  * io to console).
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate #define	PMC_CONSOLE_FB		0x10000	/* console framebuffer */
817c478bd9Sstevel@tonic-gate #define	PMC_NOINVOL_DONE	0x20000 /* processed by pm_noinvol_specd() */
827c478bd9Sstevel@tonic-gate #define	PMC_DRIVER_REMOVED	0x40000 /* driver is removed	*/
83*c42872d4Smh27603 #define	PMC_CPU_DEVICE		0x80000 /* device is a power manageable CPU */
84*c42872d4Smh27603 #define	PMC_CPU_THRESH		0x100000 /* cpu threshold set */
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #define	PMC_THRESH_ALL	(PMC_DEF_THRESH | PMC_DEV_THRESH | \
87*c42872d4Smh27603     PMC_COMP_THRESH | PMC_NEXDEF_THRESH | PMC_CPU_THRESH)
887c478bd9Sstevel@tonic-gate #define	PMC_THRESH_NONE	~(PMC_THRESH_ALL)
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /* Flags for the component */
917c478bd9Sstevel@tonic-gate #define	PM_POWER_OP		0x00001	/* set power in process */
927c478bd9Sstevel@tonic-gate #define	PM_PHC_WHILE_SET_POWER	0x00002	/* phc and set power deadlock */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * One of these is attached to each devinfo that is autopm'd.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate typedef struct pm_scan {
987c478bd9Sstevel@tonic-gate 	int		ps_idle_down;	/* PMID_XXX flags */
997c478bd9Sstevel@tonic-gate 	int		ps_scan_flags;	/* scan flags, defined below */
1007c478bd9Sstevel@tonic-gate 	timeout_id_t	ps_scan_id;	/* per dip scan timeout id */
1017c478bd9Sstevel@tonic-gate } pm_scan_t;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /*
1047c478bd9Sstevel@tonic-gate  * ps_scan_flags may take the following values, plus possibly
1057c478bd9Sstevel@tonic-gate  * more defined.
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate #define	PM_SCANNING		0x100	/* scanning: pm_scan_dev is active */
1087c478bd9Sstevel@tonic-gate #define	PM_SCAN_AGAIN		0x200
1097c478bd9Sstevel@tonic-gate #define	PM_SCAN_STOP		0x400
1107c478bd9Sstevel@tonic-gate #define	PM_SCAN_DISPATCHED	0x800
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate #define	PM_MIN_SCAN	((clock_t)15)	/* Minimum scan interval in seconds */
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate  * Power management component definitions, used for tracking idleness of
1167c478bd9Sstevel@tonic-gate  * devices.  An array of these hangs off the devi_pm_components member of the
1177c478bd9Sstevel@tonic-gate  * dev_info struct (if initialized by driver and/or auto-pm)
1187c478bd9Sstevel@tonic-gate  * The array of these structs is followed in the same kmem_zalloc'd chunk by
1197c478bd9Sstevel@tonic-gate  * the names pointed to by the structs.
1207c478bd9Sstevel@tonic-gate  */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate  * This (sub-)struct contains all the info extracted from the pm-components
1247c478bd9Sstevel@tonic-gate  * property for each component (name of component, names and values of power
1257c478bd9Sstevel@tonic-gate  * levels supported).  It is in a separate structure to allow it to be handled
1267c478bd9Sstevel@tonic-gate  * as a struct assignment.
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate typedef struct pm_comp {
1297c478bd9Sstevel@tonic-gate 	char 	*pmc_name;		/* name of component */
1307c478bd9Sstevel@tonic-gate 	int	pmc_numlevels;		/* number of power levels supported */
1317c478bd9Sstevel@tonic-gate 	int	*pmc_lvals;		/* numerical values of levels */
1327c478bd9Sstevel@tonic-gate 	int	*pmc_thresh;		/* thresholds in secs, last INT_MAX */
1337c478bd9Sstevel@tonic-gate 	char	**pmc_lnames;		/* human readable names of levels */
1347c478bd9Sstevel@tonic-gate 	/*
1357c478bd9Sstevel@tonic-gate 	 * This part is just bookkeeping for the storage space involved above
1367c478bd9Sstevel@tonic-gate 	 * used for copying and freeing the struct members.  This because C
1377c478bd9Sstevel@tonic-gate 	 * is really an assembler at heart.
1387c478bd9Sstevel@tonic-gate 	 */
1397c478bd9Sstevel@tonic-gate 	size_t	pmc_name_sz;		/* size of name string		*/
1407c478bd9Sstevel@tonic-gate 	char	*pmc_lname_buf;		/* buffer holding *pmc_lnames	*/
1417c478bd9Sstevel@tonic-gate 	size_t	pmc_lnames_sz;		/* total size of pmc_lname_buf	*/
1427c478bd9Sstevel@tonic-gate } pm_comp_t;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate  * Here we have the rest of what we need to know about a component.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate typedef struct pm_component {
1487c478bd9Sstevel@tonic-gate 	uint_t pmc_flags;		/* flags this component */
1497c478bd9Sstevel@tonic-gate 	uint_t pmc_busycount;		/* for nesting busy calls */
1507c478bd9Sstevel@tonic-gate 	time_t pmc_timestamp;		/* timestamp */
1517c478bd9Sstevel@tonic-gate 	uint_t pmc_norm_pwr;		/* normal power index (or value) */
1527c478bd9Sstevel@tonic-gate 	int pmc_cur_pwr;		/* current power index (or value)  */
1537c478bd9Sstevel@tonic-gate 	int pmc_phc_pwr;		/* prev. value of curpwr (deadlock) */
1547c478bd9Sstevel@tonic-gate 	pm_comp_t pmc_comp;		/* component description */
1557c478bd9Sstevel@tonic-gate } pm_component_t;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate  * All members of this struct are protected by PM_LOCK_DIP(dip).
1597c478bd9Sstevel@tonic-gate  *
1607c478bd9Sstevel@tonic-gate  * kidsupcnt counts (the number of components of new-style children at non-zero
1617c478bd9Sstevel@tonic-gate  * level (unknown counts as non-zero)) + (the number of old-style children with
1627c478bd9Sstevel@tonic-gate  * component 0 at non-zero level) for parents that have not asked for
1637c478bd9Sstevel@tonic-gate  * notifcation.  When kidsupcnt is 0 for a nexus node, then pm scans it,
1647c478bd9Sstevel@tonic-gate  * otherwise it leaves it alone.
1657c478bd9Sstevel@tonic-gate  * Parents that ask for notification always get get scanned,
1667c478bd9Sstevel@tonic-gate  * so we keep their kidsupcnt at zero.
1677c478bd9Sstevel@tonic-gate  */
1687c478bd9Sstevel@tonic-gate typedef struct pm_info {
1697c478bd9Sstevel@tonic-gate 	uint_t		pmi_dev_pm_state; /* PM state of a device */
1707c478bd9Sstevel@tonic-gate 	int		pmi_clone;	/* owner for direct pm'd devs */
1717c478bd9Sstevel@tonic-gate 	int		pmi_levels[2];	/* storage space for 2 levels */
1727c478bd9Sstevel@tonic-gate 	int		*pmi_lp;	/* storage space for >2 levels */
1737c478bd9Sstevel@tonic-gate 	kcondvar_t	pmi_cv;		/* condvar for direct PM access */
1747c478bd9Sstevel@tonic-gate } pm_info_t;
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate  * Work request structure for the dependency processing thread.
1787c478bd9Sstevel@tonic-gate  */
1797c478bd9Sstevel@tonic-gate typedef struct pm_dep_wk {
1807c478bd9Sstevel@tonic-gate 	int		pdw_type;		/* Type of request */
1817c478bd9Sstevel@tonic-gate 	int		pdw_wait;		/* caller waits for result */
1827c478bd9Sstevel@tonic-gate 	int		pdw_done;		/* set when req is done */
1837c478bd9Sstevel@tonic-gate 	int		pdw_ret;		/* return value to caller */
1847c478bd9Sstevel@tonic-gate 	int		pdw_pwr;		/* pwr level of keeper */
1857c478bd9Sstevel@tonic-gate 	kcondvar_t	pdw_cv;			/* cv to wake up caller */
1867c478bd9Sstevel@tonic-gate 	struct		pm_dep_wk *pdw_next;	/* next element */
1877c478bd9Sstevel@tonic-gate 	char		*pdw_keeper;
1887c478bd9Sstevel@tonic-gate 	char		*pdw_kept;
1897c478bd9Sstevel@tonic-gate } pm_dep_wk_t;
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  * Types of work, depends on when it gets called:
1937c478bd9Sstevel@tonic-gate  */
1947c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_POWER_ON		1	/* power on */
1957c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_POWER_OFF		2	/* power off */
1967c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_DETACH		3	/* detach */
1977c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_REMOVE_DEP		4	/* dependency removed */
1987c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_BRINGUP_SELF		5	/* released from direct PM */
1997c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_RECORD_KEEPER		6	/* PM_ADD_DEPENDENT */
2007c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_RECORD_KEEPER_PROP	7	/* PM_ADD_DEPENDENT_PROP */
2017c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_KEPT			8	/* dep. work as a kept */
2027c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_KEEPER		9	/* dep. work as a keeper */
2037c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_ATTACH		10	/* when dip is attached */
2047c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_CHECK_KEPT		11	/* check if this is a kept */
2057c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_CPR_SUSPEND		12	/* Suspend dep. during CPR */
2067c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_CPR_RESUME		13	/* Resume dep. after CPR */
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * Wait for dependency work to finish or not.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate #define	PM_DEP_WAIT	1
2127c478bd9Sstevel@tonic-gate #define	PM_DEP_NOWAIT	0
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate typedef enum pm_canblock
2157c478bd9Sstevel@tonic-gate {
2167c478bd9Sstevel@tonic-gate 	PM_CANBLOCK_BLOCK,	/* wait for controlling process action */
2177c478bd9Sstevel@tonic-gate 	PM_CANBLOCK_FAIL,	/* don't wait, fail request */
2187c478bd9Sstevel@tonic-gate 	PM_CANBLOCK_BYPASS	/* don't wait, ignore controlling process */
2197c478bd9Sstevel@tonic-gate } pm_canblock_t;
2207c478bd9Sstevel@tonic-gate 
221*c42872d4Smh27603 typedef enum pm_cpupm
222*c42872d4Smh27603 {
223*c42872d4Smh27603 	PM_CPUPM_NOTSET,	/* no specific treatment of CPU devices */
224*c42872d4Smh27603 	PM_CPUPM_ENABLE,	/* power manage CPU devices */
225*c42872d4Smh27603 	PM_CPUPM_DISABLE	/* do not power manage CPU devices */
226*c42872d4Smh27603 } pm_cpupm_t;
227*c42872d4Smh27603 
2287c478bd9Sstevel@tonic-gate /*
2297c478bd9Sstevel@tonic-gate  * The power request struct uses for the DDI_CTLOPS_POWER busctl.
2307c478bd9Sstevel@tonic-gate  *
2317c478bd9Sstevel@tonic-gate  * Note: When changing this enum it is necessary to maintain binary
2327c478bd9Sstevel@tonic-gate  * compatibility with older versions.  To insure that, add new values only
2337c478bd9Sstevel@tonic-gate  * at the end and refrain from deleting any existing values.
2347c478bd9Sstevel@tonic-gate  */
2357c478bd9Sstevel@tonic-gate typedef enum {
2367c478bd9Sstevel@tonic-gate 	PMR_SET_POWER = 1,		/* called ddi_power (obsolete)	*/
2377c478bd9Sstevel@tonic-gate 	PMR_SUSPEND,			/* parental suspend		*/
2387c478bd9Sstevel@tonic-gate 	PMR_RESUME,			/* parental resume		*/
2397c478bd9Sstevel@tonic-gate 	PMR_PRE_SET_POWER,		/* parent's "pre" notification	*/
2407c478bd9Sstevel@tonic-gate 	PMR_POST_SET_POWER,		/* parent's "post" notification	*/
2417c478bd9Sstevel@tonic-gate 	PMR_PPM_SET_POWER,		/* platform pm set power	*/
2427c478bd9Sstevel@tonic-gate 	PMR_PPM_ATTACH,			/* ppm attach notify - unused	*/
2437c478bd9Sstevel@tonic-gate 	PMR_PPM_DETACH,			/* ppm detach notify - unused   */
2447c478bd9Sstevel@tonic-gate 	PMR_PPM_POWER_CHANGE_NOTIFY,	/* ppm level change notify	*/
2457c478bd9Sstevel@tonic-gate 	PMR_REPORT_PMCAP,		/* report pm capability		*/
2467c478bd9Sstevel@tonic-gate 	PMR_CHANGED_POWER,		/* parent's power_has_changed notif. */
2477c478bd9Sstevel@tonic-gate 	PMR_PPM_PRE_PROBE,		/* ppm pre probe notify		*/
2487c478bd9Sstevel@tonic-gate 	PMR_PPM_POST_PROBE,		/* ppm post probe notify	*/
2497c478bd9Sstevel@tonic-gate 	PMR_PPM_PRE_ATTACH,		/* ppm pre attach notify	*/
2507c478bd9Sstevel@tonic-gate 	PMR_PPM_POST_ATTACH,		/* ppm post pm attach notify	*/
2517c478bd9Sstevel@tonic-gate 	PMR_PPM_PRE_DETACH,		/* ppm pre pm detach notify	*/
2527c478bd9Sstevel@tonic-gate 	PMR_PPM_POST_DETACH,		/* ppm post pm detach notify	*/
2537c478bd9Sstevel@tonic-gate 	PMR_PPM_UNMANAGE,		/* device being unmanaged	*/
2547c478bd9Sstevel@tonic-gate 	PMR_PPM_PRE_RESUME,		/* ppm resume notify		*/
2557c478bd9Sstevel@tonic-gate 	PMR_PPM_ALL_LOWEST,		/* ppm all lowest power notify	*/
2567c478bd9Sstevel@tonic-gate 	PMR_PPM_LOCK_POWER,		/* ppm lock power		*/
2577c478bd9Sstevel@tonic-gate 	PMR_PPM_UNLOCK_POWER,		/* ppm unlock power		*/
2587c478bd9Sstevel@tonic-gate 	PMR_PPM_TRY_LOCK_POWER,		/* ppm try lock power		*/
2597c478bd9Sstevel@tonic-gate 	PMR_PPM_INIT_CHILD,		/* ppm init child notify	*/
2607c478bd9Sstevel@tonic-gate 	PMR_PPM_UNINIT_CHILD,		/* ppm uninit child notify	*/
2617c478bd9Sstevel@tonic-gate 	PMR_PPM_POWER_LOCK_OWNER	/* ppm power lock owner's address */
2627c478bd9Sstevel@tonic-gate } pm_request_type;
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate /*
2657c478bd9Sstevel@tonic-gate  * When changing the elements of the union below it is necessary to
2667c478bd9Sstevel@tonic-gate  * maintain binary compatibility with older versions.  Refrain from
2677c478bd9Sstevel@tonic-gate  * deleting existing elements of the union or modifying their contents.
2687c478bd9Sstevel@tonic-gate  * Avoid increasing the total size of this structure if new elements
2697c478bd9Sstevel@tonic-gate  * must be added.
2707c478bd9Sstevel@tonic-gate  */
2717c478bd9Sstevel@tonic-gate typedef struct power_req {
2727c478bd9Sstevel@tonic-gate 	pm_request_type request_type;
2737c478bd9Sstevel@tonic-gate 	union req {
2747c478bd9Sstevel@tonic-gate 		/*
2757c478bd9Sstevel@tonic-gate 		 * PMR_SET_POWER (obsolete)
2767c478bd9Sstevel@tonic-gate 		 */
2777c478bd9Sstevel@tonic-gate 		struct set_power_req {
2787c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
2797c478bd9Sstevel@tonic-gate 			int		cmpt;
2807c478bd9Sstevel@tonic-gate 			int		level;
2817c478bd9Sstevel@tonic-gate 		} set_power_req;
2827c478bd9Sstevel@tonic-gate 		/*
2837c478bd9Sstevel@tonic-gate 		 * PMR_SUSPEND
2847c478bd9Sstevel@tonic-gate 		 */
2857c478bd9Sstevel@tonic-gate 		struct suspend_req {
2867c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
2877c478bd9Sstevel@tonic-gate 			ddi_detach_cmd_t cmd;
2887c478bd9Sstevel@tonic-gate 		} suspend_req;
2897c478bd9Sstevel@tonic-gate 		/*
2907c478bd9Sstevel@tonic-gate 		 * PMR_PPM_PRE_RESUME or PMR_RESUME
2917c478bd9Sstevel@tonic-gate 		 */
2927c478bd9Sstevel@tonic-gate 		struct resume_req {
2937c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
2947c478bd9Sstevel@tonic-gate 			ddi_attach_cmd_t cmd;
2957c478bd9Sstevel@tonic-gate 		} resume_req;
2967c478bd9Sstevel@tonic-gate 		/*
2977c478bd9Sstevel@tonic-gate 		 * PMR_PRE_SET_POWER
2987c478bd9Sstevel@tonic-gate 		 */
2997c478bd9Sstevel@tonic-gate 		struct pre_set_power_req {
3007c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3017c478bd9Sstevel@tonic-gate 			int		cmpt;
3027c478bd9Sstevel@tonic-gate 			int		old_level;
3037c478bd9Sstevel@tonic-gate 			int		new_level;
3047c478bd9Sstevel@tonic-gate 		} pre_set_power_req;
3057c478bd9Sstevel@tonic-gate 		/*
3067c478bd9Sstevel@tonic-gate 		 * PMR_POST_SET_POWER
3077c478bd9Sstevel@tonic-gate 		 */
3087c478bd9Sstevel@tonic-gate 		struct post_set_power_req {
3097c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3107c478bd9Sstevel@tonic-gate 			int		cmpt;
3117c478bd9Sstevel@tonic-gate 			int		old_level;
3127c478bd9Sstevel@tonic-gate 			int		new_level;
3137c478bd9Sstevel@tonic-gate 			int		result;		/* driver's return */
3147c478bd9Sstevel@tonic-gate 		} post_set_power_req;
3157c478bd9Sstevel@tonic-gate 		/*
3167c478bd9Sstevel@tonic-gate 		 * PMR_PPM_SET_POWER
3177c478bd9Sstevel@tonic-gate 		 */
3187c478bd9Sstevel@tonic-gate 		struct ppm_set_power_req {
3197c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3207c478bd9Sstevel@tonic-gate 			int		cmpt;
3217c478bd9Sstevel@tonic-gate 			int		old_level;
3227c478bd9Sstevel@tonic-gate 			int		new_level;
3237c478bd9Sstevel@tonic-gate 			pm_canblock_t	canblock;
3247c478bd9Sstevel@tonic-gate 			void		*cookie;
3257c478bd9Sstevel@tonic-gate 		} ppm_set_power_req;
3267c478bd9Sstevel@tonic-gate 		/*
3277c478bd9Sstevel@tonic-gate 		 * PMR_PPM_POWER_CHANGE_NOTIFY
3287c478bd9Sstevel@tonic-gate 		 */
3297c478bd9Sstevel@tonic-gate 		struct ppm_notify_level_req {
3307c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3317c478bd9Sstevel@tonic-gate 			int		cmpt;
3327c478bd9Sstevel@tonic-gate 			int		old_level;
3337c478bd9Sstevel@tonic-gate 			int		new_level;
3347c478bd9Sstevel@tonic-gate 		} ppm_notify_level_req;
3357c478bd9Sstevel@tonic-gate 		/*
3367c478bd9Sstevel@tonic-gate 		 * PMR_REPORT_PMCAP
3377c478bd9Sstevel@tonic-gate 		 */
3387c478bd9Sstevel@tonic-gate 		struct report_pmcap_req {
3397c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3407c478bd9Sstevel@tonic-gate 			int		cap;
3417c478bd9Sstevel@tonic-gate 			void 		*arg;
3427c478bd9Sstevel@tonic-gate 		} report_pmcap_req;
3437c478bd9Sstevel@tonic-gate 		/*
3447c478bd9Sstevel@tonic-gate 		 * PMR_CHANGED_POWER
3457c478bd9Sstevel@tonic-gate 		 */
3467c478bd9Sstevel@tonic-gate 		struct changed_power_req {
3477c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3487c478bd9Sstevel@tonic-gate 			int		cmpt;
3497c478bd9Sstevel@tonic-gate 			int		old_level;
3507c478bd9Sstevel@tonic-gate 			int		new_level;
3517c478bd9Sstevel@tonic-gate 			int		result;
3527c478bd9Sstevel@tonic-gate 		} changed_power_req;
3537c478bd9Sstevel@tonic-gate 		/*
3547c478bd9Sstevel@tonic-gate 		 * PMR_PPM_PRE_PROBE, PMR_PPM_POST_PROBE, PMR_PPM_PRE_ATTACH,
3557c478bd9Sstevel@tonic-gate 		 * PMR_PPM_POST_ATTACH, PMR_PPM_PRE_DETACH, PMR_PPM_POST_DETACH
3567c478bd9Sstevel@tonic-gate 		 * PMR_PPM_INIT_CHILD, PMR_PPM_UNINIT_CHILD, or PMR_PPM_UNMANAGE
3577c478bd9Sstevel@tonic-gate 		 */
3587c478bd9Sstevel@tonic-gate 		struct ppm_config_req {
3597c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3607c478bd9Sstevel@tonic-gate 			int		result;		/* post only */
3617c478bd9Sstevel@tonic-gate 		} ppm_config_req;
3627c478bd9Sstevel@tonic-gate 		/*
3637c478bd9Sstevel@tonic-gate 		 * PMR_PPM_ALL_LOWEST
3647c478bd9Sstevel@tonic-gate 		 */
3657c478bd9Sstevel@tonic-gate 		struct ppm_all_lowest_req {
3667c478bd9Sstevel@tonic-gate 			int		mode;
3677c478bd9Sstevel@tonic-gate 		} ppm_all_lowest_req;
3687c478bd9Sstevel@tonic-gate 		/*
3697c478bd9Sstevel@tonic-gate 		 * PMR_PPM_LOCK_POWER, PMR_PPM_TRY_LOCK_POWER
3707c478bd9Sstevel@tonic-gate 		 */
3717c478bd9Sstevel@tonic-gate 		struct ppm_lock_power_req {
3727c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3737c478bd9Sstevel@tonic-gate 			int		*circp;
3747c478bd9Sstevel@tonic-gate 		} ppm_lock_power_req;
3757c478bd9Sstevel@tonic-gate 		/*
3767c478bd9Sstevel@tonic-gate 		 * PMR_PPM_UNLOCK_POWER
3777c478bd9Sstevel@tonic-gate 		 */
3787c478bd9Sstevel@tonic-gate 		struct ppm_unlock_power_req {
3797c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3807c478bd9Sstevel@tonic-gate 			int		circ;
3817c478bd9Sstevel@tonic-gate 		} ppm_unlock_power_req;
3827c478bd9Sstevel@tonic-gate 		/*
3837c478bd9Sstevel@tonic-gate 		 * PMR_PPM_POWER_LOCK_OWNER
3847c478bd9Sstevel@tonic-gate 		 */
3857c478bd9Sstevel@tonic-gate 		struct ppm_power_lock_owner_req {
3867c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3877c478bd9Sstevel@tonic-gate 			kthread_t	*owner;
3887c478bd9Sstevel@tonic-gate 		} ppm_power_lock_owner_req;
3897c478bd9Sstevel@tonic-gate 	} req;
3907c478bd9Sstevel@tonic-gate } power_req_t;
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate /*
3937c478bd9Sstevel@tonic-gate  * Structure used by the following bus_power operations:
3947c478bd9Sstevel@tonic-gate  *
3957c478bd9Sstevel@tonic-gate  *	BUS_POWER_PRE_NOTIFICATION
3967c478bd9Sstevel@tonic-gate  *	BUS_POWER_POST_NOTIFICATION
3977c478bd9Sstevel@tonic-gate  *	BUS_POWER_CHILD_PWRCHG
3987c478bd9Sstevel@tonic-gate  */
3997c478bd9Sstevel@tonic-gate typedef struct pm_bp_child_pwrchg {
4007c478bd9Sstevel@tonic-gate 	dev_info_t	*bpc_dip;	/* dip of the target device */
4017c478bd9Sstevel@tonic-gate 	char		*bpc_path;	/* path to the target device */
4027c478bd9Sstevel@tonic-gate 	int		bpc_comp;	/* component changing power */
4037c478bd9Sstevel@tonic-gate 	int		bpc_olevel;	/* old power level */
4047c478bd9Sstevel@tonic-gate 	int		bpc_nlevel;	/* new power level */
4057c478bd9Sstevel@tonic-gate 	void		*bpc_private;	/* PM framework private */
4067c478bd9Sstevel@tonic-gate } pm_bp_child_pwrchg_t;
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate /*
4097c478bd9Sstevel@tonic-gate  * Structure used by the BUS_POWER_NEXUS_PWRUP operation
4107c478bd9Sstevel@tonic-gate  */
4117c478bd9Sstevel@tonic-gate typedef struct pm_bp_nexus_pwrup {
4127c478bd9Sstevel@tonic-gate 	dev_info_t	*bpn_dip;	/* dip of the nexus device */
4137c478bd9Sstevel@tonic-gate 	int		bpn_comp;	/* component powering up */
4147c478bd9Sstevel@tonic-gate 	int		bpn_level;	/* new power level */
4157c478bd9Sstevel@tonic-gate 	void		*bpn_private;	/* PM framework private */
4167c478bd9Sstevel@tonic-gate } pm_bp_nexus_pwrup_t;
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate /*
4197c478bd9Sstevel@tonic-gate  * Structure used by the BUS_POWER_HAS_CHANGED operation
4207c478bd9Sstevel@tonic-gate  */
4217c478bd9Sstevel@tonic-gate typedef struct pm_bp_has_changed {
4227c478bd9Sstevel@tonic-gate 	dev_info_t	*bphc_dip;	/* dip of the target device */
4237c478bd9Sstevel@tonic-gate 	char		*bphc_path;	/* path to the target device */
4247c478bd9Sstevel@tonic-gate 	int		bphc_comp;	/* component changing power */
4257c478bd9Sstevel@tonic-gate 	int		bphc_olevel;	/* old power level */
4267c478bd9Sstevel@tonic-gate 	int		bphc_nlevel;	/* new power level */
4277c478bd9Sstevel@tonic-gate 	void		*bphc_private;	/* PM framework private */
4287c478bd9Sstevel@tonic-gate } pm_bp_has_changed_t;
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate /*
4317c478bd9Sstevel@tonic-gate  * Commands indicating which activity is requiring an
4327c478bd9Sstevel@tonic-gate  * update to the noinvol counters.
4337c478bd9Sstevel@tonic-gate  */
4347c478bd9Sstevel@tonic-gate #define	PM_BP_NOINVOL_ATTACH	1
4357c478bd9Sstevel@tonic-gate #define	PM_BP_NOINVOL_DETACH	2
4367c478bd9Sstevel@tonic-gate #define	PM_BP_NOINVOL_REMDRV	3
4377c478bd9Sstevel@tonic-gate #define	PM_BP_NOINVOL_CFB	4
4387c478bd9Sstevel@tonic-gate #define	PM_BP_NOINVOL_POWER	5
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate /*
4417c478bd9Sstevel@tonic-gate  * Structure used by the BUS_POWER_NOINVOL operation.
4427c478bd9Sstevel@tonic-gate  */
4437c478bd9Sstevel@tonic-gate typedef struct pm_bp_noinvol {
4447c478bd9Sstevel@tonic-gate 	dev_info_t	*bpni_dip;	/* dip of the target device */
4457c478bd9Sstevel@tonic-gate 	char		*bpni_path;	/* path to the target device */
4467c478bd9Sstevel@tonic-gate 	int		bpni_cmd;	/* how to update the counters */
4477c478bd9Sstevel@tonic-gate 	int		bpni_volpmd;	/* volpmd of target device */
4487c478bd9Sstevel@tonic-gate 	int		bpni_wasvolpmd;	/* whether to update volpmd */
4497c478bd9Sstevel@tonic-gate 	void		*bpni_private;	/* PM framework private */
4507c478bd9Sstevel@tonic-gate } pm_bp_noinvol_t;
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate /*
4537c478bd9Sstevel@tonic-gate  * This struct is used by the code that makes a PMR_PPM_SET_POWER request
4547c478bd9Sstevel@tonic-gate  * to ppm. Devices that changed power other than the primary device (which
4557c478bd9Sstevel@tonic-gate  * was requested) are passed back to the pm framework through this
4567c478bd9Sstevel@tonic-gate  * structure.
4577c478bd9Sstevel@tonic-gate  */
4587c478bd9Sstevel@tonic-gate typedef struct pm_ppm_devlist {
4597c478bd9Sstevel@tonic-gate 	dev_info_t	*ppd_who;
4607c478bd9Sstevel@tonic-gate 	int		ppd_cmpt;
4617c478bd9Sstevel@tonic-gate 	int		ppd_old_level;
4627c478bd9Sstevel@tonic-gate 	int		ppd_new_level;
4637c478bd9Sstevel@tonic-gate 	struct pm_ppm_devlist	*ppd_next;
4647c478bd9Sstevel@tonic-gate } pm_ppm_devlist_t;
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate /*
4677c478bd9Sstevel@tonic-gate  * This struct is used by the code that brings up parents and notifies
4687c478bd9Sstevel@tonic-gate  * ppm drivers across probe/attach/detach (pm_pre/post_probe/attach/detach())
4697c478bd9Sstevel@tonic-gate  */
4707c478bd9Sstevel@tonic-gate typedef struct pm_ppm_cookie {
4717c478bd9Sstevel@tonic-gate 	dev_info_t		*ppc_dip;	/* dip of target node */
4727c478bd9Sstevel@tonic-gate 	dev_info_t		*ppc_pdip;	/* parent's dip */
4737c478bd9Sstevel@tonic-gate 	dev_info_t		*ppc_ppm;	/* interested ppm driver */
4747c478bd9Sstevel@tonic-gate 	int			ppc_cmd;	/* attach/detach cmd */
4757c478bd9Sstevel@tonic-gate } pm_ppm_cookie_t;
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate /*
4787c478bd9Sstevel@tonic-gate  * This struct records one dependency (a device keeps another or others up)
4797c478bd9Sstevel@tonic-gate  * pdr_size includes size of strings.
4807c478bd9Sstevel@tonic-gate  */
4817c478bd9Sstevel@tonic-gate typedef struct pm_dep_rec {
4827c478bd9Sstevel@tonic-gate 	char *pdr_keeper;		/* physpath of device keeping up */
4837c478bd9Sstevel@tonic-gate 	char *pdr_kept;			/* physpath or property name */
4847c478bd9Sstevel@tonic-gate 	char **pdr_kept_paths;		/* array of kept devices' paths */
4857c478bd9Sstevel@tonic-gate 	struct pm_dep_rec *pdr_next;	/* next dependency device */
4867c478bd9Sstevel@tonic-gate 	size_t pdr_size;		/* size to kmem_free */
4877c478bd9Sstevel@tonic-gate 	major_t pdr_major;		/* major of kept driver (not props) */
4887c478bd9Sstevel@tonic-gate 	int pdr_isprop;			/* true if kept is property name */
4897c478bd9Sstevel@tonic-gate 	int pdr_kept_count;		/* how many kept altogether */
4907c478bd9Sstevel@tonic-gate 	int pdr_satisfied;		/* true if in force (not properties) */
4917c478bd9Sstevel@tonic-gate } pm_pdr_t;
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate /*
4957c478bd9Sstevel@tonic-gate  * This struct records threshold information about a single component
4967c478bd9Sstevel@tonic-gate  */
4977c478bd9Sstevel@tonic-gate typedef struct pm_thresh_entry {
4987c478bd9Sstevel@tonic-gate 	int pte_numthresh;
4997c478bd9Sstevel@tonic-gate 	int *pte_thresh;
5007c478bd9Sstevel@tonic-gate } pm_pte_t;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate /*
5037c478bd9Sstevel@tonic-gate  * Note that this header and its array of entry structs with their arrays
5047c478bd9Sstevel@tonic-gate  * of thresholds and string storage for physpath are all kmem_alloced in one
5057c478bd9Sstevel@tonic-gate  * chunk for easy freeing ptr_size is the size of that chunk
5067c478bd9Sstevel@tonic-gate  */
5077c478bd9Sstevel@tonic-gate typedef struct pm_thresh_rec {
5087c478bd9Sstevel@tonic-gate 	char			*ptr_physpath;	/* identifies node */
5097c478bd9Sstevel@tonic-gate 	struct pm_thresh_rec	*ptr_next;
5107c478bd9Sstevel@tonic-gate 	int			ptr_numcomps;	/* number of components */
5117c478bd9Sstevel@tonic-gate 	size_t			ptr_size;	/* total size for kmem_free */
5127c478bd9Sstevel@tonic-gate 	pm_pte_t 		*ptr_entries;
5137c478bd9Sstevel@tonic-gate } pm_thresh_rec_t;
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate /*
5167c478bd9Sstevel@tonic-gate  * pmi_dev_pm_state state bits:
5177c478bd9Sstevel@tonic-gate  */
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate /*
5207c478bd9Sstevel@tonic-gate  * a direct-pm device, not scanned, but controlled by a process
5217c478bd9Sstevel@tonic-gate  */
5227c478bd9Sstevel@tonic-gate #define	PM_DIRECT	0x1
5237c478bd9Sstevel@tonic-gate /*
5247c478bd9Sstevel@tonic-gate  * autopm is suspended while waiting to see if detach succeeds
5257c478bd9Sstevel@tonic-gate  */
5267c478bd9Sstevel@tonic-gate #define	PM_DETACHING	0x2
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate /*
5297c478bd9Sstevel@tonic-gate  * An all_to_normal operation for an autopm device that is detaching, is
5307c478bd9Sstevel@tonic-gate  * deferred in case the detach fails.
5317c478bd9Sstevel@tonic-gate  */
5327c478bd9Sstevel@tonic-gate #define	PM_ALLNORM_DEFERRED	0x4
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate #define	PM_GET_PM_INFO(dip) (DEVI(dip)->devi_pm_info)
5357c478bd9Sstevel@tonic-gate #define	PM_GET_PM_SCAN(dip) (DEVI(dip)->devi_pm_scan)
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate #define	PM_NUMCMPTS(dip) (DEVI(dip)->devi_pm_num_components)
5387c478bd9Sstevel@tonic-gate #define	PM_CP(dip, comp) (&DEVI(dip)->devi_pm_components[comp])
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate /*
5417c478bd9Sstevel@tonic-gate  * Returns true if the device specified by dip is directly power managed
5427c478bd9Sstevel@tonic-gate  */
5437c478bd9Sstevel@tonic-gate #define	PM_ISDIRECT(dip) \
5447c478bd9Sstevel@tonic-gate 	(((pm_info_t *)PM_GET_PM_INFO(dip))->pmi_dev_pm_state & PM_DIRECT)
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate /*
5477c478bd9Sstevel@tonic-gate  * Returns true if the device specified by dip is an old node for which we
5487c478bd9Sstevel@tonic-gate  * provide backwards compatible behavior (e.g. no pm-components property).
5497c478bd9Sstevel@tonic-gate  */
5507c478bd9Sstevel@tonic-gate #define	PM_ISBC(dip) (DEVI(dip)->devi_pm_flags & PMC_BC)
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate /*
5537c478bd9Sstevel@tonic-gate  * Returns true if we have skipped a dependency bringup on this dip.
5547c478bd9Sstevel@tonic-gate  */
5557c478bd9Sstevel@tonic-gate #define	PM_SKBU(dip) (DEVI(dip)->devi_pm_flags & PMC_SKIP_BRINGUP)
5567c478bd9Sstevel@tonic-gate 
557*c42872d4Smh27603 /*
558*c42872d4Smh27603  * Returns true if device specified by dip is a power manageable CPU.
559*c42872d4Smh27603  */
560*c42872d4Smh27603 #define	PM_ISCPU(dip) (DEVI(dip)->devi_pm_flags & PMC_CPU_DEVICE)
561*c42872d4Smh27603 
562*c42872d4Smh27603 /*
563*c42872d4Smh27603  * Returns true if cpupm is enabled.
564*c42872d4Smh27603  */
565*c42872d4Smh27603 #define	PM_CPUPM_ENABLED (cpupm == PM_CPUPM_ENABLE)
566*c42872d4Smh27603 
567*c42872d4Smh27603 /*
568*c42872d4Smh27603  * Returns true if is disabled.
569*c42872d4Smh27603  */
570*c42872d4Smh27603 #define	PM_CPUPM_DISABLED (cpupm == PM_CPUPM_DISABLE)
571*c42872d4Smh27603 
572*c42872d4Smh27603 /*
573*c42872d4Smh27603  * If (autopm is enabled and
574*c42872d4Smh27603  *      (CPUs are not disabled, or it isn't a cpu)) OR
575*c42872d4Smh27603  *    (CPUs are enabled and it is one)
576*c42872d4Smh27603  */
577*c42872d4Smh27603 #define	PM_SCANABLE(dip) ((autopm_enabled && \
578*c42872d4Smh27603 (!PM_CPUPM_DISABLED || !PM_ISCPU(dip))) || (PM_CPUPM_ENABLED && PM_ISCPU(dip)))
579*c42872d4Smh27603 
5807c478bd9Sstevel@tonic-gate #define	PM_NOT_ALL_LOWEST	0x0	/* not all components are at lowest */
5817c478bd9Sstevel@tonic-gate #define	PM_ALL_LOWEST		0x1	/* all components are at lowest lvl */
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate #define	PM_ADDR(dip)	(ddi_get_name_addr(dip) ? ddi_get_name_addr(dip) : "")
5847c478bd9Sstevel@tonic-gate #define	PM_NAME(dip)	(ddi_binding_name(dip))
5857c478bd9Sstevel@tonic-gate #define	PM_NODE(dip)	(ddi_node_name(dip))
5867c478bd9Sstevel@tonic-gate #define	PM_INST(dip)	(ddi_get_instance(dip))
5877c478bd9Sstevel@tonic-gate #define	PM_DEVICE(dip)	PM_NAME(dip), PM_ADDR(dip), PM_NODE(dip), PM_INST(dip)
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate #ifdef	DEBUG
5907c478bd9Sstevel@tonic-gate /*
5917c478bd9Sstevel@tonic-gate  * Flags passed to PMD to enable debug printfs.  If the same flag is set in
5927c478bd9Sstevel@tonic-gate  * pm_debug below then the message is printed.  The most generally useful
5937c478bd9Sstevel@tonic-gate  * ones are the first 3 or 4.
5947c478bd9Sstevel@tonic-gate  */
5957c478bd9Sstevel@tonic-gate #define	PMD_ERROR	0x0000001
5967c478bd9Sstevel@tonic-gate #define	PMD_FAIL	0x0000002
5977c478bd9Sstevel@tonic-gate #define	PMD_IOCTL	0x0000004
5987c478bd9Sstevel@tonic-gate #define	PMD_SCAN	0x0000008
5997c478bd9Sstevel@tonic-gate #define	PMD_RESCAN	0x0000010
6007c478bd9Sstevel@tonic-gate #define	PMD_REMINFO	0x0000020
6017c478bd9Sstevel@tonic-gate #define	PMD_NAMETODIP	0x0000040
6027c478bd9Sstevel@tonic-gate #define	PMD_CLOSE	0x0000080
6037c478bd9Sstevel@tonic-gate #define	PMD_DIN		0x0000100	/* Dev Is Needed */
6047c478bd9Sstevel@tonic-gate #define	PMD_PMC		0x0000200	/* for testing with sun4m pmc driver */
6057c478bd9Sstevel@tonic-gate #define	PMD_PPM		0x0000400
6067c478bd9Sstevel@tonic-gate #define	PMD_DEP		0x0000800	/* dependency processing */
6077c478bd9Sstevel@tonic-gate #define	PMD_IDLEDOWN	0x0001000
6087c478bd9Sstevel@tonic-gate #define	PMD_SET		0x0002000
6097c478bd9Sstevel@tonic-gate #define	PMD_BRING	0x0004000
6107c478bd9Sstevel@tonic-gate #define	PMD_ALLNORM	0x0008000
6117c478bd9Sstevel@tonic-gate #define	PMD_REMDEV	0x0010000
6127c478bd9Sstevel@tonic-gate #define	PMD_LEVEL	0x0020000
6137c478bd9Sstevel@tonic-gate #define	PMD_THRESH	0x0040000
6147c478bd9Sstevel@tonic-gate #define	PMD_DPM		0x0080000	/* Direct Power Management */
6157c478bd9Sstevel@tonic-gate #define	PMD_NORM	0x0100000
6167c478bd9Sstevel@tonic-gate #define	PMD_STATS	0x0200000
6177c478bd9Sstevel@tonic-gate #define	PMD_DEREG	0x0400000
6187c478bd9Sstevel@tonic-gate #define	PMD_KEEPS	0x0800000
6197c478bd9Sstevel@tonic-gate #define	PMD_KIDSUP	0x1000000
6207c478bd9Sstevel@tonic-gate #define	PMD_TCHECK	0x2000000
6217c478bd9Sstevel@tonic-gate #define	PMD_NOINVOL	0x4000000
6227c478bd9Sstevel@tonic-gate #define	PMD_CFB		0x8000000	/* console fb pm */
6237c478bd9Sstevel@tonic-gate #define	PMD_DHR		0x10000000	/* driver hold/rele changes */
6247c478bd9Sstevel@tonic-gate #define	PMD_PIL		0x20000000	/* print out PIL when calling power */
6257c478bd9Sstevel@tonic-gate #define	PMD_PHC		0x40000000	/* pm_power_has_changed messages */
6267c478bd9Sstevel@tonic-gate #define	PMD_LOCK	0x80000000
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate extern uint_t	pm_debug;
6297c478bd9Sstevel@tonic-gate extern uint_t	pm_divertdebug;
6307c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/
6317c478bd9Sstevel@tonic-gate extern void	pm_log(const char *fmt, ...) __KPRINTFLIKE(1);
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate #define	PMD(level, arglist) { 			\
6347c478bd9Sstevel@tonic-gate 	if (pm_debug & (level)) {		\
6357c478bd9Sstevel@tonic-gate 		pm_log arglist;			\
6367c478bd9Sstevel@tonic-gate 	}					\
6377c478bd9Sstevel@tonic-gate }
6387c478bd9Sstevel@tonic-gate 
6397c478bd9Sstevel@tonic-gate #else
6407c478bd9Sstevel@tonic-gate #define	PMD(level, arglist)
6417c478bd9Sstevel@tonic-gate #endif
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate extern void	pm_detaching(dev_info_t *);
6447c478bd9Sstevel@tonic-gate extern void	pm_detach_failed(dev_info_t *);
6457c478bd9Sstevel@tonic-gate extern int	pm_power(dev_info_t *, int, int);
6467c478bd9Sstevel@tonic-gate extern int	pm_unmanage(dev_info_t *);
6477c478bd9Sstevel@tonic-gate extern void	pm_rem_info(dev_info_t *);
6487c478bd9Sstevel@tonic-gate extern int	pm_get_norm_pwrs(dev_info_t *, int **, size_t *);
6497c478bd9Sstevel@tonic-gate extern dev_info_t *pm_name_to_dip(char *, int);
6507c478bd9Sstevel@tonic-gate extern int	pm_power_up(dev_info_t *, int, int, int, pm_info_t *);
6517c478bd9Sstevel@tonic-gate extern int	pm_default_idle_threshold;
6527c478bd9Sstevel@tonic-gate extern void	pm_set_device_threshold(dev_info_t *, int, int);
6537c478bd9Sstevel@tonic-gate extern int	pm_valid_power(dev_info_t *, int, int);
6547c478bd9Sstevel@tonic-gate extern void	pm_lock_power(dev_info_t *, int *);
6557c478bd9Sstevel@tonic-gate extern void	pm_unlock_power(dev_info_t *, int);
6567c478bd9Sstevel@tonic-gate extern int	pm_try_locking_power(dev_info_t *, int *);
6577c478bd9Sstevel@tonic-gate extern void	pm_lock_power_single(dev_info_t *, int *);
6587c478bd9Sstevel@tonic-gate extern void	pm_unlock_power_single(dev_info_t *, int);
6597c478bd9Sstevel@tonic-gate extern int	pm_try_locking_power_single(dev_info_t *, int *);
6607c478bd9Sstevel@tonic-gate extern int	pm_isbc(dev_info_t *dip);
6617c478bd9Sstevel@tonic-gate extern int	pm_isdirect(dev_info_t *dip);
6627c478bd9Sstevel@tonic-gate extern int	pm_ctlops(dev_info_t *d, dev_info_t *r, ddi_ctl_enum_t o,
6637c478bd9Sstevel@tonic-gate 			void *a, void *v);
6647c478bd9Sstevel@tonic-gate extern int	pm_noinvol_detached(char *);
6657c478bd9Sstevel@tonic-gate extern int	pm_init_child(dev_info_t *);
6667c478bd9Sstevel@tonic-gate extern int	pm_uninit_child(dev_info_t *);
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate extern int	pm_all_to_normal(dev_info_t *, pm_canblock_t);
6697c478bd9Sstevel@tonic-gate extern int	pm_set_power(dev_info_t *, int, int, int, pm_canblock_t, int,
6707c478bd9Sstevel@tonic-gate 			int *);
6717c478bd9Sstevel@tonic-gate extern void	pm_scan_init(dev_info_t *dip);
6727c478bd9Sstevel@tonic-gate extern void	pm_scan_fini(dev_info_t *dip);
6737c478bd9Sstevel@tonic-gate extern void	pm_scan_stop(dev_info_t *dip);
6747c478bd9Sstevel@tonic-gate extern int	pm_scan_stop_walk(dev_info_t *dip, void *);
6757c478bd9Sstevel@tonic-gate extern void	pm_scan(void *);
6767c478bd9Sstevel@tonic-gate extern time_t	pm_scan_dev(dev_info_t *dip);
6777c478bd9Sstevel@tonic-gate extern void	pm_rescan(void *);
6787c478bd9Sstevel@tonic-gate extern int	pm_rescan_walk(dev_info_t *, void *);
6797c478bd9Sstevel@tonic-gate extern void	pm_forget_power_level(dev_info_t *);
6807c478bd9Sstevel@tonic-gate extern int	pm_pre_config(dev_info_t *, char *);
6817c478bd9Sstevel@tonic-gate extern int	pm_pre_unconfig(dev_info_t *, int, int *, char *);
6827c478bd9Sstevel@tonic-gate extern void	pm_post_config(dev_info_t *, char *);
6837c478bd9Sstevel@tonic-gate extern void	pm_post_unconfig(dev_info_t *, int, char *);
6847c478bd9Sstevel@tonic-gate extern void	pm_pre_probe(dev_info_t *, pm_ppm_cookie_t *);
6857c478bd9Sstevel@tonic-gate extern void	pm_post_probe(pm_ppm_cookie_t *, int, int);
6867c478bd9Sstevel@tonic-gate extern void	pm_post_attach(pm_ppm_cookie_t *, int);
6877c478bd9Sstevel@tonic-gate extern void	pm_pre_attach(dev_info_t *, pm_ppm_cookie_t *,
6887c478bd9Sstevel@tonic-gate 			ddi_attach_cmd_t);
6897c478bd9Sstevel@tonic-gate extern void	pm_pre_detach(dev_info_t *, ddi_detach_cmd_t,
6907c478bd9Sstevel@tonic-gate 			pm_ppm_cookie_t *);
6917c478bd9Sstevel@tonic-gate extern void	pm_post_detach(pm_ppm_cookie_t *, int);
6927c478bd9Sstevel@tonic-gate extern int	pm_powerup(dev_info_t *);
6937c478bd9Sstevel@tonic-gate extern int	pm_all_at_normal(dev_info_t *);
6947c478bd9Sstevel@tonic-gate extern int	pm_busop_bus_power(dev_info_t *, void *,
6957c478bd9Sstevel@tonic-gate 		    pm_bus_power_op_t, void *, void *);
6967c478bd9Sstevel@tonic-gate extern void	pm_hold_power(dev_info_t *);
6977c478bd9Sstevel@tonic-gate extern void	pm_rele_power(dev_info_t *);
6987c478bd9Sstevel@tonic-gate extern void	pm_driver_removed(major_t);
6997c478bd9Sstevel@tonic-gate extern void	pm_borrow_lock(kthread_t *);
7007c478bd9Sstevel@tonic-gate extern void	pm_return_lock(void);
7017c478bd9Sstevel@tonic-gate extern int	pm_reattach_noinvol(void);
7027c478bd9Sstevel@tonic-gate extern void	pm_reattach_noinvol_fini();
7037c478bd9Sstevel@tonic-gate extern void	pm_restore_direct_levels(void);
7047c478bd9Sstevel@tonic-gate extern void	pm_save_direct_levels(void);
7057c478bd9Sstevel@tonic-gate extern void	pm_cfb_setup(const char *);
7067c478bd9Sstevel@tonic-gate extern void	pm_proceed(dev_info_t *, int, int, int);
7077c478bd9Sstevel@tonic-gate extern void	pm_get_timestamps(dev_info_t *, time_t *);
7087c478bd9Sstevel@tonic-gate extern void	pm_deregister_watcher(int, dev_info_t *);
7097c478bd9Sstevel@tonic-gate extern void	pm_dispatch_to_dep_thread(int, char *, char *, int, int *, int);
7107c478bd9Sstevel@tonic-gate extern int	e_pm_valid_comp(dev_info_t *, int, pm_component_t **);
7117c478bd9Sstevel@tonic-gate extern int	e_pm_valid_info(dev_info_t *, pm_info_t **);
7127c478bd9Sstevel@tonic-gate extern int	e_pm_valid_power(dev_info_t *, int, int);
7137c478bd9Sstevel@tonic-gate extern void	pm_init_locks(void);
7147c478bd9Sstevel@tonic-gate extern int	pm_register_ppm(int (*)(dev_info_t *), dev_info_t *);
7157c478bd9Sstevel@tonic-gate extern int	pm_is_cfb(dev_info_t *);
7167c478bd9Sstevel@tonic-gate #ifdef	DEBUG
7177c478bd9Sstevel@tonic-gate extern int	pm_cfb_is_up(void);
7187c478bd9Sstevel@tonic-gate #endif
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate #ifdef DEBUG
7217c478bd9Sstevel@tonic-gate #define	PM_LOCK_DIP(dip)	{ PMD(PMD_LOCK, ("dip lock %s@%s(%s#%d) " \
7227c478bd9Sstevel@tonic-gate 				    "%s %d\n", PM_DEVICE(dip),		  \
7237c478bd9Sstevel@tonic-gate 				    __FILE__, __LINE__)) 		  \
7247c478bd9Sstevel@tonic-gate 				    mutex_enter(&DEVI(dip)->devi_pm_lock); }
7257c478bd9Sstevel@tonic-gate #define	PM_UNLOCK_DIP(dip)	{ PMD(PMD_LOCK, ("dip unlock %s@%s(%s#%d) " \
7267c478bd9Sstevel@tonic-gate 				    "%s %d\n", PM_DEVICE(dip),		    \
7277c478bd9Sstevel@tonic-gate 				    __FILE__, __LINE__))		    \
7287c478bd9Sstevel@tonic-gate 				    mutex_exit(&DEVI(dip)->devi_pm_lock); }
7297c478bd9Sstevel@tonic-gate #else
7307c478bd9Sstevel@tonic-gate #define	PM_LOCK_DIP(dip)	mutex_enter(&DEVI(dip)->devi_pm_lock)
7317c478bd9Sstevel@tonic-gate #define	PM_UNLOCK_DIP(dip)	mutex_exit(&DEVI(dip)->devi_pm_lock)
7327c478bd9Sstevel@tonic-gate #endif
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate /*
7357c478bd9Sstevel@tonic-gate  * These are the same DEBUG or not
7367c478bd9Sstevel@tonic-gate  */
7377c478bd9Sstevel@tonic-gate #define	PM_LOCK_BUSY(dip)	mutex_enter(&DEVI(dip)->devi_pm_busy_lock)
7387c478bd9Sstevel@tonic-gate #define	PM_UNLOCK_BUSY(dip)	mutex_exit(&DEVI(dip)->devi_pm_busy_lock)
7397c478bd9Sstevel@tonic-gate #define	PM_LOCK_POWER(dip, circp)	pm_lock_power(dip, circp)
7407c478bd9Sstevel@tonic-gate #define	PM_UNLOCK_POWER(dip, circ)	pm_unlock_power(dip, circ)
7417c478bd9Sstevel@tonic-gate #define	PM_TRY_LOCK_POWER(dip, circp)	pm_try_locking_power(dip, circp)
7427c478bd9Sstevel@tonic-gate #define	PM_IAM_LOCKING_DIP(dip)	(mutex_owned(&DEVI(dip)->devi_pm_lock))
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate #define	PM_DEFAULT_SYS_IDLENESS	1800	/* 30 minutes */
7457c478bd9Sstevel@tonic-gate 
7467c478bd9Sstevel@tonic-gate /*
7477c478bd9Sstevel@tonic-gate  * Codes put into the pr_retval field of pm_rsvp_t that tell pm_block()
7487c478bd9Sstevel@tonic-gate  * how to proceed
7497c478bd9Sstevel@tonic-gate  */
7507c478bd9Sstevel@tonic-gate #define	PMP_SUCCEED	0x1	/* return success, the process did it */
7517c478bd9Sstevel@tonic-gate #define	PMP_FAIL	0x2	/* return fail, process did something else */
7527c478bd9Sstevel@tonic-gate #define	PMP_RELEASE	0x3	/* let it go, the process has lost interest */
7537c478bd9Sstevel@tonic-gate 				/* also arg to pm_proceed to signal this */
7547c478bd9Sstevel@tonic-gate /*
7557c478bd9Sstevel@tonic-gate  * Values of "style" for e_pm_manage and pm_premanage
7567c478bd9Sstevel@tonic-gate  */
7577c478bd9Sstevel@tonic-gate #define	PM_STYLE_NEW		0
7587c478bd9Sstevel@tonic-gate #define	PM_STYLE_UNKNOWN	1
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate /*
7617c478bd9Sstevel@tonic-gate  * Arg passed to pm_proceed that results in PMP_SUCCEED or PMP_FAIL being set
7627c478bd9Sstevel@tonic-gate  * in pr_retval depending on what is pending
7637c478bd9Sstevel@tonic-gate  */
7647c478bd9Sstevel@tonic-gate #define	PMP_SETPOWER	0x4
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate #define	PM_MAX_CLONE	256
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate typedef struct pm_rsvp {
7697c478bd9Sstevel@tonic-gate 	dev_info_t	*pr_dip;
7707c478bd9Sstevel@tonic-gate 	int		pr_comp;
7717c478bd9Sstevel@tonic-gate 	int		pr_newlevel;
7727c478bd9Sstevel@tonic-gate 	int		pr_oldlevel;
7737c478bd9Sstevel@tonic-gate 	kcondvar_t	pr_cv;		/* a place to sleep */
7747c478bd9Sstevel@tonic-gate 	int		pr_retval;	/* what to do when you wake up */
7757c478bd9Sstevel@tonic-gate 	struct pm_rsvp	*pr_next;
7767c478bd9Sstevel@tonic-gate 	struct pm_rsvp	*pr_prev;
7777c478bd9Sstevel@tonic-gate } pm_rsvp_t;
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate typedef struct psce {	/* pm_state_change_entries */
7807c478bd9Sstevel@tonic-gate 	struct pm_state_change		*psce_first;
7817c478bd9Sstevel@tonic-gate 	struct pm_state_change		*psce_in;
7827c478bd9Sstevel@tonic-gate 	struct pm_state_change		*psce_out;
7837c478bd9Sstevel@tonic-gate 	struct pm_state_change		*psce_last;
7847c478bd9Sstevel@tonic-gate 	int				psce_overruns;
7857c478bd9Sstevel@tonic-gate 	int				psce_references;
7867c478bd9Sstevel@tonic-gate 	kmutex_t			psce_lock;
7877c478bd9Sstevel@tonic-gate } psce_t;
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate typedef struct pscc {			/* pm_state_change_control */
7907c478bd9Sstevel@tonic-gate 	int		pscc_clone;
7917c478bd9Sstevel@tonic-gate 	dev_info_t	*pscc_dip;
7927c478bd9Sstevel@tonic-gate 	psce_t		*pscc_entries;
7937c478bd9Sstevel@tonic-gate 	struct pscc	*pscc_next;
7947c478bd9Sstevel@tonic-gate 	struct pscc	*pscc_prev;
7957c478bd9Sstevel@tonic-gate } pscc_t;
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate #define	PSCCOUNT 128	/* number of state change entries kept per process */
7987c478bd9Sstevel@tonic-gate 
7997c478bd9Sstevel@tonic-gate /*
8007c478bd9Sstevel@tonic-gate  * Struct used to track the existance of devices exporting the
8017c478bd9Sstevel@tonic-gate  * no-involuntary-power-cycles property, and remember things from their
8027c478bd9Sstevel@tonic-gate  * devinfo node for later attach.
8037c478bd9Sstevel@tonic-gate  */
8047c478bd9Sstevel@tonic-gate typedef struct pm_noinvol {
8057c478bd9Sstevel@tonic-gate 	struct pm_noinvol	*ni_next;
8067c478bd9Sstevel@tonic-gate 	char			*ni_path;
8077c478bd9Sstevel@tonic-gate 	major_t			ni_major;	/* for attaching at cpr time */
8087c478bd9Sstevel@tonic-gate 	uint_t			ni_flags;	/* selected PMC_* values */
8097c478bd9Sstevel@tonic-gate 	uint_t			ni_noinvolpm;	/* saved noinvolpm count */
8107c478bd9Sstevel@tonic-gate 	uint_t			ni_volpmd;	/* saved volpmd count */
8117c478bd9Sstevel@tonic-gate 	uint_t			ni_wasvolpmd;	/* was vol pm'd at detach */
8127c478bd9Sstevel@tonic-gate 	size_t			ni_size;
8137c478bd9Sstevel@tonic-gate 	int			ni_persistent;	/* still around */
8147c478bd9Sstevel@tonic-gate } pm_noinvol_t;
8157c478bd9Sstevel@tonic-gate 
8167c478bd9Sstevel@tonic-gate #define	PMID_IOCTIMER		0x1		/* pm_ioctl sets during timer */
8177c478bd9Sstevel@tonic-gate #define	PMID_CFBTIMER		0x2		/* cfb sets during timer */
8187c478bd9Sstevel@tonic-gate #define	PMID_IOCSCAN		0x4		/* pm_ioctl sets during scan */
8197c478bd9Sstevel@tonic-gate #define	PMID_CFBSCAN		0x8		/* cfb sets during scan */
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate #define	PMID_IOC		(PMID_IOCTIMER | PMID_IOCSCAN)
8227c478bd9Sstevel@tonic-gate #define	PMID_CFB		(PMID_CFBTIMER | PMID_CFBSCAN)
8237c478bd9Sstevel@tonic-gate #define	PMID_TIMERS		(PMID_IOCTIMER | PMID_CFBTIMER)
8247c478bd9Sstevel@tonic-gate #define	PMID_SCANS		(PMID_IOCSCAN | PMID_CFBSCAN)
8257c478bd9Sstevel@tonic-gate #define	PMID_SCANS_SHIFT	2
8267c478bd9Sstevel@tonic-gate #define	PMID_SET_SCANS(pmid)	(pmid) |= (((pmid) & PMID_TIMERS) <<	\
8277c478bd9Sstevel@tonic-gate 				    PMID_SCANS_SHIFT);
8287c478bd9Sstevel@tonic-gate #define	PMID_IS_IOC(pmid)	((pmid) & PMID_IOC)
8297c478bd9Sstevel@tonic-gate #define	PMID_IS_CFB(pmid, dip)	(((pmid) & PMID_CFB) &&			\
8307c478bd9Sstevel@tonic-gate 				    (DEVI(dip)->devi_pm_flags &		\
8317c478bd9Sstevel@tonic-gate 				    (PMC_DEF_THRESH | PMC_NEXDEF_THRESH)))
8327c478bd9Sstevel@tonic-gate #define	PM_IS_PID(dip)	(PMID_IS_IOC(PM_GET_PM_SCAN(dip)->ps_idle_down) || \
8337c478bd9Sstevel@tonic-gate 	PMID_IS_CFB(PM_GET_PM_SCAN(dip)->ps_idle_down, dip))
8347c478bd9Sstevel@tonic-gate #define	PM_IS_CFB(dip)		(DEVI(dip)->devi_pm_flags & PMC_CONSOLE_FB)
8357c478bd9Sstevel@tonic-gate #define	PM_KUC(dip)		(DEVI(dip)->devi_pm_kidsupcnt)
8367c478bd9Sstevel@tonic-gate #define	PM_CURPOWER(dip, comp)	cur_power(PM_CP(dip, comp))
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate #define	PM_WANTS_NOTIFICATION(dip)					\
8397c478bd9Sstevel@tonic-gate 	(DEVI(dip)->devi_pm_flags & PMC_WANTS_NOTIFY)
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate #define	PM_HAS_BUS_POWER(dip)						\
8427c478bd9Sstevel@tonic-gate 	((DEVI(dip)->devi_ops->devo_bus_ops != NULL) &&			\
8437c478bd9Sstevel@tonic-gate 	(DEVI(dip)->devi_ops->devo_bus_ops->busops_rev >= BUSO_REV_7) &&\
8447c478bd9Sstevel@tonic-gate 	(DEVI(dip)->devi_ops->devo_bus_ops->bus_power != NULL))
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate #define	PM_BUS_POWER_FUNC(dip)						\
8477c478bd9Sstevel@tonic-gate 	DEVI(dip)->devi_ops->devo_bus_ops->bus_power
8487c478bd9Sstevel@tonic-gate 
8497c478bd9Sstevel@tonic-gate /*
8507c478bd9Sstevel@tonic-gate  * Structure used to pass down sunpm's private data variables
8517c478bd9Sstevel@tonic-gate  * through the bus_power bus_op calls
8527c478bd9Sstevel@tonic-gate  */
8537c478bd9Sstevel@tonic-gate typedef struct pm_sp_misc {
8547c478bd9Sstevel@tonic-gate 	pm_canblock_t   pspm_canblock;
8557c478bd9Sstevel@tonic-gate 	int pspm_scan;
8567c478bd9Sstevel@tonic-gate 	int *pspm_errnop;
8577c478bd9Sstevel@tonic-gate 	int pspm_direction;
8587c478bd9Sstevel@tonic-gate } pm_sp_misc_t;
8597c478bd9Sstevel@tonic-gate 
8607c478bd9Sstevel@tonic-gate /*
8617c478bd9Sstevel@tonic-gate  * This structure is used in validating that the power level
8627c478bd9Sstevel@tonic-gate  * of the descendents are off, while a device is powered off.
8637c478bd9Sstevel@tonic-gate  */
8647c478bd9Sstevel@tonic-gate typedef struct pm_desc_pwrchk {
8657c478bd9Sstevel@tonic-gate 	dev_info_t *pdpc_dip;
8667c478bd9Sstevel@tonic-gate 	int pdpc_par_involved;
8677c478bd9Sstevel@tonic-gate } pm_desc_pwrchk_t;
8687c478bd9Sstevel@tonic-gate 
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate /*
8717c478bd9Sstevel@tonic-gate  * These defines are used by pm_trans_check() to calculate time.
8727c478bd9Sstevel@tonic-gate  * Mostly copied from "tzfile.h".
8737c478bd9Sstevel@tonic-gate  */
8747c478bd9Sstevel@tonic-gate #define	EPOCH_YEAR		1970
8757c478bd9Sstevel@tonic-gate #define	SECSPERMIN		60
8767c478bd9Sstevel@tonic-gate #define	MINSPERHOUR		60
8777c478bd9Sstevel@tonic-gate #define	HOURSPERDAY		24
8787c478bd9Sstevel@tonic-gate #define	DAYSPERWEEK		7
8797c478bd9Sstevel@tonic-gate #define	DAYSPERNYEAR		365
8807c478bd9Sstevel@tonic-gate #define	SECSPERHOUR		(SECSPERMIN * MINSPERHOUR)
8817c478bd9Sstevel@tonic-gate #define	SECSPERDAY		(SECSPERHOUR * HOURSPERDAY)
8827c478bd9Sstevel@tonic-gate #define	DC_SPY			(SECSPERDAY * DAYSPERNYEAR)
8837c478bd9Sstevel@tonic-gate #define	DC_SPW			(SECSPERDAY * DAYSPERWEEK)
8847c478bd9Sstevel@tonic-gate #define	DC_SPD			SECSPERDAY
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate #define	DC_SCSI_YEAR_LEN	4		/* YYYY */
8877c478bd9Sstevel@tonic-gate #define	DC_SCSI_WEEK_LEN	2		/* WW */
8887c478bd9Sstevel@tonic-gate #define	DC_SCSI_NPY		5		/* # power-cycle years */
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
8917c478bd9Sstevel@tonic-gate 
8927c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
8937c478bd9Sstevel@tonic-gate }
8947c478bd9Sstevel@tonic-gate #endif
8957c478bd9Sstevel@tonic-gate 
8967c478bd9Sstevel@tonic-gate #endif /* _SYS_EPM_H */
897