1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_EPM_H 28 #define _SYS_EPM_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <sys/pm.h> 33 #include <sys/dditypes.h> 34 #include <sys/devops.h> 35 #include <sys/ddi_impldefs.h> 36 #include <sys/taskq.h> 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #ifdef _KERNEL 43 44 /* 45 * epm.h: Function prototypes and data structs for kernel pm functions. 46 */ 47 48 void e_pm_props(dev_info_t *); 49 int e_new_pm_props(dev_info_t *); 50 51 #define PM_LEVEL_UPONLY (-2) /* only raise power level */ 52 #define PM_LEVEL_DOWNONLY (-3) /* only lower power level */ 53 #define PM_LEVEL_EXACT (-4) /* wants exact power level */ 54 55 /* 56 * Values used by e_pm_props and friends, found in devi_pm_flags 57 */ 58 #define PMC_NEEDS_SR 0x00001 /* do suspend/resume despite no "reg" */ 59 #define PMC_NO_SR 0x00002 /* don't suspend/resume despite "reg" */ 60 #define PMC_PARENTAL_SR 0x00004 /* call up tree to suspend/resume */ 61 #define PMC_WANTS_NOTIFY 0x00008 /* notify if child pwr level changes */ 62 #define PMC_BC 0x00010 /* no pm-components, backwards compat */ 63 #define PMC_COMPONENTS_DONE 0x00020 /* parsed pm-components */ 64 #define PMC_COMPONENTS_FAILED 0x00040 /* failed parsing pm-components */ 65 #define PMC_SUSPENDED 0x00080 /* device has been suspended */ 66 #define PMC_DEF_THRESH 0x00100 /* thresholds are default */ 67 #define PMC_DEV_THRESH 0x00200 /* SET_THRESHOLD ioctl seen */ 68 #define PMC_COMP_THRESH 0x00400 /* relative threshold set */ 69 #define PMC_NEXDEF_THRESH 0x00800 /* relative threshold set for nexus */ 70 #define PMC_NOPMKID 0x01000 /* non-pm'd child of pm'd parent */ 71 #define PMC_NO_INVOL 0x02000 /* no pm without driver's consent */ 72 #define PMC_VOLPMD 0x04000 /* went down voluntarily */ 73 #define PMC_SKIP_BRINGUP 0x08000 /* Skipped a dependency bringup */ 74 75 /* 76 * A node which is the console frame buffer, and should not be powered down 77 * automatically because the OBP driver doesn't know how to power it back up 78 * before using it (can remove this when prom calls back into kernel to do 79 * io to console). 80 */ 81 #define PMC_CONSOLE_FB 0x10000 /* console framebuffer */ 82 #define PMC_NOINVOL_DONE 0x20000 /* processed by pm_noinvol_specd() */ 83 #define PMC_DRIVER_REMOVED 0x40000 /* driver is removed */ 84 85 #define PMC_THRESH_ALL (PMC_DEF_THRESH | PMC_DEV_THRESH | \ 86 PMC_COMP_THRESH | PMC_NEXDEF_THRESH) 87 #define PMC_THRESH_NONE ~(PMC_THRESH_ALL) 88 89 /* Flags for the component */ 90 #define PM_POWER_OP 0x00001 /* set power in process */ 91 #define PM_PHC_WHILE_SET_POWER 0x00002 /* phc and set power deadlock */ 92 93 /* 94 * One of these is attached to each devinfo that is autopm'd. 95 */ 96 typedef struct pm_scan { 97 int ps_idle_down; /* PMID_XXX flags */ 98 int ps_scan_flags; /* scan flags, defined below */ 99 timeout_id_t ps_scan_id; /* per dip scan timeout id */ 100 } pm_scan_t; 101 102 /* 103 * ps_scan_flags may take the following values, plus possibly 104 * more defined. 105 */ 106 #define PM_SCANNING 0x100 /* scanning: pm_scan_dev is active */ 107 #define PM_SCAN_AGAIN 0x200 108 #define PM_SCAN_STOP 0x400 109 #define PM_SCAN_DISPATCHED 0x800 110 111 #define PM_MIN_SCAN ((clock_t)15) /* Minimum scan interval in seconds */ 112 113 /* 114 * Power management component definitions, used for tracking idleness of 115 * devices. An array of these hangs off the devi_pm_components member of the 116 * dev_info struct (if initialized by driver and/or auto-pm) 117 * The array of these structs is followed in the same kmem_zalloc'd chunk by 118 * the names pointed to by the structs. 119 */ 120 121 /* 122 * This (sub-)struct contains all the info extracted from the pm-components 123 * property for each component (name of component, names and values of power 124 * levels supported). It is in a separate structure to allow it to be handled 125 * as a struct assignment. 126 */ 127 typedef struct pm_comp { 128 char *pmc_name; /* name of component */ 129 int pmc_numlevels; /* number of power levels supported */ 130 int *pmc_lvals; /* numerical values of levels */ 131 int *pmc_thresh; /* thresholds in secs, last INT_MAX */ 132 char **pmc_lnames; /* human readable names of levels */ 133 /* 134 * This part is just bookkeeping for the storage space involved above 135 * used for copying and freeing the struct members. This because C 136 * is really an assembler at heart. 137 */ 138 size_t pmc_name_sz; /* size of name string */ 139 char *pmc_lname_buf; /* buffer holding *pmc_lnames */ 140 size_t pmc_lnames_sz; /* total size of pmc_lname_buf */ 141 } pm_comp_t; 142 143 /* 144 * Here we have the rest of what we need to know about a component. 145 */ 146 typedef struct pm_component { 147 uint_t pmc_flags; /* flags this component */ 148 uint_t pmc_busycount; /* for nesting busy calls */ 149 time_t pmc_timestamp; /* timestamp */ 150 uint_t pmc_norm_pwr; /* normal power index (or value) */ 151 int pmc_cur_pwr; /* current power index (or value) */ 152 int pmc_phc_pwr; /* prev. value of curpwr (deadlock) */ 153 pm_comp_t pmc_comp; /* component description */ 154 } pm_component_t; 155 156 /* 157 * All members of this struct are protected by PM_LOCK_DIP(dip). 158 * 159 * kidsupcnt counts (the number of components of new-style children at non-zero 160 * level (unknown counts as non-zero)) + (the number of old-style children with 161 * component 0 at non-zero level) for parents that have not asked for 162 * notifcation. When kidsupcnt is 0 for a nexus node, then pm scans it, 163 * otherwise it leaves it alone. 164 * Parents that ask for notification always get get scanned, 165 * so we keep their kidsupcnt at zero. 166 */ 167 typedef struct pm_info { 168 uint_t pmi_dev_pm_state; /* PM state of a device */ 169 int pmi_clone; /* owner for direct pm'd devs */ 170 int pmi_levels[2]; /* storage space for 2 levels */ 171 int *pmi_lp; /* storage space for >2 levels */ 172 kcondvar_t pmi_cv; /* condvar for direct PM access */ 173 } pm_info_t; 174 175 /* 176 * Work request structure for the dependency processing thread. 177 */ 178 typedef struct pm_dep_wk { 179 int pdw_type; /* Type of request */ 180 int pdw_wait; /* caller waits for result */ 181 int pdw_done; /* set when req is done */ 182 int pdw_ret; /* return value to caller */ 183 int pdw_pwr; /* pwr level of keeper */ 184 kcondvar_t pdw_cv; /* cv to wake up caller */ 185 struct pm_dep_wk *pdw_next; /* next element */ 186 char *pdw_keeper; 187 char *pdw_kept; 188 } pm_dep_wk_t; 189 190 /* 191 * Types of work, depends on when it gets called: 192 */ 193 #define PM_DEP_WK_POWER_ON 1 /* power on */ 194 #define PM_DEP_WK_POWER_OFF 2 /* power off */ 195 #define PM_DEP_WK_DETACH 3 /* detach */ 196 #define PM_DEP_WK_REMOVE_DEP 4 /* dependency removed */ 197 #define PM_DEP_WK_BRINGUP_SELF 5 /* released from direct PM */ 198 #define PM_DEP_WK_RECORD_KEEPER 6 /* PM_ADD_DEPENDENT */ 199 #define PM_DEP_WK_RECORD_KEEPER_PROP 7 /* PM_ADD_DEPENDENT_PROP */ 200 #define PM_DEP_WK_KEPT 8 /* dep. work as a kept */ 201 #define PM_DEP_WK_KEEPER 9 /* dep. work as a keeper */ 202 #define PM_DEP_WK_ATTACH 10 /* when dip is attached */ 203 #define PM_DEP_WK_CHECK_KEPT 11 /* check if this is a kept */ 204 #define PM_DEP_WK_CPR_SUSPEND 12 /* Suspend dep. during CPR */ 205 #define PM_DEP_WK_CPR_RESUME 13 /* Resume dep. after CPR */ 206 207 /* 208 * Wait for dependency work to finish or not. 209 */ 210 #define PM_DEP_WAIT 1 211 #define PM_DEP_NOWAIT 0 212 213 typedef enum pm_canblock 214 { 215 PM_CANBLOCK_BLOCK, /* wait for controlling process action */ 216 PM_CANBLOCK_FAIL, /* don't wait, fail request */ 217 PM_CANBLOCK_BYPASS /* don't wait, ignore controlling process */ 218 } pm_canblock_t; 219 220 /* 221 * The power request struct uses for the DDI_CTLOPS_POWER busctl. 222 * 223 * Note: When changing this enum it is necessary to maintain binary 224 * compatibility with older versions. To insure that, add new values only 225 * at the end and refrain from deleting any existing values. 226 */ 227 typedef enum { 228 PMR_SET_POWER = 1, /* called ddi_power (obsolete) */ 229 PMR_SUSPEND, /* parental suspend */ 230 PMR_RESUME, /* parental resume */ 231 PMR_PRE_SET_POWER, /* parent's "pre" notification */ 232 PMR_POST_SET_POWER, /* parent's "post" notification */ 233 PMR_PPM_SET_POWER, /* platform pm set power */ 234 PMR_PPM_ATTACH, /* ppm attach notify - unused */ 235 PMR_PPM_DETACH, /* ppm detach notify - unused */ 236 PMR_PPM_POWER_CHANGE_NOTIFY, /* ppm level change notify */ 237 PMR_REPORT_PMCAP, /* report pm capability */ 238 PMR_CHANGED_POWER, /* parent's power_has_changed notif. */ 239 PMR_PPM_PRE_PROBE, /* ppm pre probe notify */ 240 PMR_PPM_POST_PROBE, /* ppm post probe notify */ 241 PMR_PPM_PRE_ATTACH, /* ppm pre attach notify */ 242 PMR_PPM_POST_ATTACH, /* ppm post pm attach notify */ 243 PMR_PPM_PRE_DETACH, /* ppm pre pm detach notify */ 244 PMR_PPM_POST_DETACH, /* ppm post pm detach notify */ 245 PMR_PPM_UNMANAGE, /* device being unmanaged */ 246 PMR_PPM_PRE_RESUME, /* ppm resume notify */ 247 PMR_PPM_ALL_LOWEST, /* ppm all lowest power notify */ 248 PMR_PPM_LOCK_POWER, /* ppm lock power */ 249 PMR_PPM_UNLOCK_POWER, /* ppm unlock power */ 250 PMR_PPM_TRY_LOCK_POWER, /* ppm try lock power */ 251 PMR_PPM_INIT_CHILD, /* ppm init child notify */ 252 PMR_PPM_UNINIT_CHILD, /* ppm uninit child notify */ 253 PMR_PPM_POWER_LOCK_OWNER /* ppm power lock owner's address */ 254 } pm_request_type; 255 256 /* 257 * When changing the elements of the union below it is necessary to 258 * maintain binary compatibility with older versions. Refrain from 259 * deleting existing elements of the union or modifying their contents. 260 * Avoid increasing the total size of this structure if new elements 261 * must be added. 262 */ 263 typedef struct power_req { 264 pm_request_type request_type; 265 union req { 266 /* 267 * PMR_SET_POWER (obsolete) 268 */ 269 struct set_power_req { 270 dev_info_t *who; 271 int cmpt; 272 int level; 273 } set_power_req; 274 /* 275 * PMR_SUSPEND 276 */ 277 struct suspend_req { 278 dev_info_t *who; 279 ddi_detach_cmd_t cmd; 280 } suspend_req; 281 /* 282 * PMR_PPM_PRE_RESUME or PMR_RESUME 283 */ 284 struct resume_req { 285 dev_info_t *who; 286 ddi_attach_cmd_t cmd; 287 } resume_req; 288 /* 289 * PMR_PRE_SET_POWER 290 */ 291 struct pre_set_power_req { 292 dev_info_t *who; 293 int cmpt; 294 int old_level; 295 int new_level; 296 } pre_set_power_req; 297 /* 298 * PMR_POST_SET_POWER 299 */ 300 struct post_set_power_req { 301 dev_info_t *who; 302 int cmpt; 303 int old_level; 304 int new_level; 305 int result; /* driver's return */ 306 } post_set_power_req; 307 /* 308 * PMR_PPM_SET_POWER 309 */ 310 struct ppm_set_power_req { 311 dev_info_t *who; 312 int cmpt; 313 int old_level; 314 int new_level; 315 pm_canblock_t canblock; 316 void *cookie; 317 } ppm_set_power_req; 318 /* 319 * PMR_PPM_POWER_CHANGE_NOTIFY 320 */ 321 struct ppm_notify_level_req { 322 dev_info_t *who; 323 int cmpt; 324 int old_level; 325 int new_level; 326 } ppm_notify_level_req; 327 /* 328 * PMR_REPORT_PMCAP 329 */ 330 struct report_pmcap_req { 331 dev_info_t *who; 332 int cap; 333 void *arg; 334 } report_pmcap_req; 335 /* 336 * PMR_CHANGED_POWER 337 */ 338 struct changed_power_req { 339 dev_info_t *who; 340 int cmpt; 341 int old_level; 342 int new_level; 343 int result; 344 } changed_power_req; 345 /* 346 * PMR_PPM_PRE_PROBE, PMR_PPM_POST_PROBE, PMR_PPM_PRE_ATTACH, 347 * PMR_PPM_POST_ATTACH, PMR_PPM_PRE_DETACH, PMR_PPM_POST_DETACH 348 * PMR_PPM_INIT_CHILD, PMR_PPM_UNINIT_CHILD, or PMR_PPM_UNMANAGE 349 */ 350 struct ppm_config_req { 351 dev_info_t *who; 352 int result; /* post only */ 353 } ppm_config_req; 354 /* 355 * PMR_PPM_ALL_LOWEST 356 */ 357 struct ppm_all_lowest_req { 358 int mode; 359 } ppm_all_lowest_req; 360 /* 361 * PMR_PPM_LOCK_POWER, PMR_PPM_TRY_LOCK_POWER 362 */ 363 struct ppm_lock_power_req { 364 dev_info_t *who; 365 int *circp; 366 } ppm_lock_power_req; 367 /* 368 * PMR_PPM_UNLOCK_POWER 369 */ 370 struct ppm_unlock_power_req { 371 dev_info_t *who; 372 int circ; 373 } ppm_unlock_power_req; 374 /* 375 * PMR_PPM_POWER_LOCK_OWNER 376 */ 377 struct ppm_power_lock_owner_req { 378 dev_info_t *who; 379 kthread_t *owner; 380 } ppm_power_lock_owner_req; 381 } req; 382 } power_req_t; 383 384 /* 385 * Structure used by the following bus_power operations: 386 * 387 * BUS_POWER_PRE_NOTIFICATION 388 * BUS_POWER_POST_NOTIFICATION 389 * BUS_POWER_CHILD_PWRCHG 390 */ 391 typedef struct pm_bp_child_pwrchg { 392 dev_info_t *bpc_dip; /* dip of the target device */ 393 char *bpc_path; /* path to the target device */ 394 int bpc_comp; /* component changing power */ 395 int bpc_olevel; /* old power level */ 396 int bpc_nlevel; /* new power level */ 397 void *bpc_private; /* PM framework private */ 398 } pm_bp_child_pwrchg_t; 399 400 /* 401 * Structure used by the BUS_POWER_NEXUS_PWRUP operation 402 */ 403 typedef struct pm_bp_nexus_pwrup { 404 dev_info_t *bpn_dip; /* dip of the nexus device */ 405 int bpn_comp; /* component powering up */ 406 int bpn_level; /* new power level */ 407 void *bpn_private; /* PM framework private */ 408 } pm_bp_nexus_pwrup_t; 409 410 /* 411 * Structure used by the BUS_POWER_HAS_CHANGED operation 412 */ 413 typedef struct pm_bp_has_changed { 414 dev_info_t *bphc_dip; /* dip of the target device */ 415 char *bphc_path; /* path to the target device */ 416 int bphc_comp; /* component changing power */ 417 int bphc_olevel; /* old power level */ 418 int bphc_nlevel; /* new power level */ 419 void *bphc_private; /* PM framework private */ 420 } pm_bp_has_changed_t; 421 422 /* 423 * Commands indicating which activity is requiring an 424 * update to the noinvol counters. 425 */ 426 #define PM_BP_NOINVOL_ATTACH 1 427 #define PM_BP_NOINVOL_DETACH 2 428 #define PM_BP_NOINVOL_REMDRV 3 429 #define PM_BP_NOINVOL_CFB 4 430 #define PM_BP_NOINVOL_POWER 5 431 432 /* 433 * Structure used by the BUS_POWER_NOINVOL operation. 434 */ 435 typedef struct pm_bp_noinvol { 436 dev_info_t *bpni_dip; /* dip of the target device */ 437 char *bpni_path; /* path to the target device */ 438 int bpni_cmd; /* how to update the counters */ 439 int bpni_volpmd; /* volpmd of target device */ 440 int bpni_wasvolpmd; /* whether to update volpmd */ 441 void *bpni_private; /* PM framework private */ 442 } pm_bp_noinvol_t; 443 444 /* 445 * This struct is used by the code that makes a PMR_PPM_SET_POWER request 446 * to ppm. Devices that changed power other than the primary device (which 447 * was requested) are passed back to the pm framework through this 448 * structure. 449 */ 450 typedef struct pm_ppm_devlist { 451 dev_info_t *ppd_who; 452 int ppd_cmpt; 453 int ppd_old_level; 454 int ppd_new_level; 455 struct pm_ppm_devlist *ppd_next; 456 } pm_ppm_devlist_t; 457 458 /* 459 * This struct is used by the code that brings up parents and notifies 460 * ppm drivers across probe/attach/detach (pm_pre/post_probe/attach/detach()) 461 */ 462 typedef struct pm_ppm_cookie { 463 dev_info_t *ppc_dip; /* dip of target node */ 464 dev_info_t *ppc_pdip; /* parent's dip */ 465 dev_info_t *ppc_ppm; /* interested ppm driver */ 466 int ppc_cmd; /* attach/detach cmd */ 467 } pm_ppm_cookie_t; 468 469 /* 470 * This struct records one dependency (a device keeps another or others up) 471 * pdr_size includes size of strings. 472 */ 473 typedef struct pm_dep_rec { 474 char *pdr_keeper; /* physpath of device keeping up */ 475 char *pdr_kept; /* physpath or property name */ 476 char **pdr_kept_paths; /* array of kept devices' paths */ 477 struct pm_dep_rec *pdr_next; /* next dependency device */ 478 size_t pdr_size; /* size to kmem_free */ 479 major_t pdr_major; /* major of kept driver (not props) */ 480 int pdr_isprop; /* true if kept is property name */ 481 int pdr_kept_count; /* how many kept altogether */ 482 int pdr_satisfied; /* true if in force (not properties) */ 483 } pm_pdr_t; 484 485 486 /* 487 * This struct records threshold information about a single component 488 */ 489 typedef struct pm_thresh_entry { 490 int pte_numthresh; 491 int *pte_thresh; 492 } pm_pte_t; 493 494 /* 495 * Note that this header and its array of entry structs with their arrays 496 * of thresholds and string storage for physpath are all kmem_alloced in one 497 * chunk for easy freeing ptr_size is the size of that chunk 498 */ 499 typedef struct pm_thresh_rec { 500 char *ptr_physpath; /* identifies node */ 501 struct pm_thresh_rec *ptr_next; 502 int ptr_numcomps; /* number of components */ 503 size_t ptr_size; /* total size for kmem_free */ 504 pm_pte_t *ptr_entries; 505 } pm_thresh_rec_t; 506 507 /* 508 * pmi_dev_pm_state state bits: 509 */ 510 511 /* 512 * a direct-pm device, not scanned, but controlled by a process 513 */ 514 #define PM_DIRECT 0x1 515 /* 516 * autopm is suspended while waiting to see if detach succeeds 517 */ 518 #define PM_DETACHING 0x2 519 520 /* 521 * An all_to_normal operation for an autopm device that is detaching, is 522 * deferred in case the detach fails. 523 */ 524 #define PM_ALLNORM_DEFERRED 0x4 525 526 #define PM_GET_PM_INFO(dip) (DEVI(dip)->devi_pm_info) 527 #define PM_GET_PM_SCAN(dip) (DEVI(dip)->devi_pm_scan) 528 529 #define PM_NUMCMPTS(dip) (DEVI(dip)->devi_pm_num_components) 530 #define PM_CP(dip, comp) (&DEVI(dip)->devi_pm_components[comp]) 531 532 /* 533 * Returns true if the device specified by dip is directly power managed 534 */ 535 #define PM_ISDIRECT(dip) \ 536 (((pm_info_t *)PM_GET_PM_INFO(dip))->pmi_dev_pm_state & PM_DIRECT) 537 538 /* 539 * Returns true if the device specified by dip is an old node for which we 540 * provide backwards compatible behavior (e.g. no pm-components property). 541 */ 542 #define PM_ISBC(dip) (DEVI(dip)->devi_pm_flags & PMC_BC) 543 544 /* 545 * Returns true if we have skipped a dependency bringup on this dip. 546 */ 547 #define PM_SKBU(dip) (DEVI(dip)->devi_pm_flags & PMC_SKIP_BRINGUP) 548 549 #define PM_NOT_ALL_LOWEST 0x0 /* not all components are at lowest */ 550 #define PM_ALL_LOWEST 0x1 /* all components are at lowest lvl */ 551 552 #define PM_ADDR(dip) (ddi_get_name_addr(dip) ? ddi_get_name_addr(dip) : "") 553 #define PM_NAME(dip) (ddi_binding_name(dip)) 554 #define PM_NODE(dip) (ddi_node_name(dip)) 555 #define PM_INST(dip) (ddi_get_instance(dip)) 556 #define PM_DEVICE(dip) PM_NAME(dip), PM_ADDR(dip), PM_NODE(dip), PM_INST(dip) 557 558 #ifdef DEBUG 559 /* 560 * Flags passed to PMD to enable debug printfs. If the same flag is set in 561 * pm_debug below then the message is printed. The most generally useful 562 * ones are the first 3 or 4. 563 */ 564 #define PMD_ERROR 0x0000001 565 #define PMD_FAIL 0x0000002 566 #define PMD_IOCTL 0x0000004 567 #define PMD_SCAN 0x0000008 568 #define PMD_RESCAN 0x0000010 569 #define PMD_REMINFO 0x0000020 570 #define PMD_NAMETODIP 0x0000040 571 #define PMD_CLOSE 0x0000080 572 #define PMD_DIN 0x0000100 /* Dev Is Needed */ 573 #define PMD_PMC 0x0000200 /* for testing with sun4m pmc driver */ 574 #define PMD_PPM 0x0000400 575 #define PMD_DEP 0x0000800 /* dependency processing */ 576 #define PMD_IDLEDOWN 0x0001000 577 #define PMD_SET 0x0002000 578 #define PMD_BRING 0x0004000 579 #define PMD_ALLNORM 0x0008000 580 #define PMD_REMDEV 0x0010000 581 #define PMD_LEVEL 0x0020000 582 #define PMD_THRESH 0x0040000 583 #define PMD_DPM 0x0080000 /* Direct Power Management */ 584 #define PMD_NORM 0x0100000 585 #define PMD_STATS 0x0200000 586 #define PMD_DEREG 0x0400000 587 #define PMD_KEEPS 0x0800000 588 #define PMD_KIDSUP 0x1000000 589 #define PMD_TCHECK 0x2000000 590 #define PMD_NOINVOL 0x4000000 591 #define PMD_CFB 0x8000000 /* console fb pm */ 592 #define PMD_DHR 0x10000000 /* driver hold/rele changes */ 593 #define PMD_PIL 0x20000000 /* print out PIL when calling power */ 594 #define PMD_PHC 0x40000000 /* pm_power_has_changed messages */ 595 #define PMD_LOCK 0x80000000 596 597 extern uint_t pm_debug; 598 extern uint_t pm_divertdebug; 599 /*PRINTFLIKE1*/ 600 extern void pm_log(const char *fmt, ...) __KPRINTFLIKE(1); 601 602 #define PMD(level, arglist) { \ 603 if (pm_debug & (level)) { \ 604 pm_log arglist; \ 605 } \ 606 } 607 608 #else 609 #define PMD(level, arglist) 610 #endif 611 612 extern void pm_detaching(dev_info_t *); 613 extern void pm_detach_failed(dev_info_t *); 614 extern int pm_power(dev_info_t *, int, int); 615 extern int pm_unmanage(dev_info_t *); 616 extern void pm_rem_info(dev_info_t *); 617 extern int pm_get_norm_pwrs(dev_info_t *, int **, size_t *); 618 extern dev_info_t *pm_name_to_dip(char *, int); 619 extern int pm_power_up(dev_info_t *, int, int, int, pm_info_t *); 620 extern int pm_default_idle_threshold; 621 extern void pm_set_device_threshold(dev_info_t *, int, int); 622 extern int pm_valid_power(dev_info_t *, int, int); 623 extern void pm_lock_power(dev_info_t *, int *); 624 extern void pm_unlock_power(dev_info_t *, int); 625 extern int pm_try_locking_power(dev_info_t *, int *); 626 extern void pm_lock_power_single(dev_info_t *, int *); 627 extern void pm_unlock_power_single(dev_info_t *, int); 628 extern int pm_try_locking_power_single(dev_info_t *, int *); 629 extern int pm_isbc(dev_info_t *dip); 630 extern int pm_isdirect(dev_info_t *dip); 631 extern int pm_ctlops(dev_info_t *d, dev_info_t *r, ddi_ctl_enum_t o, 632 void *a, void *v); 633 extern int pm_noinvol_detached(char *); 634 extern int pm_init_child(dev_info_t *); 635 extern int pm_uninit_child(dev_info_t *); 636 637 extern int pm_all_to_normal(dev_info_t *, pm_canblock_t); 638 extern int pm_set_power(dev_info_t *, int, int, int, pm_canblock_t, int, 639 int *); 640 extern void pm_scan_init(dev_info_t *dip); 641 extern void pm_scan_fini(dev_info_t *dip); 642 extern void pm_scan_stop(dev_info_t *dip); 643 extern int pm_scan_stop_walk(dev_info_t *dip, void *); 644 extern void pm_scan(void *); 645 extern time_t pm_scan_dev(dev_info_t *dip); 646 extern void pm_rescan(void *); 647 extern int pm_rescan_walk(dev_info_t *, void *); 648 extern void pm_forget_power_level(dev_info_t *); 649 extern int pm_pre_config(dev_info_t *, char *); 650 extern int pm_pre_unconfig(dev_info_t *, int, int *, char *); 651 extern void pm_post_config(dev_info_t *, char *); 652 extern void pm_post_unconfig(dev_info_t *, int, char *); 653 extern void pm_pre_probe(dev_info_t *, pm_ppm_cookie_t *); 654 extern void pm_post_probe(pm_ppm_cookie_t *, int, int); 655 extern void pm_post_attach(pm_ppm_cookie_t *, int); 656 extern void pm_pre_attach(dev_info_t *, pm_ppm_cookie_t *, 657 ddi_attach_cmd_t); 658 extern void pm_pre_detach(dev_info_t *, ddi_detach_cmd_t, 659 pm_ppm_cookie_t *); 660 extern void pm_post_detach(pm_ppm_cookie_t *, int); 661 extern int pm_powerup(dev_info_t *); 662 extern int pm_all_at_normal(dev_info_t *); 663 extern int pm_busop_bus_power(dev_info_t *, void *, 664 pm_bus_power_op_t, void *, void *); 665 extern void pm_hold_power(dev_info_t *); 666 extern void pm_rele_power(dev_info_t *); 667 extern void pm_driver_removed(major_t); 668 extern void pm_borrow_lock(kthread_t *); 669 extern void pm_return_lock(void); 670 extern int pm_reattach_noinvol(void); 671 extern void pm_reattach_noinvol_fini(); 672 extern void pm_restore_direct_levels(void); 673 extern void pm_save_direct_levels(void); 674 extern void pm_cfb_setup(const char *); 675 extern void pm_proceed(dev_info_t *, int, int, int); 676 extern void pm_get_timestamps(dev_info_t *, time_t *); 677 extern void pm_deregister_watcher(int, dev_info_t *); 678 extern void pm_dispatch_to_dep_thread(int, char *, char *, int, int *, int); 679 extern int e_pm_valid_comp(dev_info_t *, int, pm_component_t **); 680 extern int e_pm_valid_info(dev_info_t *, pm_info_t **); 681 extern int e_pm_valid_power(dev_info_t *, int, int); 682 extern void pm_init_locks(void); 683 extern int pm_register_ppm(int (*)(dev_info_t *), dev_info_t *); 684 extern int pm_is_cfb(dev_info_t *); 685 #ifdef DEBUG 686 extern int pm_cfb_is_up(void); 687 #endif 688 689 #ifdef DEBUG 690 #define PM_LOCK_DIP(dip) { PMD(PMD_LOCK, ("dip lock %s@%s(%s#%d) " \ 691 "%s %d\n", PM_DEVICE(dip), \ 692 __FILE__, __LINE__)) \ 693 mutex_enter(&DEVI(dip)->devi_pm_lock); } 694 #define PM_UNLOCK_DIP(dip) { PMD(PMD_LOCK, ("dip unlock %s@%s(%s#%d) " \ 695 "%s %d\n", PM_DEVICE(dip), \ 696 __FILE__, __LINE__)) \ 697 mutex_exit(&DEVI(dip)->devi_pm_lock); } 698 #else 699 #define PM_LOCK_DIP(dip) mutex_enter(&DEVI(dip)->devi_pm_lock) 700 #define PM_UNLOCK_DIP(dip) mutex_exit(&DEVI(dip)->devi_pm_lock) 701 #endif 702 703 /* 704 * These are the same DEBUG or not 705 */ 706 #define PM_LOCK_BUSY(dip) mutex_enter(&DEVI(dip)->devi_pm_busy_lock) 707 #define PM_UNLOCK_BUSY(dip) mutex_exit(&DEVI(dip)->devi_pm_busy_lock) 708 #define PM_LOCK_POWER(dip, circp) pm_lock_power(dip, circp) 709 #define PM_UNLOCK_POWER(dip, circ) pm_unlock_power(dip, circ) 710 #define PM_TRY_LOCK_POWER(dip, circp) pm_try_locking_power(dip, circp) 711 #define PM_IAM_LOCKING_DIP(dip) (mutex_owned(&DEVI(dip)->devi_pm_lock)) 712 713 #define PM_DEFAULT_SYS_IDLENESS 1800 /* 30 minutes */ 714 715 /* 716 * Codes put into the pr_retval field of pm_rsvp_t that tell pm_block() 717 * how to proceed 718 */ 719 #define PMP_SUCCEED 0x1 /* return success, the process did it */ 720 #define PMP_FAIL 0x2 /* return fail, process did something else */ 721 #define PMP_RELEASE 0x3 /* let it go, the process has lost interest */ 722 /* also arg to pm_proceed to signal this */ 723 /* 724 * Values of "style" for e_pm_manage and pm_premanage 725 */ 726 #define PM_STYLE_NEW 0 727 #define PM_STYLE_UNKNOWN 1 728 729 /* 730 * Arg passed to pm_proceed that results in PMP_SUCCEED or PMP_FAIL being set 731 * in pr_retval depending on what is pending 732 */ 733 #define PMP_SETPOWER 0x4 734 735 #define PM_MAX_CLONE 256 736 737 typedef struct pm_rsvp { 738 dev_info_t *pr_dip; 739 int pr_comp; 740 int pr_newlevel; 741 int pr_oldlevel; 742 kcondvar_t pr_cv; /* a place to sleep */ 743 int pr_retval; /* what to do when you wake up */ 744 struct pm_rsvp *pr_next; 745 struct pm_rsvp *pr_prev; 746 } pm_rsvp_t; 747 748 typedef struct psce { /* pm_state_change_entries */ 749 struct pm_state_change *psce_first; 750 struct pm_state_change *psce_in; 751 struct pm_state_change *psce_out; 752 struct pm_state_change *psce_last; 753 int psce_overruns; 754 int psce_references; 755 kmutex_t psce_lock; 756 } psce_t; 757 758 typedef struct pscc { /* pm_state_change_control */ 759 int pscc_clone; 760 dev_info_t *pscc_dip; 761 psce_t *pscc_entries; 762 struct pscc *pscc_next; 763 struct pscc *pscc_prev; 764 } pscc_t; 765 766 #define PSCCOUNT 128 /* number of state change entries kept per process */ 767 768 /* 769 * Struct used to track the existance of devices exporting the 770 * no-involuntary-power-cycles property, and remember things from their 771 * devinfo node for later attach. 772 */ 773 typedef struct pm_noinvol { 774 struct pm_noinvol *ni_next; 775 char *ni_path; 776 major_t ni_major; /* for attaching at cpr time */ 777 uint_t ni_flags; /* selected PMC_* values */ 778 uint_t ni_noinvolpm; /* saved noinvolpm count */ 779 uint_t ni_volpmd; /* saved volpmd count */ 780 uint_t ni_wasvolpmd; /* was vol pm'd at detach */ 781 size_t ni_size; 782 int ni_persistent; /* still around */ 783 } pm_noinvol_t; 784 785 #define PMID_IOCTIMER 0x1 /* pm_ioctl sets during timer */ 786 #define PMID_CFBTIMER 0x2 /* cfb sets during timer */ 787 #define PMID_IOCSCAN 0x4 /* pm_ioctl sets during scan */ 788 #define PMID_CFBSCAN 0x8 /* cfb sets during scan */ 789 790 #define PMID_IOC (PMID_IOCTIMER | PMID_IOCSCAN) 791 #define PMID_CFB (PMID_CFBTIMER | PMID_CFBSCAN) 792 #define PMID_TIMERS (PMID_IOCTIMER | PMID_CFBTIMER) 793 #define PMID_SCANS (PMID_IOCSCAN | PMID_CFBSCAN) 794 #define PMID_SCANS_SHIFT 2 795 #define PMID_SET_SCANS(pmid) (pmid) |= (((pmid) & PMID_TIMERS) << \ 796 PMID_SCANS_SHIFT); 797 #define PMID_IS_IOC(pmid) ((pmid) & PMID_IOC) 798 #define PMID_IS_CFB(pmid, dip) (((pmid) & PMID_CFB) && \ 799 (DEVI(dip)->devi_pm_flags & \ 800 (PMC_DEF_THRESH | PMC_NEXDEF_THRESH))) 801 #define PM_IS_PID(dip) (PMID_IS_IOC(PM_GET_PM_SCAN(dip)->ps_idle_down) || \ 802 PMID_IS_CFB(PM_GET_PM_SCAN(dip)->ps_idle_down, dip)) 803 #define PM_IS_CFB(dip) (DEVI(dip)->devi_pm_flags & PMC_CONSOLE_FB) 804 #define PM_KUC(dip) (DEVI(dip)->devi_pm_kidsupcnt) 805 #define PM_CURPOWER(dip, comp) cur_power(PM_CP(dip, comp)) 806 807 #define PM_WANTS_NOTIFICATION(dip) \ 808 (DEVI(dip)->devi_pm_flags & PMC_WANTS_NOTIFY) 809 810 #define PM_HAS_BUS_POWER(dip) \ 811 ((DEVI(dip)->devi_ops->devo_bus_ops != NULL) && \ 812 (DEVI(dip)->devi_ops->devo_bus_ops->busops_rev >= BUSO_REV_7) &&\ 813 (DEVI(dip)->devi_ops->devo_bus_ops->bus_power != NULL)) 814 815 #define PM_BUS_POWER_FUNC(dip) \ 816 DEVI(dip)->devi_ops->devo_bus_ops->bus_power 817 818 /* 819 * Structure used to pass down sunpm's private data variables 820 * through the bus_power bus_op calls 821 */ 822 typedef struct pm_sp_misc { 823 pm_canblock_t pspm_canblock; 824 int pspm_scan; 825 int *pspm_errnop; 826 int pspm_direction; 827 } pm_sp_misc_t; 828 829 /* 830 * This structure is used in validating that the power level 831 * of the descendents are off, while a device is powered off. 832 */ 833 typedef struct pm_desc_pwrchk { 834 dev_info_t *pdpc_dip; 835 int pdpc_par_involved; 836 } pm_desc_pwrchk_t; 837 838 839 /* 840 * These defines are used by pm_trans_check() to calculate time. 841 * Mostly copied from "tzfile.h". 842 */ 843 #define EPOCH_YEAR 1970 844 #define SECSPERMIN 60 845 #define MINSPERHOUR 60 846 #define HOURSPERDAY 24 847 #define DAYSPERWEEK 7 848 #define DAYSPERNYEAR 365 849 #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) 850 #define SECSPERDAY (SECSPERHOUR * HOURSPERDAY) 851 #define DC_SPY (SECSPERDAY * DAYSPERNYEAR) 852 #define DC_SPW (SECSPERDAY * DAYSPERWEEK) 853 #define DC_SPD SECSPERDAY 854 855 #define DC_SCSI_YEAR_LEN 4 /* YYYY */ 856 #define DC_SCSI_WEEK_LEN 2 /* WW */ 857 #define DC_SCSI_NPY 5 /* # power-cycle years */ 858 859 #endif /* _KERNEL */ 860 861 #ifdef __cplusplus 862 } 863 #endif 864 865 #endif /* _SYS_EPM_H */ 866