xref: /illumos-gate/usr/src/uts/common/sys/epm.h (revision d5ebc493)
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
5c42872d4Smh  * Common Development and Distribution License (the "License").
6c42872d4Smh  * 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 /*
220e751525SEric Saxe  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
263fe80ca4SDan Cross /*
273fe80ca4SDan Cross  * Copyright 2023 Oxide Computer Company
283fe80ca4SDan Cross  */
293fe80ca4SDan Cross 
307c478bd9Sstevel@tonic-gate #ifndef	_SYS_EPM_H
317c478bd9Sstevel@tonic-gate #define	_SYS_EPM_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/pm.h>
347c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
357c478bd9Sstevel@tonic-gate #include <sys/devops.h>
367c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
377c478bd9Sstevel@tonic-gate #include <sys/taskq.h>
38da6c28aaSamw #include <sys/tzfile.h>
397c478bd9Sstevel@tonic-gate 
402df1fe9cSrandyf /*
412df1fe9cSrandyf  * XXXX
422df1fe9cSrandyf  * Do we really need this include?  It may be leftover from early CPUPM code.
432df1fe9cSrandyf  * #include <sys/processor.h>
442df1fe9cSrandyf  */
452df1fe9cSrandyf 
467c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
477c478bd9Sstevel@tonic-gate extern "C" {
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * epm.h:	Function prototypes and data structs for kernel pm functions.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate void e_pm_props(dev_info_t *);
577c478bd9Sstevel@tonic-gate int e_new_pm_props(dev_info_t *);
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #define	PM_LEVEL_UPONLY (-2)	/* only raise power level */
607c478bd9Sstevel@tonic-gate #define	PM_LEVEL_DOWNONLY (-3)	/* only lower power level */
617c478bd9Sstevel@tonic-gate #define	PM_LEVEL_EXACT (-4)	/* wants exact power level */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * Values used by e_pm_props and friends, found in devi_pm_flags
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate #define	PMC_NEEDS_SR		0x00001	/* do suspend/resume despite no "reg" */
677c478bd9Sstevel@tonic-gate #define	PMC_NO_SR		0x00002	/* don't suspend/resume despite "reg" */
687c478bd9Sstevel@tonic-gate #define	PMC_PARENTAL_SR		0x00004	/* call up tree to suspend/resume */
697c478bd9Sstevel@tonic-gate #define	PMC_WANTS_NOTIFY	0x00008	/* notify if child pwr level changes */
707c478bd9Sstevel@tonic-gate #define	PMC_BC			0x00010	/* no pm-components, backwards compat */
717c478bd9Sstevel@tonic-gate #define	PMC_COMPONENTS_DONE	0x00020 /* parsed pm-components */
727c478bd9Sstevel@tonic-gate #define	PMC_COMPONENTS_FAILED	0x00040 /* failed parsing pm-components */
737c478bd9Sstevel@tonic-gate #define	PMC_SUSPENDED		0x00080 /* device has been suspended */
747c478bd9Sstevel@tonic-gate #define	PMC_DEF_THRESH		0x00100 /* thresholds are default */
757c478bd9Sstevel@tonic-gate #define	PMC_DEV_THRESH		0x00200 /* SET_THRESHOLD ioctl seen */
767c478bd9Sstevel@tonic-gate #define	PMC_COMP_THRESH		0x00400 /* relative threshold set */
777c478bd9Sstevel@tonic-gate #define	PMC_NEXDEF_THRESH	0x00800 /* relative threshold set for nexus */
787c478bd9Sstevel@tonic-gate #define	PMC_NOPMKID		0x01000 /* non-pm'd child of pm'd parent */
797c478bd9Sstevel@tonic-gate #define	PMC_NO_INVOL		0x02000 /* no pm without driver's consent */
807c478bd9Sstevel@tonic-gate #define	PMC_VOLPMD		0x04000 /* went down voluntarily */
817c478bd9Sstevel@tonic-gate #define	PMC_SKIP_BRINGUP	0x08000 /* Skipped a dependency bringup */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * A node which is the console frame buffer, and should not be powered down
857c478bd9Sstevel@tonic-gate  * automatically because the OBP driver doesn't know how to power it back up
867c478bd9Sstevel@tonic-gate  * before using it  (can remove this when prom calls back into kernel to do
877c478bd9Sstevel@tonic-gate  * io to console).
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate #define	PMC_CONSOLE_FB		0x10000	/* console framebuffer */
907c478bd9Sstevel@tonic-gate #define	PMC_NOINVOL_DONE	0x20000 /* processed by pm_noinvol_specd() */
917c478bd9Sstevel@tonic-gate #define	PMC_DRIVER_REMOVED	0x40000 /* driver is removed	*/
92c42872d4Smh #define	PMC_CPU_DEVICE		0x80000 /* device is a power manageable CPU */
93c42872d4Smh #define	PMC_CPU_THRESH		0x100000 /* cpu threshold set */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #define	PMC_THRESH_ALL	(PMC_DEF_THRESH | PMC_DEV_THRESH | \
96c42872d4Smh     PMC_COMP_THRESH | PMC_NEXDEF_THRESH | PMC_CPU_THRESH)
977c478bd9Sstevel@tonic-gate #define	PMC_THRESH_NONE	~(PMC_THRESH_ALL)
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /* Flags for the component */
1007c478bd9Sstevel@tonic-gate #define	PM_POWER_OP		0x00001	/* set power in process */
1017c478bd9Sstevel@tonic-gate #define	PM_PHC_WHILE_SET_POWER	0x00002	/* phc and set power deadlock */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /*
1047c478bd9Sstevel@tonic-gate  * One of these is attached to each devinfo that is autopm'd.
1057c478bd9Sstevel@tonic-gate  */
1067c478bd9Sstevel@tonic-gate typedef struct pm_scan {
1077c478bd9Sstevel@tonic-gate 	int		ps_idle_down;	/* PMID_XXX flags */
1087c478bd9Sstevel@tonic-gate 	int		ps_scan_flags;	/* scan flags, defined below */
1097c478bd9Sstevel@tonic-gate 	timeout_id_t	ps_scan_id;	/* per dip scan timeout id */
1107c478bd9Sstevel@tonic-gate } pm_scan_t;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate  * ps_scan_flags may take the following values, plus possibly
1147c478bd9Sstevel@tonic-gate  * more defined.
1157c478bd9Sstevel@tonic-gate  */
1167c478bd9Sstevel@tonic-gate #define	PM_SCANNING		0x100	/* scanning: pm_scan_dev is active */
1177c478bd9Sstevel@tonic-gate #define	PM_SCAN_AGAIN		0x200
1187c478bd9Sstevel@tonic-gate #define	PM_SCAN_STOP		0x400
1197c478bd9Sstevel@tonic-gate #define	PM_SCAN_DISPATCHED	0x800
1207c478bd9Sstevel@tonic-gate 
121fc68e77cSmh #define	PM_DEFAULT_MIN_SCAN	((clock_t)15) /* Minimum scan interval in sec */
122fc68e77cSmh #define	PM_CPU_MIN_SCAN		((clock_t)1) /* Minimum interval for CPUs */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate  * Power management component definitions, used for tracking idleness of
1267c478bd9Sstevel@tonic-gate  * devices.  An array of these hangs off the devi_pm_components member of the
1277c478bd9Sstevel@tonic-gate  * dev_info struct (if initialized by driver and/or auto-pm)
1287c478bd9Sstevel@tonic-gate  * The array of these structs is followed in the same kmem_zalloc'd chunk by
1297c478bd9Sstevel@tonic-gate  * the names pointed to by the structs.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * This (sub-)struct contains all the info extracted from the pm-components
1347c478bd9Sstevel@tonic-gate  * property for each component (name of component, names and values of power
1357c478bd9Sstevel@tonic-gate  * levels supported).  It is in a separate structure to allow it to be handled
1367c478bd9Sstevel@tonic-gate  * as a struct assignment.
1377c478bd9Sstevel@tonic-gate  */
1387c478bd9Sstevel@tonic-gate typedef struct pm_comp {
139*d5ebc493SDan Cross 	char	*pmc_name;		/* name of component */
1407c478bd9Sstevel@tonic-gate 	int	pmc_numlevels;		/* number of power levels supported */
1417c478bd9Sstevel@tonic-gate 	int	*pmc_lvals;		/* numerical values of levels */
1427c478bd9Sstevel@tonic-gate 	int	*pmc_thresh;		/* thresholds in secs, last INT_MAX */
1437c478bd9Sstevel@tonic-gate 	char	**pmc_lnames;		/* human readable names of levels */
1447c478bd9Sstevel@tonic-gate 	/*
1457c478bd9Sstevel@tonic-gate 	 * This part is just bookkeeping for the storage space involved above
1467c478bd9Sstevel@tonic-gate 	 * used for copying and freeing the struct members.  This because C
1477c478bd9Sstevel@tonic-gate 	 * is really an assembler at heart.
1487c478bd9Sstevel@tonic-gate 	 */
1497c478bd9Sstevel@tonic-gate 	size_t	pmc_name_sz;		/* size of name string		*/
1507c478bd9Sstevel@tonic-gate 	char	*pmc_lname_buf;		/* buffer holding *pmc_lnames	*/
1517c478bd9Sstevel@tonic-gate 	size_t	pmc_lnames_sz;		/* total size of pmc_lname_buf	*/
1527c478bd9Sstevel@tonic-gate } pm_comp_t;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate  * Here we have the rest of what we need to know about a component.
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate typedef struct pm_component {
1587c478bd9Sstevel@tonic-gate 	uint_t pmc_flags;		/* flags this component */
1597c478bd9Sstevel@tonic-gate 	uint_t pmc_busycount;		/* for nesting busy calls */
1607c478bd9Sstevel@tonic-gate 	time_t pmc_timestamp;		/* timestamp */
1617c478bd9Sstevel@tonic-gate 	uint_t pmc_norm_pwr;		/* normal power index (or value) */
1627c478bd9Sstevel@tonic-gate 	int pmc_cur_pwr;		/* current power index (or value)  */
1637c478bd9Sstevel@tonic-gate 	int pmc_phc_pwr;		/* prev. value of curpwr (deadlock) */
1647c478bd9Sstevel@tonic-gate 	pm_comp_t pmc_comp;		/* component description */
1657c478bd9Sstevel@tonic-gate } pm_component_t;
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate  * All members of this struct are protected by PM_LOCK_DIP(dip).
1697c478bd9Sstevel@tonic-gate  *
1707c478bd9Sstevel@tonic-gate  * kidsupcnt counts (the number of components of new-style children at non-zero
1717c478bd9Sstevel@tonic-gate  * level (unknown counts as non-zero)) + (the number of old-style children with
1727c478bd9Sstevel@tonic-gate  * component 0 at non-zero level) for parents that have not asked for
173da6c28aaSamw  * notification.  When kidsupcnt is 0 for a nexus node, then pm scans it,
1747c478bd9Sstevel@tonic-gate  * otherwise it leaves it alone.
1757c478bd9Sstevel@tonic-gate  * Parents that ask for notification always get get scanned,
1767c478bd9Sstevel@tonic-gate  * so we keep their kidsupcnt at zero.
1777c478bd9Sstevel@tonic-gate  */
1787c478bd9Sstevel@tonic-gate typedef struct pm_info {
1797c478bd9Sstevel@tonic-gate 	uint_t		pmi_dev_pm_state; /* PM state of a device */
1807c478bd9Sstevel@tonic-gate 	int		pmi_clone;	/* owner for direct pm'd devs */
1817c478bd9Sstevel@tonic-gate 	int		pmi_levels[2];	/* storage space for 2 levels */
1827c478bd9Sstevel@tonic-gate 	int		*pmi_lp;	/* storage space for >2 levels */
1837c478bd9Sstevel@tonic-gate 	kcondvar_t	pmi_cv;		/* condvar for direct PM access */
1847c478bd9Sstevel@tonic-gate } pm_info_t;
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate /*
1877c478bd9Sstevel@tonic-gate  * Work request structure for the dependency processing thread.
1887c478bd9Sstevel@tonic-gate  */
1897c478bd9Sstevel@tonic-gate typedef struct pm_dep_wk {
1907c478bd9Sstevel@tonic-gate 	int		pdw_type;		/* Type of request */
1917c478bd9Sstevel@tonic-gate 	int		pdw_wait;		/* caller waits for result */
1927c478bd9Sstevel@tonic-gate 	int		pdw_done;		/* set when req is done */
1937c478bd9Sstevel@tonic-gate 	int		pdw_ret;		/* return value to caller */
1947c478bd9Sstevel@tonic-gate 	int		pdw_pwr;		/* pwr level of keeper */
1957c478bd9Sstevel@tonic-gate 	kcondvar_t	pdw_cv;			/* cv to wake up caller */
1967c478bd9Sstevel@tonic-gate 	struct		pm_dep_wk *pdw_next;	/* next element */
1977c478bd9Sstevel@tonic-gate 	char		*pdw_keeper;
1987c478bd9Sstevel@tonic-gate 	char		*pdw_kept;
1997c478bd9Sstevel@tonic-gate } pm_dep_wk_t;
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate /*
2027c478bd9Sstevel@tonic-gate  * Types of work, depends on when it gets called:
2037c478bd9Sstevel@tonic-gate  */
2047c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_POWER_ON		1	/* power on */
2057c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_POWER_OFF		2	/* power off */
2067c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_DETACH		3	/* detach */
2077c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_REMOVE_DEP		4	/* dependency removed */
2087c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_BRINGUP_SELF		5	/* released from direct PM */
2097c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_RECORD_KEEPER		6	/* PM_ADD_DEPENDENT */
2107c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_RECORD_KEEPER_PROP	7	/* PM_ADD_DEPENDENT_PROP */
2117c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_KEPT			8	/* dep. work as a kept */
2127c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_KEEPER		9	/* dep. work as a keeper */
2137c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_ATTACH		10	/* when dip is attached */
2147c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_CHECK_KEPT		11	/* check if this is a kept */
2157c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_CPR_SUSPEND		12	/* Suspend dep. during CPR */
2167c478bd9Sstevel@tonic-gate #define	PM_DEP_WK_CPR_RESUME		13	/* Resume dep. after CPR */
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate /*
2197c478bd9Sstevel@tonic-gate  * Wait for dependency work to finish or not.
2207c478bd9Sstevel@tonic-gate  */
2217c478bd9Sstevel@tonic-gate #define	PM_DEP_WAIT	1
2227c478bd9Sstevel@tonic-gate #define	PM_DEP_NOWAIT	0
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate typedef enum pm_canblock
2257c478bd9Sstevel@tonic-gate {
2267c478bd9Sstevel@tonic-gate 	PM_CANBLOCK_BLOCK,	/* wait for controlling process action */
2277c478bd9Sstevel@tonic-gate 	PM_CANBLOCK_FAIL,	/* don't wait, fail request */
2287c478bd9Sstevel@tonic-gate 	PM_CANBLOCK_BYPASS	/* don't wait, ignore controlling process */
2297c478bd9Sstevel@tonic-gate } pm_canblock_t;
2307c478bd9Sstevel@tonic-gate 
231c42872d4Smh typedef enum pm_cpupm
232c42872d4Smh {
233c42872d4Smh 	PM_CPUPM_NOTSET,	/* no specific treatment of CPU devices */
2340e751525SEric Saxe 	PM_CPUPM_POLLING,	/* CPUPM enabled: polling mode */
2350e751525SEric Saxe 	PM_CPUPM_EVENT,		/* CPUPM enabled: event driven mode */
236c42872d4Smh 	PM_CPUPM_DISABLE	/* do not power manage CPU devices */
237c42872d4Smh } pm_cpupm_t;
238c42872d4Smh 
2392df1fe9cSrandyf #define	PPM(dip) ((dev_info_t *)DEVI(dip)->devi_pm_ppm)
2402df1fe9cSrandyf 
2417c478bd9Sstevel@tonic-gate /*
2427c478bd9Sstevel@tonic-gate  * The power request struct uses for the DDI_CTLOPS_POWER busctl.
2437c478bd9Sstevel@tonic-gate  *
2447c478bd9Sstevel@tonic-gate  * Note: When changing this enum it is necessary to maintain binary
2457c478bd9Sstevel@tonic-gate  * compatibility with older versions.  To insure that, add new values only
2467c478bd9Sstevel@tonic-gate  * at the end and refrain from deleting any existing values.
2477c478bd9Sstevel@tonic-gate  */
2487c478bd9Sstevel@tonic-gate typedef enum {
2497c478bd9Sstevel@tonic-gate 	PMR_SET_POWER = 1,		/* called ddi_power (obsolete)	*/
2507c478bd9Sstevel@tonic-gate 	PMR_SUSPEND,			/* parental suspend		*/
2517c478bd9Sstevel@tonic-gate 	PMR_RESUME,			/* parental resume		*/
2527c478bd9Sstevel@tonic-gate 	PMR_PRE_SET_POWER,		/* parent's "pre" notification	*/
2537c478bd9Sstevel@tonic-gate 	PMR_POST_SET_POWER,		/* parent's "post" notification	*/
2547c478bd9Sstevel@tonic-gate 	PMR_PPM_SET_POWER,		/* platform pm set power	*/
2557c478bd9Sstevel@tonic-gate 	PMR_PPM_ATTACH,			/* ppm attach notify - unused	*/
2567c478bd9Sstevel@tonic-gate 	PMR_PPM_DETACH,			/* ppm detach notify - unused   */
2577c478bd9Sstevel@tonic-gate 	PMR_PPM_POWER_CHANGE_NOTIFY,	/* ppm level change notify	*/
2587c478bd9Sstevel@tonic-gate 	PMR_REPORT_PMCAP,		/* report pm capability		*/
2597c478bd9Sstevel@tonic-gate 	PMR_CHANGED_POWER,		/* parent's power_has_changed notif. */
2607c478bd9Sstevel@tonic-gate 	PMR_PPM_PRE_PROBE,		/* ppm pre probe notify		*/
2617c478bd9Sstevel@tonic-gate 	PMR_PPM_POST_PROBE,		/* ppm post probe notify	*/
2627c478bd9Sstevel@tonic-gate 	PMR_PPM_PRE_ATTACH,		/* ppm pre attach notify	*/
2637c478bd9Sstevel@tonic-gate 	PMR_PPM_POST_ATTACH,		/* ppm post pm attach notify	*/
2647c478bd9Sstevel@tonic-gate 	PMR_PPM_PRE_DETACH,		/* ppm pre pm detach notify	*/
2657c478bd9Sstevel@tonic-gate 	PMR_PPM_POST_DETACH,		/* ppm post pm detach notify	*/
2667c478bd9Sstevel@tonic-gate 	PMR_PPM_UNMANAGE,		/* device being unmanaged	*/
2677c478bd9Sstevel@tonic-gate 	PMR_PPM_PRE_RESUME,		/* ppm resume notify		*/
2687c478bd9Sstevel@tonic-gate 	PMR_PPM_ALL_LOWEST,		/* ppm all lowest power notify	*/
2697c478bd9Sstevel@tonic-gate 	PMR_PPM_LOCK_POWER,		/* ppm lock power		*/
2707c478bd9Sstevel@tonic-gate 	PMR_PPM_UNLOCK_POWER,		/* ppm unlock power		*/
2717c478bd9Sstevel@tonic-gate 	PMR_PPM_TRY_LOCK_POWER,		/* ppm try lock power		*/
2727c478bd9Sstevel@tonic-gate 	PMR_PPM_INIT_CHILD,		/* ppm init child notify	*/
2737c478bd9Sstevel@tonic-gate 	PMR_PPM_UNINIT_CHILD,		/* ppm uninit child notify	*/
2742df1fe9cSrandyf 	PMR_PPM_POWER_LOCK_OWNER,	/* ppm power lock owner's address */
2752df1fe9cSrandyf 	PMR_PPM_ENTER_SX,		/* ppm: enter ACPI S[2-4] state	*/
2762df1fe9cSrandyf 	PMR_PPM_EXIT_SX,		/* ppm: enter ACPI S[2-4] state	*/
2772df1fe9cSrandyf 	PMR_PPM_SEARCH_LIST		/* ppm: search tuple list	*/
2787c478bd9Sstevel@tonic-gate } pm_request_type;
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate /*
2817c478bd9Sstevel@tonic-gate  * When changing the elements of the union below it is necessary to
2827c478bd9Sstevel@tonic-gate  * maintain binary compatibility with older versions.  Refrain from
2837c478bd9Sstevel@tonic-gate  * deleting existing elements of the union or modifying their contents.
2847c478bd9Sstevel@tonic-gate  * Avoid increasing the total size of this structure if new elements
2857c478bd9Sstevel@tonic-gate  * must be added.
2867c478bd9Sstevel@tonic-gate  */
2877c478bd9Sstevel@tonic-gate typedef struct power_req {
2887c478bd9Sstevel@tonic-gate 	pm_request_type request_type;
2897c478bd9Sstevel@tonic-gate 	union req {
2907c478bd9Sstevel@tonic-gate 		/*
2917c478bd9Sstevel@tonic-gate 		 * PMR_SET_POWER (obsolete)
2927c478bd9Sstevel@tonic-gate 		 */
2937c478bd9Sstevel@tonic-gate 		struct set_power_req {
2947c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
2957c478bd9Sstevel@tonic-gate 			int		cmpt;
2967c478bd9Sstevel@tonic-gate 			int		level;
2977c478bd9Sstevel@tonic-gate 		} set_power_req;
2987c478bd9Sstevel@tonic-gate 		/*
2997c478bd9Sstevel@tonic-gate 		 * PMR_SUSPEND
3007c478bd9Sstevel@tonic-gate 		 */
3017c478bd9Sstevel@tonic-gate 		struct suspend_req {
3027c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3037c478bd9Sstevel@tonic-gate 			ddi_detach_cmd_t cmd;
3047c478bd9Sstevel@tonic-gate 		} suspend_req;
3057c478bd9Sstevel@tonic-gate 		/*
3067c478bd9Sstevel@tonic-gate 		 * PMR_PPM_PRE_RESUME or PMR_RESUME
3077c478bd9Sstevel@tonic-gate 		 */
3087c478bd9Sstevel@tonic-gate 		struct resume_req {
3097c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3107c478bd9Sstevel@tonic-gate 			ddi_attach_cmd_t cmd;
3117c478bd9Sstevel@tonic-gate 		} resume_req;
3127c478bd9Sstevel@tonic-gate 		/*
3137c478bd9Sstevel@tonic-gate 		 * PMR_PRE_SET_POWER
3147c478bd9Sstevel@tonic-gate 		 */
3157c478bd9Sstevel@tonic-gate 		struct pre_set_power_req {
3167c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3177c478bd9Sstevel@tonic-gate 			int		cmpt;
3187c478bd9Sstevel@tonic-gate 			int		old_level;
3197c478bd9Sstevel@tonic-gate 			int		new_level;
3207c478bd9Sstevel@tonic-gate 		} pre_set_power_req;
3217c478bd9Sstevel@tonic-gate 		/*
3227c478bd9Sstevel@tonic-gate 		 * PMR_POST_SET_POWER
3237c478bd9Sstevel@tonic-gate 		 */
3247c478bd9Sstevel@tonic-gate 		struct post_set_power_req {
3257c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3267c478bd9Sstevel@tonic-gate 			int		cmpt;
3277c478bd9Sstevel@tonic-gate 			int		old_level;
3287c478bd9Sstevel@tonic-gate 			int		new_level;
3297c478bd9Sstevel@tonic-gate 			int		result;		/* driver's return */
3307c478bd9Sstevel@tonic-gate 		} post_set_power_req;
3317c478bd9Sstevel@tonic-gate 		/*
3327c478bd9Sstevel@tonic-gate 		 * PMR_PPM_SET_POWER
3337c478bd9Sstevel@tonic-gate 		 */
3347c478bd9Sstevel@tonic-gate 		struct ppm_set_power_req {
3357c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3367c478bd9Sstevel@tonic-gate 			int		cmpt;
3377c478bd9Sstevel@tonic-gate 			int		old_level;
3387c478bd9Sstevel@tonic-gate 			int		new_level;
3397c478bd9Sstevel@tonic-gate 			pm_canblock_t	canblock;
3407c478bd9Sstevel@tonic-gate 			void		*cookie;
3417c478bd9Sstevel@tonic-gate 		} ppm_set_power_req;
3427c478bd9Sstevel@tonic-gate 		/*
3437c478bd9Sstevel@tonic-gate 		 * PMR_PPM_POWER_CHANGE_NOTIFY
3447c478bd9Sstevel@tonic-gate 		 */
3457c478bd9Sstevel@tonic-gate 		struct ppm_notify_level_req {
3467c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3477c478bd9Sstevel@tonic-gate 			int		cmpt;
3487c478bd9Sstevel@tonic-gate 			int		old_level;
3497c478bd9Sstevel@tonic-gate 			int		new_level;
3507c478bd9Sstevel@tonic-gate 		} ppm_notify_level_req;
3517c478bd9Sstevel@tonic-gate 		/*
3527c478bd9Sstevel@tonic-gate 		 * PMR_REPORT_PMCAP
3537c478bd9Sstevel@tonic-gate 		 */
3547c478bd9Sstevel@tonic-gate 		struct report_pmcap_req {
3557c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3567c478bd9Sstevel@tonic-gate 			int		cap;
357*d5ebc493SDan Cross 			void		*arg;
3587c478bd9Sstevel@tonic-gate 		} report_pmcap_req;
3597c478bd9Sstevel@tonic-gate 		/*
3607c478bd9Sstevel@tonic-gate 		 * PMR_CHANGED_POWER
3617c478bd9Sstevel@tonic-gate 		 */
3627c478bd9Sstevel@tonic-gate 		struct changed_power_req {
3637c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3647c478bd9Sstevel@tonic-gate 			int		cmpt;
3657c478bd9Sstevel@tonic-gate 			int		old_level;
3667c478bd9Sstevel@tonic-gate 			int		new_level;
3677c478bd9Sstevel@tonic-gate 			int		result;
3687c478bd9Sstevel@tonic-gate 		} changed_power_req;
3697c478bd9Sstevel@tonic-gate 		/*
3707c478bd9Sstevel@tonic-gate 		 * PMR_PPM_PRE_PROBE, PMR_PPM_POST_PROBE, PMR_PPM_PRE_ATTACH,
3717c478bd9Sstevel@tonic-gate 		 * PMR_PPM_POST_ATTACH, PMR_PPM_PRE_DETACH, PMR_PPM_POST_DETACH
3727c478bd9Sstevel@tonic-gate 		 * PMR_PPM_INIT_CHILD, PMR_PPM_UNINIT_CHILD, or PMR_PPM_UNMANAGE
3737c478bd9Sstevel@tonic-gate 		 */
3747c478bd9Sstevel@tonic-gate 		struct ppm_config_req {
3757c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3767c478bd9Sstevel@tonic-gate 			int		result;		/* post only */
3777c478bd9Sstevel@tonic-gate 		} ppm_config_req;
3787c478bd9Sstevel@tonic-gate 		/*
3797c478bd9Sstevel@tonic-gate 		 * PMR_PPM_ALL_LOWEST
3807c478bd9Sstevel@tonic-gate 		 */
3817c478bd9Sstevel@tonic-gate 		struct ppm_all_lowest_req {
3827c478bd9Sstevel@tonic-gate 			int		mode;
3837c478bd9Sstevel@tonic-gate 		} ppm_all_lowest_req;
3847c478bd9Sstevel@tonic-gate 		/*
3857c478bd9Sstevel@tonic-gate 		 * PMR_PPM_LOCK_POWER, PMR_PPM_TRY_LOCK_POWER
3867c478bd9Sstevel@tonic-gate 		 */
3877c478bd9Sstevel@tonic-gate 		struct ppm_lock_power_req {
3887c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3897c478bd9Sstevel@tonic-gate 		} ppm_lock_power_req;
3907c478bd9Sstevel@tonic-gate 		/*
3917c478bd9Sstevel@tonic-gate 		 * PMR_PPM_UNLOCK_POWER
3927c478bd9Sstevel@tonic-gate 		 */
3937c478bd9Sstevel@tonic-gate 		struct ppm_unlock_power_req {
3947c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
3957c478bd9Sstevel@tonic-gate 		} ppm_unlock_power_req;
3967c478bd9Sstevel@tonic-gate 		/*
3977c478bd9Sstevel@tonic-gate 		 * PMR_PPM_POWER_LOCK_OWNER
3987c478bd9Sstevel@tonic-gate 		 */
3997c478bd9Sstevel@tonic-gate 		struct ppm_power_lock_owner_req {
4007c478bd9Sstevel@tonic-gate 			dev_info_t	*who;
4017c478bd9Sstevel@tonic-gate 			kthread_t	*owner;
4027c478bd9Sstevel@tonic-gate 		} ppm_power_lock_owner_req;
4032df1fe9cSrandyf 		/*
4042df1fe9cSrandyf 		 * PMR_PPM_POWER_ENTER_SX
4052df1fe9cSrandyf 		 */
4062df1fe9cSrandyf 		struct ppm_power_enter_sx_req {
4072df1fe9cSrandyf 			int	sx_state;	/* S3, S4 */
4082df1fe9cSrandyf 			int	test_point;	/* test point */
4092df1fe9cSrandyf 			uint64_t wakephys;	/* restart vector phys addr */
4102df1fe9cSrandyf 			void *psr;		/* PSM (apic) state buffer */
4112df1fe9cSrandyf 		} ppm_power_enter_sx_req;
4122df1fe9cSrandyf 		/*
4132df1fe9cSrandyf 		 * PMR_PPM_SEARCH_LIST
4142df1fe9cSrandyf 		 */
4152df1fe9cSrandyf 		struct ppm_search_list {
4162df1fe9cSrandyf 			pm_searchargs_t *searchlist;
4172df1fe9cSrandyf 			int		result;
4182df1fe9cSrandyf 		} ppm_search_list_req;
4197c478bd9Sstevel@tonic-gate 	} req;
4207c478bd9Sstevel@tonic-gate } power_req_t;
4217c478bd9Sstevel@tonic-gate 
4222df1fe9cSrandyf #define	S3	3
4232df1fe9cSrandyf #define	S4	4
4242df1fe9cSrandyf 
4252df1fe9cSrandyf extern int cpr_test_point;
4262df1fe9cSrandyf extern major_t cpr_device;
4272df1fe9cSrandyf 
4282df1fe9cSrandyf #define	LOOP_BACK_NONE	0
4292df1fe9cSrandyf #define	LOOP_BACK_PASS	1
4302df1fe9cSrandyf #define	LOOP_BACK_FAIL	2
4312df1fe9cSrandyf #define	FORCE_SUSPEND_TO_RAM	3
4322df1fe9cSrandyf #define	DEVICE_SUSPEND_TO_RAM	4
4332df1fe9cSrandyf 
4342df1fe9cSrandyf /*
4352df1fe9cSrandyf  * Struct passed as arg to appm_ioctl
4362df1fe9cSrandyf  */
4372df1fe9cSrandyf typedef struct s3_args {
4382df1fe9cSrandyf 	int		s3a_state;	/* S3, S4 */
4392df1fe9cSrandyf 	int		s3a_test_point;	/* test point */
4402df1fe9cSrandyf 	uint64_t	s3a_wakephys;	/* restart vector physical addr */
4412df1fe9cSrandyf 	void		*s3a_psr;	/* apic state save buffer */
4422df1fe9cSrandyf } s3a_t;
4432df1fe9cSrandyf 
4447c478bd9Sstevel@tonic-gate /*
4457c478bd9Sstevel@tonic-gate  * Structure used by the following bus_power operations:
4467c478bd9Sstevel@tonic-gate  *
4477c478bd9Sstevel@tonic-gate  *	BUS_POWER_PRE_NOTIFICATION
4487c478bd9Sstevel@tonic-gate  *	BUS_POWER_POST_NOTIFICATION
4497c478bd9Sstevel@tonic-gate  *	BUS_POWER_CHILD_PWRCHG
4507c478bd9Sstevel@tonic-gate  */
4517c478bd9Sstevel@tonic-gate typedef struct pm_bp_child_pwrchg {
4527c478bd9Sstevel@tonic-gate 	dev_info_t	*bpc_dip;	/* dip of the target device */
4537c478bd9Sstevel@tonic-gate 	char		*bpc_path;	/* path to the target device */
4547c478bd9Sstevel@tonic-gate 	int		bpc_comp;	/* component changing power */
4557c478bd9Sstevel@tonic-gate 	int		bpc_olevel;	/* old power level */
4567c478bd9Sstevel@tonic-gate 	int		bpc_nlevel;	/* new power level */
4577c478bd9Sstevel@tonic-gate 	void		*bpc_private;	/* PM framework private */
4587c478bd9Sstevel@tonic-gate } pm_bp_child_pwrchg_t;
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate /*
4617c478bd9Sstevel@tonic-gate  * Structure used by the BUS_POWER_NEXUS_PWRUP operation
4627c478bd9Sstevel@tonic-gate  */
4637c478bd9Sstevel@tonic-gate typedef struct pm_bp_nexus_pwrup {
4647c478bd9Sstevel@tonic-gate 	dev_info_t	*bpn_dip;	/* dip of the nexus device */
4657c478bd9Sstevel@tonic-gate 	int		bpn_comp;	/* component powering up */
4667c478bd9Sstevel@tonic-gate 	int		bpn_level;	/* new power level */
4677c478bd9Sstevel@tonic-gate 	void		*bpn_private;	/* PM framework private */
4687c478bd9Sstevel@tonic-gate } pm_bp_nexus_pwrup_t;
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate /*
4717c478bd9Sstevel@tonic-gate  * Structure used by the BUS_POWER_HAS_CHANGED operation
4727c478bd9Sstevel@tonic-gate  */
4737c478bd9Sstevel@tonic-gate typedef struct pm_bp_has_changed {
4747c478bd9Sstevel@tonic-gate 	dev_info_t	*bphc_dip;	/* dip of the target device */
4757c478bd9Sstevel@tonic-gate 	char		*bphc_path;	/* path to the target device */
4767c478bd9Sstevel@tonic-gate 	int		bphc_comp;	/* component changing power */
4777c478bd9Sstevel@tonic-gate 	int		bphc_olevel;	/* old power level */
4787c478bd9Sstevel@tonic-gate 	int		bphc_nlevel;	/* new power level */
4797c478bd9Sstevel@tonic-gate 	void		*bphc_private;	/* PM framework private */
4807c478bd9Sstevel@tonic-gate } pm_bp_has_changed_t;
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate /*
4837c478bd9Sstevel@tonic-gate  * Commands indicating which activity is requiring an
4847c478bd9Sstevel@tonic-gate  * update to the noinvol counters.
4857c478bd9Sstevel@tonic-gate  */
4867c478bd9Sstevel@tonic-gate #define	PM_BP_NOINVOL_ATTACH	1
4877c478bd9Sstevel@tonic-gate #define	PM_BP_NOINVOL_DETACH	2
4887c478bd9Sstevel@tonic-gate #define	PM_BP_NOINVOL_REMDRV	3
4897c478bd9Sstevel@tonic-gate #define	PM_BP_NOINVOL_CFB	4
4907c478bd9Sstevel@tonic-gate #define	PM_BP_NOINVOL_POWER	5
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate /*
4937c478bd9Sstevel@tonic-gate  * Structure used by the BUS_POWER_NOINVOL operation.
4947c478bd9Sstevel@tonic-gate  */
4957c478bd9Sstevel@tonic-gate typedef struct pm_bp_noinvol {
4967c478bd9Sstevel@tonic-gate 	dev_info_t	*bpni_dip;	/* dip of the target device */
4977c478bd9Sstevel@tonic-gate 	char		*bpni_path;	/* path to the target device */
4987c478bd9Sstevel@tonic-gate 	int		bpni_cmd;	/* how to update the counters */
4997c478bd9Sstevel@tonic-gate 	int		bpni_volpmd;	/* volpmd of target device */
5007c478bd9Sstevel@tonic-gate 	int		bpni_wasvolpmd;	/* whether to update volpmd */
5017c478bd9Sstevel@tonic-gate 	void		*bpni_private;	/* PM framework private */
5027c478bd9Sstevel@tonic-gate } pm_bp_noinvol_t;
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate /*
5057c478bd9Sstevel@tonic-gate  * This struct is used by the code that makes a PMR_PPM_SET_POWER request
5067c478bd9Sstevel@tonic-gate  * to ppm. Devices that changed power other than the primary device (which
5077c478bd9Sstevel@tonic-gate  * was requested) are passed back to the pm framework through this
5087c478bd9Sstevel@tonic-gate  * structure.
5097c478bd9Sstevel@tonic-gate  */
5107c478bd9Sstevel@tonic-gate typedef struct pm_ppm_devlist {
5117c478bd9Sstevel@tonic-gate 	dev_info_t	*ppd_who;
5127c478bd9Sstevel@tonic-gate 	int		ppd_cmpt;
5137c478bd9Sstevel@tonic-gate 	int		ppd_old_level;
5147c478bd9Sstevel@tonic-gate 	int		ppd_new_level;
5157c478bd9Sstevel@tonic-gate 	struct pm_ppm_devlist	*ppd_next;
5167c478bd9Sstevel@tonic-gate } pm_ppm_devlist_t;
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate /*
5197c478bd9Sstevel@tonic-gate  * This struct is used by the code that brings up parents and notifies
5207c478bd9Sstevel@tonic-gate  * ppm drivers across probe/attach/detach (pm_pre/post_probe/attach/detach())
5217c478bd9Sstevel@tonic-gate  */
5227c478bd9Sstevel@tonic-gate typedef struct pm_ppm_cookie {
5237c478bd9Sstevel@tonic-gate 	dev_info_t		*ppc_dip;	/* dip of target node */
5247c478bd9Sstevel@tonic-gate 	dev_info_t		*ppc_pdip;	/* parent's dip */
5257c478bd9Sstevel@tonic-gate 	dev_info_t		*ppc_ppm;	/* interested ppm driver */
5267c478bd9Sstevel@tonic-gate 	int			ppc_cmd;	/* attach/detach cmd */
5277c478bd9Sstevel@tonic-gate } pm_ppm_cookie_t;
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate /*
5307c478bd9Sstevel@tonic-gate  * This struct records one dependency (a device keeps another or others up)
5317c478bd9Sstevel@tonic-gate  * pdr_size includes size of strings.
5327c478bd9Sstevel@tonic-gate  */
5337c478bd9Sstevel@tonic-gate typedef struct pm_dep_rec {
5347c478bd9Sstevel@tonic-gate 	char *pdr_keeper;		/* physpath of device keeping up */
5357c478bd9Sstevel@tonic-gate 	char *pdr_kept;			/* physpath or property name */
5367c478bd9Sstevel@tonic-gate 	char **pdr_kept_paths;		/* array of kept devices' paths */
5377c478bd9Sstevel@tonic-gate 	struct pm_dep_rec *pdr_next;	/* next dependency device */
5387c478bd9Sstevel@tonic-gate 	size_t pdr_size;		/* size to kmem_free */
5397c478bd9Sstevel@tonic-gate 	major_t pdr_major;		/* major of kept driver (not props) */
5407c478bd9Sstevel@tonic-gate 	int pdr_isprop;			/* true if kept is property name */
5417c478bd9Sstevel@tonic-gate 	int pdr_kept_count;		/* how many kept altogether */
5427c478bd9Sstevel@tonic-gate 	int pdr_satisfied;		/* true if in force (not properties) */
5437c478bd9Sstevel@tonic-gate } pm_pdr_t;
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate /*
5477c478bd9Sstevel@tonic-gate  * This struct records threshold information about a single component
5487c478bd9Sstevel@tonic-gate  */
5497c478bd9Sstevel@tonic-gate typedef struct pm_thresh_entry {
5507c478bd9Sstevel@tonic-gate 	int pte_numthresh;
5517c478bd9Sstevel@tonic-gate 	int *pte_thresh;
5527c478bd9Sstevel@tonic-gate } pm_pte_t;
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate /*
5557c478bd9Sstevel@tonic-gate  * Note that this header and its array of entry structs with their arrays
5567c478bd9Sstevel@tonic-gate  * of thresholds and string storage for physpath are all kmem_alloced in one
5577c478bd9Sstevel@tonic-gate  * chunk for easy freeing ptr_size is the size of that chunk
5587c478bd9Sstevel@tonic-gate  */
5597c478bd9Sstevel@tonic-gate typedef struct pm_thresh_rec {
5607c478bd9Sstevel@tonic-gate 	char			*ptr_physpath;	/* identifies node */
5617c478bd9Sstevel@tonic-gate 	struct pm_thresh_rec	*ptr_next;
5627c478bd9Sstevel@tonic-gate 	int			ptr_numcomps;	/* number of components */
5637c478bd9Sstevel@tonic-gate 	size_t			ptr_size;	/* total size for kmem_free */
564*d5ebc493SDan Cross 	pm_pte_t		*ptr_entries;
5657c478bd9Sstevel@tonic-gate } pm_thresh_rec_t;
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate /*
5687c478bd9Sstevel@tonic-gate  * pmi_dev_pm_state state bits:
5697c478bd9Sstevel@tonic-gate  */
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate /*
5727c478bd9Sstevel@tonic-gate  * a direct-pm device, not scanned, but controlled by a process
5737c478bd9Sstevel@tonic-gate  */
5747c478bd9Sstevel@tonic-gate #define	PM_DIRECT	0x1
5757c478bd9Sstevel@tonic-gate /*
5767c478bd9Sstevel@tonic-gate  * autopm is suspended while waiting to see if detach succeeds
5777c478bd9Sstevel@tonic-gate  */
5787c478bd9Sstevel@tonic-gate #define	PM_DETACHING	0x2
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate /*
5817c478bd9Sstevel@tonic-gate  * An all_to_normal operation for an autopm device that is detaching, is
5827c478bd9Sstevel@tonic-gate  * deferred in case the detach fails.
5837c478bd9Sstevel@tonic-gate  */
5847c478bd9Sstevel@tonic-gate #define	PM_ALLNORM_DEFERRED	0x4
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate #define	PM_GET_PM_INFO(dip) (DEVI(dip)->devi_pm_info)
5877c478bd9Sstevel@tonic-gate #define	PM_GET_PM_SCAN(dip) (DEVI(dip)->devi_pm_scan)
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate #define	PM_NUMCMPTS(dip) (DEVI(dip)->devi_pm_num_components)
5907c478bd9Sstevel@tonic-gate #define	PM_CP(dip, comp) (&DEVI(dip)->devi_pm_components[comp])
5917c478bd9Sstevel@tonic-gate 
5927c478bd9Sstevel@tonic-gate /*
5937c478bd9Sstevel@tonic-gate  * Returns true if the device specified by dip is directly power managed
5947c478bd9Sstevel@tonic-gate  */
5957c478bd9Sstevel@tonic-gate #define	PM_ISDIRECT(dip) \
5967c478bd9Sstevel@tonic-gate 	(((pm_info_t *)PM_GET_PM_INFO(dip))->pmi_dev_pm_state & PM_DIRECT)
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate /*
5997c478bd9Sstevel@tonic-gate  * Returns true if the device specified by dip is an old node for which we
6007c478bd9Sstevel@tonic-gate  * provide backwards compatible behavior (e.g. no pm-components property).
6017c478bd9Sstevel@tonic-gate  */
6027c478bd9Sstevel@tonic-gate #define	PM_ISBC(dip) (DEVI(dip)->devi_pm_flags & PMC_BC)
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate /*
6057c478bd9Sstevel@tonic-gate  * Returns true if we have skipped a dependency bringup on this dip.
6067c478bd9Sstevel@tonic-gate  */
6077c478bd9Sstevel@tonic-gate #define	PM_SKBU(dip) (DEVI(dip)->devi_pm_flags & PMC_SKIP_BRINGUP)
6087c478bd9Sstevel@tonic-gate 
609c42872d4Smh /*
610c42872d4Smh  * Returns true if device specified by dip is a power manageable CPU.
611c42872d4Smh  */
612c42872d4Smh #define	PM_ISCPU(dip) (DEVI(dip)->devi_pm_flags & PMC_CPU_DEVICE)
613c42872d4Smh 
614c42872d4Smh /*
6150e751525SEric Saxe  * Returns true if cpupm is enabled in event driven mode.
616c42872d4Smh  */
6170e751525SEric Saxe #define	PM_EVENT_CPUPM (cpupm == PM_CPUPM_EVENT)
6180e751525SEric Saxe 
6190e751525SEric Saxe /*
6200e751525SEric Saxe  * Returns true if cpupm is enabled in polling mode.
6210e751525SEric Saxe  */
6220e751525SEric Saxe #define	PM_POLLING_CPUPM (cpupm == PM_CPUPM_POLLING)
6230e751525SEric Saxe 
6240e751525SEric Saxe /*
6250e751525SEric Saxe  * Returns true if cpupm operating using the default mode.
6260e751525SEric Saxe  */
6270e751525SEric Saxe #define	PM_DEFAULT_CPUPM (cpupm == cpupm_default_mode)
628c42872d4Smh 
629c42872d4Smh /*
630c42872d4Smh  * Returns true if is disabled.
631c42872d4Smh  */
632c42872d4Smh #define	PM_CPUPM_DISABLED (cpupm == PM_CPUPM_DISABLE)
633c42872d4Smh 
634c42872d4Smh /*
6350e751525SEric Saxe  * If ((autopm is enabled and
6360e751525SEric Saxe  *	(CPUPM is not disabled and we're not in event mode, or it isn't a cpu))
6370e751525SEric Saxe  *	  OR
6380e751525SEric Saxe  *	(CPUPM are enabled and it is one))
639c42872d4Smh  */
640c42872d4Smh #define	PM_SCANABLE(dip) ((autopm_enabled && \
6410e751525SEric Saxe 	((!PM_CPUPM_DISABLED && !PM_EVENT_CPUPM) || !PM_ISCPU(dip))) || \
6420e751525SEric Saxe 	(PM_POLLING_CPUPM && PM_ISCPU(dip)))
643c42872d4Smh 
6447c478bd9Sstevel@tonic-gate #define	PM_NOT_ALL_LOWEST	0x0	/* not all components are at lowest */
6457c478bd9Sstevel@tonic-gate #define	PM_ALL_LOWEST		0x1	/* all components are at lowest lvl */
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate #define	PM_ADDR(dip)	(ddi_get_name_addr(dip) ? ddi_get_name_addr(dip) : "")
6487c478bd9Sstevel@tonic-gate #define	PM_NAME(dip)	(ddi_binding_name(dip))
6497c478bd9Sstevel@tonic-gate #define	PM_NODE(dip)	(ddi_node_name(dip))
6507c478bd9Sstevel@tonic-gate #define	PM_INST(dip)	(ddi_get_instance(dip))
6517c478bd9Sstevel@tonic-gate #define	PM_DEVICE(dip)	PM_NAME(dip), PM_ADDR(dip), PM_NODE(dip), PM_INST(dip)
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate #ifdef	DEBUG
6547c478bd9Sstevel@tonic-gate /*
6557c478bd9Sstevel@tonic-gate  * Flags passed to PMD to enable debug printfs.  If the same flag is set in
6567c478bd9Sstevel@tonic-gate  * pm_debug below then the message is printed.  The most generally useful
6577c478bd9Sstevel@tonic-gate  * ones are the first 3 or 4.
6587c478bd9Sstevel@tonic-gate  */
6597c478bd9Sstevel@tonic-gate #define	PMD_ERROR	0x0000001
6607c478bd9Sstevel@tonic-gate #define	PMD_FAIL	0x0000002
6617c478bd9Sstevel@tonic-gate #define	PMD_IOCTL	0x0000004
6627c478bd9Sstevel@tonic-gate #define	PMD_SCAN	0x0000008
6637c478bd9Sstevel@tonic-gate #define	PMD_RESCAN	0x0000010
6647c478bd9Sstevel@tonic-gate #define	PMD_REMINFO	0x0000020
6657c478bd9Sstevel@tonic-gate #define	PMD_NAMETODIP	0x0000040
6667c478bd9Sstevel@tonic-gate #define	PMD_CLOSE	0x0000080
6677c478bd9Sstevel@tonic-gate #define	PMD_DIN		0x0000100	/* Dev Is Needed */
6687c478bd9Sstevel@tonic-gate #define	PMD_PMC		0x0000200	/* for testing with sun4m pmc driver */
6697c478bd9Sstevel@tonic-gate #define	PMD_PPM		0x0000400
6707c478bd9Sstevel@tonic-gate #define	PMD_DEP		0x0000800	/* dependency processing */
6717c478bd9Sstevel@tonic-gate #define	PMD_IDLEDOWN	0x0001000
6727c478bd9Sstevel@tonic-gate #define	PMD_SET		0x0002000
6737c478bd9Sstevel@tonic-gate #define	PMD_BRING	0x0004000
6747c478bd9Sstevel@tonic-gate #define	PMD_ALLNORM	0x0008000
6757c478bd9Sstevel@tonic-gate #define	PMD_REMDEV	0x0010000
6767c478bd9Sstevel@tonic-gate #define	PMD_LEVEL	0x0020000
6777c478bd9Sstevel@tonic-gate #define	PMD_THRESH	0x0040000
6787c478bd9Sstevel@tonic-gate #define	PMD_DPM		0x0080000	/* Direct Power Management */
6797c478bd9Sstevel@tonic-gate #define	PMD_NORM	0x0100000
6807c478bd9Sstevel@tonic-gate #define	PMD_STATS	0x0200000
6817c478bd9Sstevel@tonic-gate #define	PMD_DEREG	0x0400000
6827c478bd9Sstevel@tonic-gate #define	PMD_KEEPS	0x0800000
6837c478bd9Sstevel@tonic-gate #define	PMD_KIDSUP	0x1000000
6847c478bd9Sstevel@tonic-gate #define	PMD_TCHECK	0x2000000
6857c478bd9Sstevel@tonic-gate #define	PMD_NOINVOL	0x4000000
6867c478bd9Sstevel@tonic-gate #define	PMD_CFB		0x8000000	/* console fb pm */
6877c478bd9Sstevel@tonic-gate #define	PMD_DHR		0x10000000	/* driver hold/rele changes */
6887c478bd9Sstevel@tonic-gate #define	PMD_PIL		0x20000000	/* print out PIL when calling power */
6897c478bd9Sstevel@tonic-gate #define	PMD_PHC		0x40000000	/* pm_power_has_changed messages */
6907c478bd9Sstevel@tonic-gate #define	PMD_LOCK	0x80000000
6912df1fe9cSrandyf #define	PMD_SX		0x80000000	/* ACPI S[1234] states */
6922df1fe9cSrandyf #define	PMD_PROTO	PMD_SX		/* and other Prototype stuff */
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate extern uint_t	pm_debug;
6957c478bd9Sstevel@tonic-gate extern uint_t	pm_divertdebug;
6967c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/
6977c478bd9Sstevel@tonic-gate extern void	pm_log(const char *fmt, ...) __KPRINTFLIKE(1);
6987c478bd9Sstevel@tonic-gate 
6992df1fe9cSrandyf #if !defined(__sparc)
7002df1fe9cSrandyf /*
7012df1fe9cSrandyf  * On non-sparc machines, PMDDEBUG isn't as big a deal as Sparc, so we
7022df1fe9cSrandyf  * define PMDDEUG here for use on non-sparc platforms.
7032df1fe9cSrandyf  */
7042df1fe9cSrandyf #define	PMDDEBUG
7052df1fe9cSrandyf #endif /* !__sparc */
7062df1fe9cSrandyf 
707c50cf65dSkchow #ifdef PMDDEBUG
708*d5ebc493SDan Cross #define	PMD(level, arglist) {			\
7097c478bd9Sstevel@tonic-gate 	if (pm_debug & (level)) {		\
7107c478bd9Sstevel@tonic-gate 		pm_log arglist;			\
7117c478bd9Sstevel@tonic-gate 	}					\
7127c478bd9Sstevel@tonic-gate }
7132df1fe9cSrandyf #else /* !PMDDEBUG */
714c50cf65dSkchow #define	PMD(level, arglist)	((void)0);
7152df1fe9cSrandyf #endif /* PMDDEBUG */
7162df1fe9cSrandyf #ifndef	sparc
7172df1fe9cSrandyf extern clock_t pt_sleep;
7182df1fe9cSrandyf /* code is char hex number to display on POST LED */
7192df1fe9cSrandyf #define	PT(code) {outb(0x80, (char)code); drv_usecwait(pt_sleep); }
7202df1fe9cSrandyf #else
7212df1fe9cSrandyf #define	PT(code)
722c50cf65dSkchow #endif
7237c478bd9Sstevel@tonic-gate #else
7247c478bd9Sstevel@tonic-gate #define	PMD(level, arglist)
7252df1fe9cSrandyf #define	PT(code)
7267c478bd9Sstevel@tonic-gate #endif
7272df1fe9cSrandyf /*
7282df1fe9cSrandyf  * Code	Value	Indication
7292df1fe9cSrandyf  *
7302df1fe9cSrandyf  */
7312df1fe9cSrandyf #define	PT_SPL7		0x01	/* pm_suspend spl7 */
7322df1fe9cSrandyf #define	PT_PMSRET	0x02	/* pm_suspend returns */
7332df1fe9cSrandyf #define	PT_PPMCTLOP	0x03	/* invoking ppm_ctlops */
7342df1fe9cSrandyf #define	PT_ACPISDEV	0x04	/* acpi suspend devices */
7352df1fe9cSrandyf #define	PT_IC		0x05	/* acpi intr_clear */
7362df1fe9cSrandyf #define	PT_1to1		0x06	/* 1:1 mapping */
7372df1fe9cSrandyf #define	PT_SC		0x07	/* save context */
7382df1fe9cSrandyf #define	PT_SWV		0x08	/* set waking vector */
7392df1fe9cSrandyf #define	PT_SWV_FAIL	0x09	/* set waking vector failed */
7402df1fe9cSrandyf #define	PT_EWE		0x0a	/* enable wake events */
7412df1fe9cSrandyf #define	PT_EWE_FAIL	0x0b	/* enable wake events failed */
7422df1fe9cSrandyf #define	PT_RTCW		0x0c	/* setting rtc wakeup */
7432df1fe9cSrandyf #define	PT_RTCW_FAIL	0x0d	/* setting rtc wakeup failed */
7442df1fe9cSrandyf #define	PT_TOD		0x0e	/* setting tod */
7452df1fe9cSrandyf #define	PT_SXP		0x0f	/* sx prep */
7462df1fe9cSrandyf #define	PT_SXE		0x10	/* sx enter */
7472df1fe9cSrandyf #define	PT_SXE_FAIL	0x11	/* sx enter failed */
7482df1fe9cSrandyf #define	PT_INSOM	0x12	/* insomnia label */
7492df1fe9cSrandyf #define	PT_WOKE		0x20	/* woke up */
7502df1fe9cSrandyf #define	PT_UNDO1to1	0x21	/* Undo 1:1 mapping */
7512df1fe9cSrandyf #define	PT_LSS		0x22	/* leave sleep state */
7522df1fe9cSrandyf #define	PT_LSS_FAIL	0x23	/* leave sleep state failed */
753076d97abSPhi Tran #define	PT_CPB		0x24	/* clear power button event */
754076d97abSPhi Tran #define	PT_CPB_FAIL	0x25	/* clear power button event failed */
7552df1fe9cSrandyf #define	PT_DRTC_FAIL	0x26	/* disable rtc fails */
7562df1fe9cSrandyf #define	PT_ACPIREINIT	0x27	/* reinit apic */
7572df1fe9cSrandyf #define	PT_ACPIRESTORE	0x28	/* restore apic */
7582df1fe9cSrandyf #define	PT_INTRRESTORE	0x28	/* restore interrupts */
7592df1fe9cSrandyf #define	PT_RESDEV	0x2a	/* ressume acpi devices */
7602df1fe9cSrandyf #define	PT_CPU		0x2b	/* init_cpu_syscall */
7612df1fe9cSrandyf #define	PT_PRESUME	0x30	/* pm_resume entered */
7622df1fe9cSrandyf #define	PT_RSUS		0x31	/* pm_resume "suspended" */
7632df1fe9cSrandyf #define	PT_RKERN	0x32	/* pm_resume "kernel" */
7642df1fe9cSrandyf #define	PT_RDRV		0x33	/* pm_resume "driver" */
7652df1fe9cSrandyf #define	PT_RDRV_FAIL	0x34	/* pm_resume "driver" failed */
7662df1fe9cSrandyf #define	PT_RRNOINVOL	0x35	/* pm_resume "reattach_noinvol" */
7672df1fe9cSrandyf #define	PT_RUSER	0x36	/* pm_resume "user" */
7682df1fe9cSrandyf #define	PT_RAPMSIG	0x37	/* pm_resume APM/SRN signal */
7692df1fe9cSrandyf #define	PT_RMPO		0x38	/* pm_resume "mp_online" */
7702df1fe9cSrandyf #define	PT_RDONE	0x39	/* pm_resume done */
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate extern void	pm_detaching(dev_info_t *);
7737c478bd9Sstevel@tonic-gate extern void	pm_detach_failed(dev_info_t *);
7747c478bd9Sstevel@tonic-gate extern int	pm_power(dev_info_t *, int, int);
7757c478bd9Sstevel@tonic-gate extern int	pm_unmanage(dev_info_t *);
7767c478bd9Sstevel@tonic-gate extern void	pm_rem_info(dev_info_t *);
7777c478bd9Sstevel@tonic-gate extern int	pm_get_norm_pwrs(dev_info_t *, int **, size_t *);
7787c478bd9Sstevel@tonic-gate extern dev_info_t *pm_name_to_dip(char *, int);
7797c478bd9Sstevel@tonic-gate extern int	pm_power_up(dev_info_t *, int, int, int, pm_info_t *);
7807c478bd9Sstevel@tonic-gate extern int	pm_default_idle_threshold;
7817c478bd9Sstevel@tonic-gate extern void	pm_set_device_threshold(dev_info_t *, int, int);
7827c478bd9Sstevel@tonic-gate extern int	pm_valid_power(dev_info_t *, int, int);
7833fe80ca4SDan Cross extern void	pm_lock_power(dev_info_t *);
7843fe80ca4SDan Cross extern void	pm_unlock_power(dev_info_t *);
7853fe80ca4SDan Cross extern int	pm_try_locking_power(dev_info_t *);
7863fe80ca4SDan Cross extern void	pm_lock_power_single(dev_info_t *);
7873fe80ca4SDan Cross extern void	pm_unlock_power_single(dev_info_t *);
7883fe80ca4SDan Cross extern int	pm_try_locking_power_single(dev_info_t *);
7897c478bd9Sstevel@tonic-gate extern int	pm_isbc(dev_info_t *dip);
7907c478bd9Sstevel@tonic-gate extern int	pm_isdirect(dev_info_t *dip);
7917c478bd9Sstevel@tonic-gate extern int	pm_ctlops(dev_info_t *d, dev_info_t *r, ddi_ctl_enum_t o,
7927c478bd9Sstevel@tonic-gate 			void *a, void *v);
7937c478bd9Sstevel@tonic-gate extern int	pm_noinvol_detached(char *);
7947c478bd9Sstevel@tonic-gate extern int	pm_init_child(dev_info_t *);
7957c478bd9Sstevel@tonic-gate extern int	pm_uninit_child(dev_info_t *);
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate extern int	pm_all_to_normal(dev_info_t *, pm_canblock_t);
7987c478bd9Sstevel@tonic-gate extern int	pm_set_power(dev_info_t *, int, int, int, pm_canblock_t, int,
7997c478bd9Sstevel@tonic-gate 			int *);
8007c478bd9Sstevel@tonic-gate extern void	pm_scan_init(dev_info_t *dip);
8017c478bd9Sstevel@tonic-gate extern void	pm_scan_fini(dev_info_t *dip);
8027c478bd9Sstevel@tonic-gate extern void	pm_scan_stop(dev_info_t *dip);
8037c478bd9Sstevel@tonic-gate extern int	pm_scan_stop_walk(dev_info_t *dip, void *);
8047c478bd9Sstevel@tonic-gate extern void	pm_scan(void *);
8057c478bd9Sstevel@tonic-gate extern time_t	pm_scan_dev(dev_info_t *dip);
8067c478bd9Sstevel@tonic-gate extern void	pm_rescan(void *);
8077c478bd9Sstevel@tonic-gate extern int	pm_rescan_walk(dev_info_t *, void *);
8087c478bd9Sstevel@tonic-gate extern void	pm_forget_power_level(dev_info_t *);
8097c478bd9Sstevel@tonic-gate extern int	pm_pre_config(dev_info_t *, char *);
8107c478bd9Sstevel@tonic-gate extern int	pm_pre_unconfig(dev_info_t *, int, int *, char *);
8117c478bd9Sstevel@tonic-gate extern void	pm_post_config(dev_info_t *, char *);
8127c478bd9Sstevel@tonic-gate extern void	pm_post_unconfig(dev_info_t *, int, char *);
8137c478bd9Sstevel@tonic-gate extern void	pm_pre_probe(dev_info_t *, pm_ppm_cookie_t *);
8147c478bd9Sstevel@tonic-gate extern void	pm_post_probe(pm_ppm_cookie_t *, int, int);
8157c478bd9Sstevel@tonic-gate extern void	pm_post_attach(pm_ppm_cookie_t *, int);
8167c478bd9Sstevel@tonic-gate extern void	pm_pre_attach(dev_info_t *, pm_ppm_cookie_t *,
8177c478bd9Sstevel@tonic-gate 			ddi_attach_cmd_t);
8187c478bd9Sstevel@tonic-gate extern void	pm_pre_detach(dev_info_t *, ddi_detach_cmd_t,
8197c478bd9Sstevel@tonic-gate 			pm_ppm_cookie_t *);
8207c478bd9Sstevel@tonic-gate extern void	pm_post_detach(pm_ppm_cookie_t *, int);
8217c478bd9Sstevel@tonic-gate extern int	pm_powerup(dev_info_t *);
8227c478bd9Sstevel@tonic-gate extern int	pm_all_at_normal(dev_info_t *);
8237c478bd9Sstevel@tonic-gate extern int	pm_busop_bus_power(dev_info_t *, void *,
8247c478bd9Sstevel@tonic-gate 		    pm_bus_power_op_t, void *, void *);
8257c478bd9Sstevel@tonic-gate extern void	pm_hold_power(dev_info_t *);
8267c478bd9Sstevel@tonic-gate extern void	pm_rele_power(dev_info_t *);
8277c478bd9Sstevel@tonic-gate extern void	pm_driver_removed(major_t);
8287c478bd9Sstevel@tonic-gate extern void	pm_borrow_lock(kthread_t *);
8297c478bd9Sstevel@tonic-gate extern void	pm_return_lock(void);
8307c478bd9Sstevel@tonic-gate extern int	pm_reattach_noinvol(void);
8317c478bd9Sstevel@tonic-gate extern void	pm_reattach_noinvol_fini();
8327c478bd9Sstevel@tonic-gate extern void	pm_restore_direct_levels(void);
8337c478bd9Sstevel@tonic-gate extern void	pm_save_direct_levels(void);
8347c478bd9Sstevel@tonic-gate extern void	pm_cfb_setup(const char *);
8357c478bd9Sstevel@tonic-gate extern void	pm_proceed(dev_info_t *, int, int, int);
8367c478bd9Sstevel@tonic-gate extern void	pm_get_timestamps(dev_info_t *, time_t *);
8377c478bd9Sstevel@tonic-gate extern void	pm_deregister_watcher(int, dev_info_t *);
8387c478bd9Sstevel@tonic-gate extern void	pm_dispatch_to_dep_thread(int, char *, char *, int, int *, int);
8397c478bd9Sstevel@tonic-gate extern int	e_pm_valid_comp(dev_info_t *, int, pm_component_t **);
8407c478bd9Sstevel@tonic-gate extern int	e_pm_valid_info(dev_info_t *, pm_info_t **);
8417c478bd9Sstevel@tonic-gate extern int	e_pm_valid_power(dev_info_t *, int, int);
8427c478bd9Sstevel@tonic-gate extern void	pm_init_locks(void);
8437c478bd9Sstevel@tonic-gate extern int	pm_register_ppm(int (*)(dev_info_t *), dev_info_t *);
8447c478bd9Sstevel@tonic-gate extern int	pm_is_cfb(dev_info_t *);
8457c478bd9Sstevel@tonic-gate #ifdef	DEBUG
8467c478bd9Sstevel@tonic-gate extern int	pm_cfb_is_up(void);
8477c478bd9Sstevel@tonic-gate #endif
8487c478bd9Sstevel@tonic-gate 
8492df1fe9cSrandyf #ifdef DIPLOCKDEBUG
8507c478bd9Sstevel@tonic-gate #define	PM_LOCK_DIP(dip)	{ PMD(PMD_LOCK, ("dip lock %s@%s(%s#%d) " \
8517c478bd9Sstevel@tonic-gate 				    "%s %d\n", PM_DEVICE(dip),		  \
852*d5ebc493SDan Cross 				    __FILE__, __LINE__))		  \
8537c478bd9Sstevel@tonic-gate 				    mutex_enter(&DEVI(dip)->devi_pm_lock); }
8547c478bd9Sstevel@tonic-gate #define	PM_UNLOCK_DIP(dip)	{ PMD(PMD_LOCK, ("dip unlock %s@%s(%s#%d) " \
8557c478bd9Sstevel@tonic-gate 				    "%s %d\n", PM_DEVICE(dip),		    \
8567c478bd9Sstevel@tonic-gate 				    __FILE__, __LINE__))		    \
8577c478bd9Sstevel@tonic-gate 				    mutex_exit(&DEVI(dip)->devi_pm_lock); }
8587c478bd9Sstevel@tonic-gate #else
8597c478bd9Sstevel@tonic-gate #define	PM_LOCK_DIP(dip)	mutex_enter(&DEVI(dip)->devi_pm_lock)
8607c478bd9Sstevel@tonic-gate #define	PM_UNLOCK_DIP(dip)	mutex_exit(&DEVI(dip)->devi_pm_lock)
8617c478bd9Sstevel@tonic-gate #endif
8627c478bd9Sstevel@tonic-gate 
8637c478bd9Sstevel@tonic-gate /*
8647c478bd9Sstevel@tonic-gate  * These are the same DEBUG or not
8657c478bd9Sstevel@tonic-gate  */
8667c478bd9Sstevel@tonic-gate #define	PM_LOCK_BUSY(dip)	mutex_enter(&DEVI(dip)->devi_pm_busy_lock)
8677c478bd9Sstevel@tonic-gate #define	PM_UNLOCK_BUSY(dip)	mutex_exit(&DEVI(dip)->devi_pm_busy_lock)
8683fe80ca4SDan Cross #define	PM_LOCK_POWER(dip)	pm_lock_power(dip)
8693fe80ca4SDan Cross #define	PM_UNLOCK_POWER(dip)	pm_unlock_power(dip)
8703fe80ca4SDan Cross #define	PM_TRY_LOCK_POWER(dip)	pm_try_locking_power(dip)
8717c478bd9Sstevel@tonic-gate #define	PM_IAM_LOCKING_DIP(dip)	(mutex_owned(&DEVI(dip)->devi_pm_lock))
8727c478bd9Sstevel@tonic-gate 
8737c478bd9Sstevel@tonic-gate #define	PM_DEFAULT_SYS_IDLENESS	1800	/* 30 minutes */
8747c478bd9Sstevel@tonic-gate 
8757c478bd9Sstevel@tonic-gate /*
8767c478bd9Sstevel@tonic-gate  * Codes put into the pr_retval field of pm_rsvp_t that tell pm_block()
8777c478bd9Sstevel@tonic-gate  * how to proceed
8787c478bd9Sstevel@tonic-gate  */
8797c478bd9Sstevel@tonic-gate #define	PMP_SUCCEED	0x1	/* return success, the process did it */
8807c478bd9Sstevel@tonic-gate #define	PMP_FAIL	0x2	/* return fail, process did something else */
8817c478bd9Sstevel@tonic-gate #define	PMP_RELEASE	0x3	/* let it go, the process has lost interest */
8827c478bd9Sstevel@tonic-gate 				/* also arg to pm_proceed to signal this */
8837c478bd9Sstevel@tonic-gate /*
8847c478bd9Sstevel@tonic-gate  * Values of "style" for e_pm_manage and pm_premanage
8857c478bd9Sstevel@tonic-gate  */
8867c478bd9Sstevel@tonic-gate #define	PM_STYLE_NEW		0
8877c478bd9Sstevel@tonic-gate #define	PM_STYLE_UNKNOWN	1
8887c478bd9Sstevel@tonic-gate 
8897c478bd9Sstevel@tonic-gate /*
8907c478bd9Sstevel@tonic-gate  * Arg passed to pm_proceed that results in PMP_SUCCEED or PMP_FAIL being set
8917c478bd9Sstevel@tonic-gate  * in pr_retval depending on what is pending
8927c478bd9Sstevel@tonic-gate  */
8937c478bd9Sstevel@tonic-gate #define	PMP_SETPOWER	0x4
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate #define	PM_MAX_CLONE	256
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate typedef struct pm_rsvp {
8987c478bd9Sstevel@tonic-gate 	dev_info_t	*pr_dip;
8997c478bd9Sstevel@tonic-gate 	int		pr_comp;
9007c478bd9Sstevel@tonic-gate 	int		pr_newlevel;
9017c478bd9Sstevel@tonic-gate 	int		pr_oldlevel;
9027c478bd9Sstevel@tonic-gate 	kcondvar_t	pr_cv;		/* a place to sleep */
9037c478bd9Sstevel@tonic-gate 	int		pr_retval;	/* what to do when you wake up */
9047c478bd9Sstevel@tonic-gate 	struct pm_rsvp	*pr_next;
9057c478bd9Sstevel@tonic-gate 	struct pm_rsvp	*pr_prev;
9067c478bd9Sstevel@tonic-gate } pm_rsvp_t;
9077c478bd9Sstevel@tonic-gate 
9087c478bd9Sstevel@tonic-gate typedef struct psce {	/* pm_state_change_entries */
9097c478bd9Sstevel@tonic-gate 	struct pm_state_change		*psce_first;
9107c478bd9Sstevel@tonic-gate 	struct pm_state_change		*psce_in;
9117c478bd9Sstevel@tonic-gate 	struct pm_state_change		*psce_out;
9127c478bd9Sstevel@tonic-gate 	struct pm_state_change		*psce_last;
9137c478bd9Sstevel@tonic-gate 	int				psce_overruns;
9147c478bd9Sstevel@tonic-gate 	int				psce_references;
9157c478bd9Sstevel@tonic-gate 	kmutex_t			psce_lock;
9167c478bd9Sstevel@tonic-gate } psce_t;
9177c478bd9Sstevel@tonic-gate 
9187c478bd9Sstevel@tonic-gate typedef struct pscc {			/* pm_state_change_control */
9197c478bd9Sstevel@tonic-gate 	int		pscc_clone;
9207c478bd9Sstevel@tonic-gate 	dev_info_t	*pscc_dip;
9217c478bd9Sstevel@tonic-gate 	psce_t		*pscc_entries;
9227c478bd9Sstevel@tonic-gate 	struct pscc	*pscc_next;
9237c478bd9Sstevel@tonic-gate 	struct pscc	*pscc_prev;
9247c478bd9Sstevel@tonic-gate } pscc_t;
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate #define	PSCCOUNT 128	/* number of state change entries kept per process */
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate /*
929da6c28aaSamw  * Struct used to track the existence of devices exporting the
9307c478bd9Sstevel@tonic-gate  * no-involuntary-power-cycles property, and remember things from their
9317c478bd9Sstevel@tonic-gate  * devinfo node for later attach.
9327c478bd9Sstevel@tonic-gate  */
9337c478bd9Sstevel@tonic-gate typedef struct pm_noinvol {
9347c478bd9Sstevel@tonic-gate 	struct pm_noinvol	*ni_next;
9357c478bd9Sstevel@tonic-gate 	char			*ni_path;
9367c478bd9Sstevel@tonic-gate 	major_t			ni_major;	/* for attaching at cpr time */
9377c478bd9Sstevel@tonic-gate 	uint_t			ni_flags;	/* selected PMC_* values */
9387c478bd9Sstevel@tonic-gate 	uint_t			ni_noinvolpm;	/* saved noinvolpm count */
9397c478bd9Sstevel@tonic-gate 	uint_t			ni_volpmd;	/* saved volpmd count */
9407c478bd9Sstevel@tonic-gate 	uint_t			ni_wasvolpmd;	/* was vol pm'd at detach */
9417c478bd9Sstevel@tonic-gate 	size_t			ni_size;
9427c478bd9Sstevel@tonic-gate 	int			ni_persistent;	/* still around */
9437c478bd9Sstevel@tonic-gate } pm_noinvol_t;
9447c478bd9Sstevel@tonic-gate 
9457c478bd9Sstevel@tonic-gate #define	PMID_IOCTIMER		0x1		/* pm_ioctl sets during timer */
9467c478bd9Sstevel@tonic-gate #define	PMID_CFBTIMER		0x2		/* cfb sets during timer */
9477c478bd9Sstevel@tonic-gate #define	PMID_IOCSCAN		0x4		/* pm_ioctl sets during scan */
9487c478bd9Sstevel@tonic-gate #define	PMID_CFBSCAN		0x8		/* cfb sets during scan */
9497c478bd9Sstevel@tonic-gate 
9507c478bd9Sstevel@tonic-gate #define	PMID_IOC		(PMID_IOCTIMER | PMID_IOCSCAN)
9517c478bd9Sstevel@tonic-gate #define	PMID_CFB		(PMID_CFBTIMER | PMID_CFBSCAN)
9527c478bd9Sstevel@tonic-gate #define	PMID_TIMERS		(PMID_IOCTIMER | PMID_CFBTIMER)
9537c478bd9Sstevel@tonic-gate #define	PMID_SCANS		(PMID_IOCSCAN | PMID_CFBSCAN)
9547c478bd9Sstevel@tonic-gate #define	PMID_SCANS_SHIFT	2
9557c478bd9Sstevel@tonic-gate #define	PMID_SET_SCANS(pmid)	(pmid) |= (((pmid) & PMID_TIMERS) <<	\
9567c478bd9Sstevel@tonic-gate 				    PMID_SCANS_SHIFT);
9577c478bd9Sstevel@tonic-gate #define	PMID_IS_IOC(pmid)	((pmid) & PMID_IOC)
9587c478bd9Sstevel@tonic-gate #define	PMID_IS_CFB(pmid, dip)	(((pmid) & PMID_CFB) &&			\
9597c478bd9Sstevel@tonic-gate 				    (DEVI(dip)->devi_pm_flags &		\
9607c478bd9Sstevel@tonic-gate 				    (PMC_DEF_THRESH | PMC_NEXDEF_THRESH)))
9617c478bd9Sstevel@tonic-gate #define	PM_IS_PID(dip)	(PMID_IS_IOC(PM_GET_PM_SCAN(dip)->ps_idle_down) || \
9627c478bd9Sstevel@tonic-gate 	PMID_IS_CFB(PM_GET_PM_SCAN(dip)->ps_idle_down, dip))
9637c478bd9Sstevel@tonic-gate #define	PM_IS_CFB(dip)		(DEVI(dip)->devi_pm_flags & PMC_CONSOLE_FB)
9647c478bd9Sstevel@tonic-gate #define	PM_KUC(dip)		(DEVI(dip)->devi_pm_kidsupcnt)
9657c478bd9Sstevel@tonic-gate #define	PM_CURPOWER(dip, comp)	cur_power(PM_CP(dip, comp))
9667c478bd9Sstevel@tonic-gate 
9677c478bd9Sstevel@tonic-gate #define	PM_WANTS_NOTIFICATION(dip)					\
9687c478bd9Sstevel@tonic-gate 	(DEVI(dip)->devi_pm_flags & PMC_WANTS_NOTIFY)
9697c478bd9Sstevel@tonic-gate 
9707c478bd9Sstevel@tonic-gate #define	PM_HAS_BUS_POWER(dip)						\
9717c478bd9Sstevel@tonic-gate 	((DEVI(dip)->devi_ops->devo_bus_ops != NULL) &&			\
9727c478bd9Sstevel@tonic-gate 	(DEVI(dip)->devi_ops->devo_bus_ops->busops_rev >= BUSO_REV_7) &&\
9737c478bd9Sstevel@tonic-gate 	(DEVI(dip)->devi_ops->devo_bus_ops->bus_power != NULL))
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate #define	PM_BUS_POWER_FUNC(dip)						\
9767c478bd9Sstevel@tonic-gate 	DEVI(dip)->devi_ops->devo_bus_ops->bus_power
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate /*
9797c478bd9Sstevel@tonic-gate  * Structure used to pass down sunpm's private data variables
9807c478bd9Sstevel@tonic-gate  * through the bus_power bus_op calls
9817c478bd9Sstevel@tonic-gate  */
9827c478bd9Sstevel@tonic-gate typedef struct pm_sp_misc {
9837c478bd9Sstevel@tonic-gate 	pm_canblock_t   pspm_canblock;
9847c478bd9Sstevel@tonic-gate 	int pspm_scan;
9857c478bd9Sstevel@tonic-gate 	int *pspm_errnop;
9867c478bd9Sstevel@tonic-gate 	int pspm_direction;
9877c478bd9Sstevel@tonic-gate } pm_sp_misc_t;
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate /*
9907c478bd9Sstevel@tonic-gate  * This structure is used in validating that the power level
9917c478bd9Sstevel@tonic-gate  * of the descendents are off, while a device is powered off.
9927c478bd9Sstevel@tonic-gate  */
9937c478bd9Sstevel@tonic-gate typedef struct pm_desc_pwrchk {
9947c478bd9Sstevel@tonic-gate 	dev_info_t *pdpc_dip;
9957c478bd9Sstevel@tonic-gate 	int pdpc_par_involved;
9967c478bd9Sstevel@tonic-gate } pm_desc_pwrchk_t;
9977c478bd9Sstevel@tonic-gate 
9987c478bd9Sstevel@tonic-gate 
9997c478bd9Sstevel@tonic-gate /*
10007c478bd9Sstevel@tonic-gate  * These defines are used by pm_trans_check() to calculate time.
10017c478bd9Sstevel@tonic-gate  * Mostly copied from "tzfile.h".
10027c478bd9Sstevel@tonic-gate  */
10037c478bd9Sstevel@tonic-gate #define	DC_SPY			(SECSPERDAY * DAYSPERNYEAR)
10047c478bd9Sstevel@tonic-gate #define	DC_SPW			(SECSPERDAY * DAYSPERWEEK)
10057c478bd9Sstevel@tonic-gate #define	DC_SPD			SECSPERDAY
10067c478bd9Sstevel@tonic-gate 
10077c478bd9Sstevel@tonic-gate #define	DC_SCSI_YEAR_LEN	4		/* YYYY */
10087c478bd9Sstevel@tonic-gate #define	DC_SCSI_WEEK_LEN	2		/* WW */
10097c478bd9Sstevel@tonic-gate #define	DC_SCSI_NPY		5		/* # power-cycle years */
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
10127c478bd9Sstevel@tonic-gate 
10137c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
10147c478bd9Sstevel@tonic-gate }
10157c478bd9Sstevel@tonic-gate #endif
10167c478bd9Sstevel@tonic-gate 
10177c478bd9Sstevel@tonic-gate #endif /* _SYS_EPM_H */
1018