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