14667Smh27603 /* 24667Smh27603 * CDDL HEADER START 34667Smh27603 * 44667Smh27603 * The contents of this file are subject to the terms of the 54667Smh27603 * Common Development and Distribution License (the "License"). 64667Smh27603 * You may not use this file except in compliance with the License. 74667Smh27603 * 84667Smh27603 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 94667Smh27603 * or http://www.opensolaris.org/os/licensing. 104667Smh27603 * See the License for the specific language governing permissions 114667Smh27603 * and limitations under the License. 124667Smh27603 * 134667Smh27603 * When distributing Covered Code, include this CDDL HEADER in each 144667Smh27603 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 154667Smh27603 * If applicable, add the following below this CDDL HEADER, with the 164667Smh27603 * fields enclosed by brackets "[]" replaced with your own identifying 174667Smh27603 * information: Portions Copyright [yyyy] [name of copyright owner] 184667Smh27603 * 194667Smh27603 * CDDL HEADER END 204667Smh27603 */ 214667Smh27603 /* 224667Smh27603 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 234667Smh27603 * Use is subject to license terms. 244667Smh27603 */ 254667Smh27603 264667Smh27603 #ifndef _SYS_PPMVAR_H 274667Smh27603 #define _SYS_PPMVAR_H 284667Smh27603 294667Smh27603 #pragma ident "%Z%%M% %I% %E% SMI" 304667Smh27603 314667Smh27603 #include <sys/epm.h> 324667Smh27603 #include <sys/sunldi.h> 334667Smh27603 344667Smh27603 #ifdef __cplusplus 354667Smh27603 extern "C" { 364667Smh27603 #endif 374667Smh27603 384667Smh27603 394667Smh27603 typedef struct ppm_unit { 404667Smh27603 dev_info_t *dip; /* node dev info */ 414667Smh27603 kmutex_t lock; /* global driver lock */ 424667Smh27603 uint_t states; /* driver states */ 434667Smh27603 timeout_id_t led_tid; /* timeout id for LED */ 444667Smh27603 } ppm_unit_t; 454667Smh27603 464667Smh27603 /* 474667Smh27603 * driver states 484667Smh27603 */ 494667Smh27603 #define PPM_STATE_SUSPENDED 0x1 /* driver is suspended */ 504667Smh27603 514667Smh27603 /* 524667Smh27603 * Check for domain operational 534667Smh27603 */ 544667Smh27603 #define PPM_DOMAIN_UP(domp) (!(domp->dflags & PPMD_OFFLINE)) 554667Smh27603 564667Smh27603 /* 574667Smh27603 * LED constants 584667Smh27603 */ 594667Smh27603 #define PPM_LED_PULSE (drv_usectohz(250000)) /* 0.25 seconds */ 604667Smh27603 #define PPM_LEDON_INTERVAL (1 * PPM_LED_PULSE) 614667Smh27603 #define PPM_LEDOFF_INTERVAL (8 * PPM_LED_PULSE) 624667Smh27603 #define PPM_LEDON 1 /* (s10) */ 634667Smh27603 #define PPM_LEDOFF 0 /* (s10) */ 644667Smh27603 654667Smh27603 /* 664667Smh27603 * internal form of "ppm.conf" data 674667Smh27603 */ 684667Smh27603 struct ppm_db { 694667Smh27603 struct ppm_db *next; 704667Smh27603 char *name; /* device name */ 714667Smh27603 int plen; /* strlen before wildcard(s10) */ 724667Smh27603 int wccnt; /* upto 2 '*' allowed */ 734667Smh27603 int wcpos[2]; /* '*' location in pathname */ 744667Smh27603 }; 754667Smh27603 typedef struct ppm_db ppm_db_t; 764667Smh27603 774667Smh27603 struct ppm_cdata { 784667Smh27603 char *name; /* property name */ 794667Smh27603 char **strings; /* string array */ 804667Smh27603 uint_t cnt; /* property count */ 814667Smh27603 }; 824667Smh27603 834667Smh27603 /* 844667Smh27603 * ppm device info 854667Smh27603 */ 864667Smh27603 struct ppm_dev { 874667Smh27603 struct ppm_dev *next; 884667Smh27603 struct ppm_domain *domp; 894667Smh27603 dev_info_t *dip; 904667Smh27603 char *path; /* OBP device pathname */ 914667Smh27603 int cmpt; /* component number */ 924667Smh27603 int rplvl; /* last requested power level */ 934667Smh27603 int level; /* actual current power level */ 944667Smh27603 int lowest; /* lowest power level for device */ 954667Smh27603 int highest; /* highest power level for device */ 964667Smh27603 uint_t flags; 974667Smh27603 }; 984667Smh27603 typedef struct ppm_dev ppm_dev_t; 994667Smh27603 1004667Smh27603 /* 1014667Smh27603 * ppm_dev.flags field 1024667Smh27603 */ 1034667Smh27603 #define PPMDEV_PCI66_D2 0x1 /* device support D2 at pci 66mhz */ 1044667Smh27603 #define PPMDEV_PCI_PROP_CLKPM 0x2 /* clock can be power managed */ 1054667Smh27603 #define PPM_PM_POWEROP 0x10 /* power level change, initiated */ 1064667Smh27603 /* from PM is in progress. */ 1074667Smh27603 #define PPM_PHC_WHILE_SET_POWER 0x20 /* power level of a device is */ 1084667Smh27603 /* changed through */ 1094667Smh27603 /* pm_power_has_changed path */ 1104667Smh27603 /* while power level change, */ 1114667Smh27603 /* initiated from PM is in */ 1124667Smh27603 /* progress. */ 1134667Smh27603 1144667Smh27603 1154667Smh27603 /* 1164667Smh27603 * per domain record of device _ever_ managed by ppm 1174667Smh27603 */ 1184667Smh27603 struct ppm_owned { 1194667Smh27603 struct ppm_owned *next; 1204667Smh27603 char *path; /* device pathname */ 1214667Smh27603 int initializing; /* initializing flag */ 1224667Smh27603 }; 1234667Smh27603 typedef struct ppm_owned ppm_owned_t; 1244667Smh27603 1254667Smh27603 1264667Smh27603 /* 1274667Smh27603 * domain control data structure - 1284667Smh27603 * when you need to do an op for a domain, look up the op in the 1294667Smh27603 * cmd member of the struct, and then perform the method on the 1304667Smh27603 * path using iowr cmd with the args specified in val or val and 1314667Smh27603 * mask or the speed index. 1324667Smh27603 */ 1334667Smh27603 struct ppm_dc { 1344667Smh27603 struct ppm_dc *next; 1354667Smh27603 ldi_handle_t lh; /* layered (ldi) handle */ 1364667Smh27603 char *path; /* control device prom pathname */ 1374667Smh27603 uint_t cmd; /* search key: op to be performed */ 138*5295Srandyf /* one of: PPMDC_CPU_NEXT */ 139*5295Srandyf /* PPMDC_CPU_GO, PPMDC_FET_ON, */ 140*5295Srandyf /* PPMDC_FET_OFF, PPMDC_LED_ON, */ 141*5295Srandyf /* PPMDC_LED_OFF, PPMDC_PCI_ON, */ 142*5295Srandyf /* PPMDC_ENTER_S3, PPMDC_PCI_OFF */ 143*5295Srandyf /* PPMDC_EXIT_S3 commands */ 1444667Smh27603 uint_t method; /* control method / union selector */ 1454667Smh27603 /* one of PPMDC_KIO, PPMDC_I2CKIO, */ 1464667Smh27603 /* PPMDC_CPUSPEEDKIO */ 1474667Smh27603 1484667Smh27603 union { 1494667Smh27603 /* In each sub struct in union, the first three fields */ 1504667Smh27603 /* must be .iord, .iowr and .val and in such order. */ 1514667Smh27603 /* The .method field above selects a union sub struct */ 1524667Smh27603 /* for a particular .cmd operation. */ 1534667Smh27603 /* The association between .method and .cmd is platform */ 1544667Smh27603 /* specific, therefore described in ppm.conf file. */ 1554667Smh27603 1564667Smh27603 /* PPMDC_KIO: simple KIO */ 1574667Smh27603 struct m_kio { 1584667Smh27603 uint_t iord; /* IOCTL read cmd */ 1594667Smh27603 uint_t iowr; /* IOCTL write cmd */ 1604667Smh27603 uint_t val; /* ioctl arg */ 1614667Smh27603 uint_t delay; /* total delay before this */ 1624667Smh27603 /* operation can be carried out */ 1634667Smh27603 uint_t post_delay; /* post delay, if any */ 1644667Smh27603 } kio; 1654667Smh27603 166*5295Srandyf #ifdef sun4u 1674667Smh27603 /* PPMDC_I2CKIO: KIO requires 'arg' as struct i2c_gpio */ 1684667Smh27603 /* (defined in i2c_client.h) */ 1694667Smh27603 struct m_i2ckio { 1704667Smh27603 uint_t iord; /* IOCTL read cmd */ 1714667Smh27603 uint_t iowr; /* IOCTL write cmd */ 1724667Smh27603 uint_t val; /* register content */ 1734667Smh27603 uint_t mask; /* mask to select relevant bits */ 1744667Smh27603 /* of register content */ 1754667Smh27603 uint_t delay; /* total delay before this */ 1764667Smh27603 /* operation can be carried out */ 1774667Smh27603 uint_t post_delay; /* post delay, if any */ 1784667Smh27603 } i2c; 179*5295Srandyf #endif 1804667Smh27603 1814667Smh27603 /* PPMDC_CPUSPEEDKIO, PPMDC_VCORE: cpu estar related */ 1824667Smh27603 /* simple KIO */ 1834667Smh27603 struct m_cpu { 1844667Smh27603 uint_t iord; /* IOCTL read cmd */ 1854667Smh27603 uint_t iowr; /* IOCTL write cmd */ 1864667Smh27603 int val; /* new register value */ 1874667Smh27603 uint_t speeds; /* number of speeds cpu supports */ 1884667Smh27603 uint_t delay; /* microseconds post op delay */ 1894667Smh27603 } cpu; 1904667Smh27603 } m_un; 1914667Smh27603 }; 1924667Smh27603 typedef struct ppm_dc ppm_dc_t; 1934667Smh27603 1944667Smh27603 /* 1954667Smh27603 * ppm_dc.cmd field - 1964667Smh27603 */ 1974667Smh27603 #define PPMDC_CPU_NEXT 2 1984667Smh27603 #define PPMDC_PRE_CHNG 3 1994667Smh27603 #define PPMDC_CPU_GO 4 2004667Smh27603 #define PPMDC_POST_CHNG 5 2014667Smh27603 #define PPMDC_FET_ON 6 2024667Smh27603 #define PPMDC_FET_OFF 7 2034667Smh27603 #define PPMDC_LED_ON 8 2044667Smh27603 #define PPMDC_LED_OFF 9 2054667Smh27603 #define PPMDC_CLK_ON 10 2064667Smh27603 #define PPMDC_CLK_OFF 11 2074667Smh27603 #define PPMDC_PRE_PWR_OFF 12 2084667Smh27603 #define PPMDC_PRE_PWR_ON 13 2094667Smh27603 #define PPMDC_POST_PWR_ON 14 2104667Smh27603 #define PPMDC_PWR_OFF 15 2114667Smh27603 #define PPMDC_PWR_ON 16 2124667Smh27603 #define PPMDC_RESET_OFF 17 2134667Smh27603 #define PPMDC_RESET_ON 18 214*5295Srandyf #define PPMDC_ENTER_S3 19 215*5295Srandyf #define PPMDC_EXIT_S3 20 2164667Smh27603 2174667Smh27603 /* 2184667Smh27603 * ppm_dc.method field - select union element 2194667Smh27603 */ 2204667Smh27603 #define PPMDC_KIO 1 /* simple ioctl with val as arg */ 2214667Smh27603 #define PPMDC_CPUSPEEDKIO 2 /* ioctl with speed index arg */ 2224667Smh27603 #define PPMDC_VCORE 3 /* CPU Vcore change operation */ 223*5295Srandyf #ifdef sun4u 2244667Smh27603 #define PPMDC_I2CKIO 4 /* ioctl with i2c_gpio_t as arg */ 225*5295Srandyf #endif 2264667Smh27603 2274667Smh27603 /* 2284667Smh27603 * devices that are powered by the same source 2294667Smh27603 * are grouped by this struct as a "power domain" 2304667Smh27603 */ 2314667Smh27603 struct ppm_domain { 2324667Smh27603 char *name; /* domain name */ 2334667Smh27603 int dflags; /* domain flags */ 2344667Smh27603 int pwr_cnt; /* number of powered up devices */ 2354667Smh27603 ppm_db_t *conflist; /* all devices from ppm.conf file */ 2364667Smh27603 ppm_dev_t *devlist; /* current attached devices */ 2374667Smh27603 char *propname; /* domain property name */ 2384667Smh27603 kmutex_t lock; /* domain lock */ 2394667Smh27603 int refcnt; /* domain lock ref count */ 2404667Smh27603 int model; /* pm model, CPU, FET or LED */ 2414667Smh27603 int status; /* domain specific status */ 2424667Smh27603 ppm_dc_t *dc; /* domain control method */ 2434667Smh27603 ppm_owned_t *owned; /* list of ever owned devices */ 2444667Smh27603 struct ppm_domain *next; /* a linked list */ 2454667Smh27603 clock_t last_off_time; /* last time domain was off */ 2464667Smh27603 2474667Smh27603 }; 2484667Smh27603 typedef struct ppm_domain ppm_domain_t; 2494667Smh27603 2504667Smh27603 2514667Smh27603 /* 2524667Smh27603 * ppm_domain.model field - 2534667Smh27603 */ 2544667Smh27603 #define PPMD_CPU 1 /* cpu PM model */ 2554667Smh27603 #define PPMD_FET 2 /* power FET pm model */ 2564667Smh27603 #define PPMD_LED 3 /* LED pm model */ 2574667Smh27603 #define PPMD_PCI 4 /* PCI pm model */ 2584667Smh27603 #define PPMD_PCI_PROP 5 /* PCI_PROP pm model */ 2594667Smh27603 #define PPMD_PCIE 6 /* PCI Express pm model */ 260*5295Srandyf #define PPMD_SX 7 /* ACPI Sx pm model */ 2614667Smh27603 2624667Smh27603 #define PPMD_IS_PCI(model) \ 2634667Smh27603 ((model) == PPMD_PCI || (model) == PPMD_PCI_PROP) 2644667Smh27603 2654667Smh27603 /* 2664667Smh27603 * ppm_domain.status field - 2674667Smh27603 */ 2684667Smh27603 #define PPMD_OFF 0x0 /* FET/LED/PCI clock: off */ 2694667Smh27603 #define PPMD_ON 0x1 /* FET/LED/PCI clock: on */ 2704667Smh27603 2714667Smh27603 /* 2724667Smh27603 * ppm_domain.dflags field - 2734667Smh27603 */ 2744667Smh27603 #define PPMD_LOCK_ONE 0x1 2754667Smh27603 #define PPMD_LOCK_ALL 0x4 2764667Smh27603 #define PPMD_PCI33MHZ 0x1000 /* 33mhz PCI slot */ 2774667Smh27603 #define PPMD_PCI66MHZ 0x2000 /* 66mhz PCI slot */ 2784667Smh27603 #define PPMD_INITCHILD_CLKON 0x4000 /* clk turned on in init_child */ 2794667Smh27603 #define PPMD_OFFLINE 0x10000 /* domain is not functional */ 2804667Smh27603 #define PPMD_CPU_READY 0x20000 /* CPU domain can process power call */ 2814667Smh27603 2824667Smh27603 struct ppm_domit { 2834667Smh27603 char *name; 2844667Smh27603 int model; 2854667Smh27603 int dflags; 2864667Smh27603 int status; 2874667Smh27603 }; 2884667Smh27603 extern struct ppm_domit ppm_domit_data[]; 2894667Smh27603 2904667Smh27603 /* 2914667Smh27603 * XXppm driver-specific routines called from common code (s10) 2924667Smh27603 */ 2934667Smh27603 struct ppm_funcs { 2944667Smh27603 void (*dev_init)(ppm_dev_t *); 2954667Smh27603 void (*dev_fini)(ppm_dev_t *); 2964667Smh27603 void (*iocset)(uint8_t); 2974667Smh27603 uint8_t (*iocget)(void); 2984667Smh27603 }; 2994667Smh27603 3004667Smh27603 extern ppm_domain_t *ppm_domain_p; 3014667Smh27603 extern void *ppm_statep; 3024667Smh27603 extern int ppm_inst; 3034667Smh27603 extern ppm_domain_t *ppm_domains[]; /* (s10) */ 3044667Smh27603 extern struct ppm_funcs ppmf; /* (s10) */ 3054667Smh27603 3064667Smh27603 extern void ppm_dev_init(ppm_dev_t *); 3074667Smh27603 extern void ppm_dev_fini(ppm_dev_t *); 3084667Smh27603 extern int ppm_create_db(dev_info_t *); 3094667Smh27603 extern int ppm_claim_dev(dev_info_t *); 3104667Smh27603 extern void ppm_rem_dev(dev_info_t *); 3114667Smh27603 extern ppm_dev_t *ppm_get_dev(dev_info_t *, ppm_domain_t *); 3124667Smh27603 extern void ppm_init_cb(dev_info_t *); 3134667Smh27603 extern int ppm_init_lyr(ppm_dc_t *, dev_info_t *); 3144667Smh27603 extern ppm_domain_t *ppm_lookup_dev(dev_info_t *); 3154667Smh27603 extern ppm_domain_t *ppm_lookup_domain(char *); 3164667Smh27603 extern ppm_dc_t *ppm_lookup_dc(ppm_domain_t *, int); 3174667Smh27603 extern ppm_dc_t *ppm_lookup_hndl(int, ppm_dc_t *); 3184667Smh27603 extern ppm_domain_t *ppm_get_domain_by_dev(const char *); 3194667Smh27603 extern boolean_t ppm_none_else_holds_power(ppm_domain_t *); 3204667Smh27603 extern ppm_owned_t *ppm_add_owned(dev_info_t *, ppm_domain_t *); 3214667Smh27603 extern void ppm_lock_one(ppm_dev_t *, power_req_t *, int *); 3224667Smh27603 extern void ppm_lock_all(ppm_domain_t *, power_req_t *, int *); 3234667Smh27603 extern boolean_t ppm_manage_early_cpus(dev_info_t *, int, int *); 3244667Smh27603 extern int ppm_change_cpu_power(ppm_dev_t *, int); 3254667Smh27603 extern int ppm_revert_cpu_power(ppm_dev_t *, int); 3264667Smh27603 extern ppm_dev_t *ppm_add_dev(dev_info_t *, ppm_domain_t *); 3274667Smh27603 3284667Smh27603 #define PPM_GET_PRIVATE(dip) \ 3294667Smh27603 DEVI(dip)->devi_pm_ppm_private 3304667Smh27603 #define PPM_SET_PRIVATE(dip, datap) \ 3314667Smh27603 DEVI(dip)->devi_pm_ppm_private = datap 3324667Smh27603 3334667Smh27603 #define PPM_LOCK_DOMAIN(domp) { \ 3344667Smh27603 if (!MUTEX_HELD(&(domp)->lock)) \ 3354667Smh27603 mutex_enter(&(domp)->lock); \ 3364667Smh27603 (domp)->refcnt++; \ 3374667Smh27603 } 3384667Smh27603 3394667Smh27603 #define PPM_UNLOCK_DOMAIN(domp) { \ 3404667Smh27603 ASSERT(MUTEX_HELD(&(domp)->lock) && \ 3414667Smh27603 (domp)->refcnt > 0); \ 3424667Smh27603 if (--(domp)->refcnt == 0) \ 3434667Smh27603 mutex_exit(&(domp)->lock); \ 3444667Smh27603 } 3454667Smh27603 3464667Smh27603 /* 3474667Smh27603 * debug support 3484667Smh27603 */ 3494667Smh27603 #ifdef DEBUG 3504667Smh27603 #include <sys/promif.h> 3514667Smh27603 3524667Smh27603 extern char *ppm_get_ctlstr(int, uint_t); 3534667Smh27603 extern void ppm_print_dc(struct ppm_dc *); 3544667Smh27603 3554667Smh27603 extern uint_t ppm_debug; 3564667Smh27603 3574667Smh27603 #define D_CREATEDB 0x00000001 3584667Smh27603 #define D_CLAIMDEV 0x00000002 3594667Smh27603 #define D_ADDDEV 0x00000004 3604667Smh27603 #define D_REMDEV 0x00000008 3614667Smh27603 #define D_LOWEST 0x00000010 3624667Smh27603 #define D_SETLVL 0x00000020 3634667Smh27603 #define D_GPIO 0x00000040 3644667Smh27603 #define D_CPU 0x00000080 3654667Smh27603 #define D_FET 0x00000100 3664667Smh27603 #define D_PCIUPA 0x00000200 3674667Smh27603 #define D_1394 0x00000400 3684667Smh27603 #define D_CTLOPS1 0x00000800 3694667Smh27603 #define D_CTLOPS2 0x00001000 3704667Smh27603 #define D_SOME 0x00002000 3714667Smh27603 #define D_LOCKS 0x00004000 3724667Smh27603 #define D_IOCTL 0x00008000 3734667Smh27603 #define D_ATTACH 0x00010000 3744667Smh27603 #define D_DETACH 0x00020000 3754667Smh27603 #define D_OPEN 0x00040000 3764667Smh27603 #define D_CLOSE 0x00080000 3774667Smh27603 #define D_INIT 0x00100000 3784667Smh27603 #define D_FINI 0x00200000 3794667Smh27603 #define D_ERROR 0x00400000 3804667Smh27603 #define D_SETPWR 0x00800000 3814667Smh27603 #define D_LED 0x01000000 3824667Smh27603 #define D_PCI 0x02000000 3834667Smh27603 #define D_PPMDC 0x04000000 3844667Smh27603 #define D_CPR 0x08000000 3854667Smh27603 3864667Smh27603 #define PPMD(level, arglist) { \ 3874667Smh27603 if (ppm_debug & (level)) { \ 3884667Smh27603 pm_log arglist; \ 3894667Smh27603 } \ 3904667Smh27603 } 3914667Smh27603 /* (s10) */ 3924667Smh27603 #define DPRINTF PPMD 3934667Smh27603 3944667Smh27603 #else /* DEBUG */ 3954667Smh27603 #define PPMD(level, arglist) 3964667Smh27603 #define DPRINTF(flag, args) /* (s10) */ 3974667Smh27603 #endif /* DEBUG */ 3984667Smh27603 3994667Smh27603 #ifdef __cplusplus 4004667Smh27603 } 4014667Smh27603 #endif 4024667Smh27603 4034667Smh27603 #endif /* _SYS_PPMVAR_H */ 404