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 5c42872d4Smh27603 * Common Development and Distribution License (the "License"). 6c42872d4Smh27603 * 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 /* 229681b4a1Skchow * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * pm This driver now only handles the ioctl interface. The scanning 307c478bd9Sstevel@tonic-gate * and policy stuff now lives in common/os/sunpm.c. 317c478bd9Sstevel@tonic-gate * Not DDI compliant 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <sys/types.h> 357c478bd9Sstevel@tonic-gate #include <sys/errno.h> 367c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 377c478bd9Sstevel@tonic-gate #include <sys/conf.h> /* driver flags and functions */ 387c478bd9Sstevel@tonic-gate #include <sys/open.h> /* OTYP_CHR definition */ 397c478bd9Sstevel@tonic-gate #include <sys/stat.h> /* S_IFCHR definition */ 407c478bd9Sstevel@tonic-gate #include <sys/pathname.h> /* name -> dev_info xlation */ 417c478bd9Sstevel@tonic-gate #include <sys/kmem.h> /* memory alloc stuff */ 427c478bd9Sstevel@tonic-gate #include <sys/debug.h> 437c478bd9Sstevel@tonic-gate #include <sys/pm.h> 447c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 457c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 467c478bd9Sstevel@tonic-gate #include <sys/epm.h> 477c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 487c478bd9Sstevel@tonic-gate #include <sys/mode.h> 497c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 507c478bd9Sstevel@tonic-gate #include <sys/promif.h> 517c478bd9Sstevel@tonic-gate #include <sys/consdev.h> 527c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 537c478bd9Sstevel@tonic-gate #include <sys/poll.h> 547c478bd9Sstevel@tonic-gate #include <sys/note.h> 557c478bd9Sstevel@tonic-gate #include <sys/taskq.h> 567c478bd9Sstevel@tonic-gate #include <sys/policy.h> 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* 59*2df1fe9cSrandyf * Minor number is instance<<8 + clone minor from range 1-254; (0 reserved 60*2df1fe9cSrandyf * for "original") 617c478bd9Sstevel@tonic-gate */ 627c478bd9Sstevel@tonic-gate #define PM_MINOR_TO_CLONE(minor) ((minor) & (PM_MAX_CLONE -1)) 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #define PM_NUMCMPTS(dip) (DEVI(dip)->devi_pm_num_components) 657c478bd9Sstevel@tonic-gate #define PM_IS_CFB(dip) (DEVI(dip)->devi_pm_flags & PMC_CONSOLE_FB) 667c478bd9Sstevel@tonic-gate #define PM_MAJOR(dip) ddi_driver_major(dip) 677c478bd9Sstevel@tonic-gate #define PM_RELE(dip) ddi_release_devi(dip) 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate #define PM_IDLEDOWN_TIME 10 70*2df1fe9cSrandyf #define MAXSMBIOSSTRLEN 64 /* from SMBIOS spec */ 71*2df1fe9cSrandyf #define MAXCOPYBUF (MAXSMBIOSSTRLEN + 1) 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate extern kmutex_t pm_scan_lock; /* protects autopm_enable, pm_scans_disabled */ 747c478bd9Sstevel@tonic-gate extern kmutex_t pm_clone_lock; /* protects pm_clones array */ 757c478bd9Sstevel@tonic-gate extern int autopm_enabled; 76c42872d4Smh27603 extern pm_cpupm_t cpupm; 77c42872d4Smh27603 extern int pm_default_idle_threshold; 78c42872d4Smh27603 extern int pm_system_idle_threshold; 79c42872d4Smh27603 extern int pm_cpu_idle_threshold; 807c478bd9Sstevel@tonic-gate extern kcondvar_t pm_clones_cv[PM_MAX_CLONE]; 817c478bd9Sstevel@tonic-gate extern uint_t pm_poll_cnt[PM_MAX_CLONE]; 82*2df1fe9cSrandyf extern int autoS3_enabled; 83*2df1fe9cSrandyf extern void pm_record_thresh(pm_thresh_rec_t *); 84*2df1fe9cSrandyf extern void pm_register_watcher(int, dev_info_t *); 85*2df1fe9cSrandyf extern int pm_get_current_power(dev_info_t *, int, int *); 86*2df1fe9cSrandyf extern int pm_interest_registered(int); 87*2df1fe9cSrandyf extern void pm_all_to_default_thresholds(void); 88*2df1fe9cSrandyf extern int pm_current_threshold(dev_info_t *, int, int *); 89*2df1fe9cSrandyf extern void pm_deregister_watcher(int, dev_info_t *); 90*2df1fe9cSrandyf extern void pm_unrecord_threshold(char *); 91*2df1fe9cSrandyf extern int pm_S3_enabled; 92*2df1fe9cSrandyf extern int pm_ppm_searchlist(pm_searchargs_t *); 93*2df1fe9cSrandyf extern psce_t *pm_psc_clone_to_direct(int); 94*2df1fe9cSrandyf extern psce_t *pm_psc_clone_to_interest(int); 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* 977c478bd9Sstevel@tonic-gate * The soft state of the power manager. Since there will only 987c478bd9Sstevel@tonic-gate * one of these, just reference it through a static pointer. 997c478bd9Sstevel@tonic-gate */ 1007c478bd9Sstevel@tonic-gate static struct pmstate { 1017c478bd9Sstevel@tonic-gate dev_info_t *pm_dip; /* ptr to our dev_info node */ 1027c478bd9Sstevel@tonic-gate int pm_instance; /* for ddi_get_instance() */ 1037c478bd9Sstevel@tonic-gate timeout_id_t pm_idledown_id; /* pm idledown timeout id */ 1047c478bd9Sstevel@tonic-gate uchar_t pm_clones[PM_MAX_CLONE]; /* uniqueify multiple opens */ 1057c478bd9Sstevel@tonic-gate struct cred *pm_cred[PM_MAX_CLONE]; /* cred for each unique open */ 1067c478bd9Sstevel@tonic-gate } pm_state = { NULL, -1, (timeout_id_t)0 }; 1077c478bd9Sstevel@tonic-gate typedef struct pmstate *pm_state_t; 1087c478bd9Sstevel@tonic-gate static pm_state_t pmstp = &pm_state; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate static int pm_open(dev_t *, int, int, cred_t *); 1117c478bd9Sstevel@tonic-gate static int pm_close(dev_t, int, int, cred_t *); 1127c478bd9Sstevel@tonic-gate static int pm_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 1137c478bd9Sstevel@tonic-gate static int pm_chpoll(dev_t, short, int, short *, struct pollhead **); 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate static struct cb_ops pm_cb_ops = { 1167c478bd9Sstevel@tonic-gate pm_open, /* open */ 1177c478bd9Sstevel@tonic-gate pm_close, /* close */ 1187c478bd9Sstevel@tonic-gate nodev, /* strategy */ 1197c478bd9Sstevel@tonic-gate nodev, /* print */ 1207c478bd9Sstevel@tonic-gate nodev, /* dump */ 1217c478bd9Sstevel@tonic-gate nodev, /* read */ 1227c478bd9Sstevel@tonic-gate nodev, /* write */ 1237c478bd9Sstevel@tonic-gate pm_ioctl, /* ioctl */ 1247c478bd9Sstevel@tonic-gate nodev, /* devmap */ 1257c478bd9Sstevel@tonic-gate nodev, /* mmap */ 1267c478bd9Sstevel@tonic-gate nodev, /* segmap */ 1277c478bd9Sstevel@tonic-gate pm_chpoll, /* poll */ 1287c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 1297c478bd9Sstevel@tonic-gate NULL, /* streamtab */ 1307c478bd9Sstevel@tonic-gate D_NEW | D_MP /* driver compatibility flag */ 1317c478bd9Sstevel@tonic-gate }; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate static int pm_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, 1347c478bd9Sstevel@tonic-gate void **result); 1357c478bd9Sstevel@tonic-gate static int pm_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 1367c478bd9Sstevel@tonic-gate static int pm_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate static struct dev_ops pm_ops = { 1397c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev */ 1407c478bd9Sstevel@tonic-gate 0, /* refcnt */ 1417c478bd9Sstevel@tonic-gate pm_getinfo, /* info */ 1427c478bd9Sstevel@tonic-gate nulldev, /* identify */ 1437c478bd9Sstevel@tonic-gate nulldev, /* probe */ 1447c478bd9Sstevel@tonic-gate pm_attach, /* attach */ 1457c478bd9Sstevel@tonic-gate pm_detach, /* detach */ 1467c478bd9Sstevel@tonic-gate nodev, /* reset */ 1477c478bd9Sstevel@tonic-gate &pm_cb_ops, /* driver operations */ 1487c478bd9Sstevel@tonic-gate NULL, /* bus operations */ 1497c478bd9Sstevel@tonic-gate NULL /* power */ 1507c478bd9Sstevel@tonic-gate }; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 1537c478bd9Sstevel@tonic-gate &mod_driverops, 1547c478bd9Sstevel@tonic-gate "power management driver v%I%", 1557c478bd9Sstevel@tonic-gate &pm_ops 1567c478bd9Sstevel@tonic-gate }; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 1597c478bd9Sstevel@tonic-gate MODREV_1, &modldrv, 0 1607c478bd9Sstevel@tonic-gate }; 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate /* Local functions */ 1637c478bd9Sstevel@tonic-gate #ifdef DEBUG 1647c478bd9Sstevel@tonic-gate static int print_info(dev_info_t *, void *); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate #endif 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate int 1697c478bd9Sstevel@tonic-gate _init(void) 1707c478bd9Sstevel@tonic-gate { 1717c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate int 1757c478bd9Sstevel@tonic-gate _fini(void) 1767c478bd9Sstevel@tonic-gate { 1777c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate int 1817c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 1827c478bd9Sstevel@tonic-gate { 1837c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate static int 1877c478bd9Sstevel@tonic-gate pm_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 1887c478bd9Sstevel@tonic-gate { 1897c478bd9Sstevel@tonic-gate int i; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate switch (cmd) { 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate case DDI_ATTACH: 1947c478bd9Sstevel@tonic-gate if (pmstp->pm_instance != -1) /* Only allow one instance */ 1957c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 1967c478bd9Sstevel@tonic-gate pmstp->pm_instance = ddi_get_instance(dip); 1977c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, "pm", S_IFCHR, 1987c478bd9Sstevel@tonic-gate (pmstp->pm_instance << 8) + 0, 1997c478bd9Sstevel@tonic-gate DDI_PSEUDO, 0) != DDI_SUCCESS) { 2007c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate pmstp->pm_dip = dip; /* pm_init and getinfo depend on it */ 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate for (i = 0; i < PM_MAX_CLONE; i++) 2057c478bd9Sstevel@tonic-gate cv_init(&pm_clones_cv[i], NULL, CV_DEFAULT, NULL); 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate ddi_report_dev(dip); 2087c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate default: 2117c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2127c478bd9Sstevel@tonic-gate } 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2167c478bd9Sstevel@tonic-gate static int 2177c478bd9Sstevel@tonic-gate pm_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 2187c478bd9Sstevel@tonic-gate { 2197c478bd9Sstevel@tonic-gate int i; 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate switch (cmd) { 2227c478bd9Sstevel@tonic-gate case DDI_DETACH: 2237c478bd9Sstevel@tonic-gate /* 2247c478bd9Sstevel@tonic-gate * Don't detach while idledown timeout is pending. Note that 2257c478bd9Sstevel@tonic-gate * we already know we're not in pm_ioctl() due to framework 2267c478bd9Sstevel@tonic-gate * synchronization, so this is a sufficient test 2277c478bd9Sstevel@tonic-gate */ 2287c478bd9Sstevel@tonic-gate if (pmstp->pm_idledown_id) 2297c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate for (i = 0; i < PM_MAX_CLONE; i++) 2327c478bd9Sstevel@tonic-gate cv_destroy(&pm_clones_cv[i]); 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 2357c478bd9Sstevel@tonic-gate pmstp->pm_instance = -1; 2367c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate default: 2397c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate } 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate static int 2447c478bd9Sstevel@tonic-gate pm_close_direct_pm_device(dev_info_t *dip, void *arg) 2457c478bd9Sstevel@tonic-gate { 2467c478bd9Sstevel@tonic-gate int clone; 2477c478bd9Sstevel@tonic-gate char *pathbuf; 2487c478bd9Sstevel@tonic-gate pm_info_t *info = PM_GET_PM_INFO(dip); 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate clone = *((int *)arg); 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate if (!info) 2537c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate pathbuf = kmem_alloc(MAXPATHLEN, KM_SLEEP); 2567c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 2577c478bd9Sstevel@tonic-gate if (clone == info->pmi_clone) { 2587c478bd9Sstevel@tonic-gate PMD(PMD_CLOSE, ("pm_close: found %s@%s(%s#%d)\n", 2597c478bd9Sstevel@tonic-gate PM_DEVICE(dip))) 2607c478bd9Sstevel@tonic-gate ASSERT(PM_ISDIRECT(dip)); 2617c478bd9Sstevel@tonic-gate info->pmi_dev_pm_state &= ~PM_DIRECT; 2627c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 2637c478bd9Sstevel@tonic-gate pm_proceed(dip, PMP_RELEASE, -1, -1); 2647c478bd9Sstevel@tonic-gate /* Bring ourselves up if there is a keeper that is up */ 2657c478bd9Sstevel@tonic-gate (void) ddi_pathname(dip, pathbuf); 2667c478bd9Sstevel@tonic-gate pm_dispatch_to_dep_thread(PM_DEP_WK_BRINGUP_SELF, NULL, 2677c478bd9Sstevel@tonic-gate pathbuf, PM_DEP_NOWAIT, NULL, 0); 2687c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 2697c478bd9Sstevel@tonic-gate info->pmi_clone = 0; 2707c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 2717c478bd9Sstevel@tonic-gate } else { 2727c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate kmem_free(pathbuf, MAXPATHLEN); 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate /* restart autopm on device released from direct pm */ 2777c478bd9Sstevel@tonic-gate pm_rescan(dip); 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate #define PM_REQ 1 2837c478bd9Sstevel@tonic-gate #define NOSTRUCT 2 2847c478bd9Sstevel@tonic-gate #define DIP 3 2857c478bd9Sstevel@tonic-gate #define NODIP 4 2867c478bd9Sstevel@tonic-gate #define NODEP 5 2877c478bd9Sstevel@tonic-gate #define DEP 6 2887c478bd9Sstevel@tonic-gate #define PM_PSC 7 289*2df1fe9cSrandyf #define PM_SRCH 8 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate #define CHECKPERMS 0x001 2927c478bd9Sstevel@tonic-gate #define SU 0x002 2937c478bd9Sstevel@tonic-gate #define SG 0x004 2947c478bd9Sstevel@tonic-gate #define OWNER 0x008 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate #define INWHO 0x001 2977c478bd9Sstevel@tonic-gate #define INDATAINT 0x002 2987c478bd9Sstevel@tonic-gate #define INDATASTRING 0x004 2997c478bd9Sstevel@tonic-gate #define INDEP 0x008 3007c478bd9Sstevel@tonic-gate #define INDATAOUT 0x010 3017c478bd9Sstevel@tonic-gate #define INDATA (INDATAOUT | INDATAINT | INDATASTRING | INDEP) 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate struct pm_cmd_info { 3047c478bd9Sstevel@tonic-gate int cmd; /* command code */ 3057c478bd9Sstevel@tonic-gate char *name; /* printable string */ 3067c478bd9Sstevel@tonic-gate int supported; /* true if still supported */ 3077c478bd9Sstevel@tonic-gate int str_type; /* PM_REQ or NOSTRUCT */ 3087c478bd9Sstevel@tonic-gate int inargs; /* INWHO, INDATAINT, INDATASTRING, INDEP, */ 3097c478bd9Sstevel@tonic-gate /* INDATAOUT */ 3107c478bd9Sstevel@tonic-gate int diptype; /* DIP or NODIP */ 3117c478bd9Sstevel@tonic-gate int deptype; /* DEP or NODEP */ 3127c478bd9Sstevel@tonic-gate int permission; /* SU, GU, or CHECKPERMS */ 3137c478bd9Sstevel@tonic-gate }; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate #ifdef DEBUG 3167c478bd9Sstevel@tonic-gate char *pm_cmd_string; 3177c478bd9Sstevel@tonic-gate int pm_cmd; 3187c478bd9Sstevel@tonic-gate #endif 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate /* 3217c478bd9Sstevel@tonic-gate * Returns true if permission granted by credentials 3227c478bd9Sstevel@tonic-gate */ 3237c478bd9Sstevel@tonic-gate static int 3247c478bd9Sstevel@tonic-gate pm_perms(int perm, cred_t *cr) 3257c478bd9Sstevel@tonic-gate { 3267c478bd9Sstevel@tonic-gate if (perm == 0) /* no restrictions */ 3277c478bd9Sstevel@tonic-gate return (1); 3287c478bd9Sstevel@tonic-gate if (perm == CHECKPERMS) /* ok for now (is checked later) */ 3297c478bd9Sstevel@tonic-gate return (1); 3307c478bd9Sstevel@tonic-gate if ((perm & SU) && secpolicy_power_mgmt(cr) == 0) /* privileged? */ 3317c478bd9Sstevel@tonic-gate return (1); 3327c478bd9Sstevel@tonic-gate if ((perm & SG) && (crgetgid(cr) == 0)) /* group 0 is ok */ 3337c478bd9Sstevel@tonic-gate return (1); 3347c478bd9Sstevel@tonic-gate return (0); 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate #ifdef DEBUG 3387c478bd9Sstevel@tonic-gate static int 3397c478bd9Sstevel@tonic-gate print_info(dev_info_t *dip, void *arg) 3407c478bd9Sstevel@tonic-gate { 3417c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(arg)) 3427c478bd9Sstevel@tonic-gate pm_info_t *info; 3437c478bd9Sstevel@tonic-gate int i, j; 3447c478bd9Sstevel@tonic-gate struct pm_component *cp; 3457c478bd9Sstevel@tonic-gate extern int pm_cur_power(pm_component_t *cp); 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate info = PM_GET_PM_INFO(dip); 3487c478bd9Sstevel@tonic-gate if (!info) 3497c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 3507c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pm_info for %s\n", ddi_node_name(dip)); 3517c478bd9Sstevel@tonic-gate for (i = 0; i < PM_NUMCMPTS(dip); i++) { 3527c478bd9Sstevel@tonic-gate cp = PM_CP(dip, i); 3537c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "\tThresholds[%d] =", i); 3547c478bd9Sstevel@tonic-gate for (j = 0; j < cp->pmc_comp.pmc_numlevels; j++) 3557c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, " %d", cp->pmc_comp.pmc_thresh[i]); 3567c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "\n"); 3577c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "\tCurrent power[%d] = %d\n", i, 3587c478bd9Sstevel@tonic-gate pm_cur_power(cp)); 3597c478bd9Sstevel@tonic-gate } 3607c478bd9Sstevel@tonic-gate if (PM_ISDIRECT(dip)) 3617c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "\tDirect power management\n"); 3627c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 3637c478bd9Sstevel@tonic-gate } 3647c478bd9Sstevel@tonic-gate #endif 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate /* 3677c478bd9Sstevel@tonic-gate * command, name, supported, str_type, inargs, diptype, deptype, permission 3687c478bd9Sstevel@tonic-gate */ 3697c478bd9Sstevel@tonic-gate static struct pm_cmd_info pmci[] = { 3707c478bd9Sstevel@tonic-gate {PM_SCHEDULE, "PM_SCHEDULE", 0}, 3717c478bd9Sstevel@tonic-gate {PM_GET_IDLE_TIME, "PM_GET_IDLE_TIME", 0}, 3727c478bd9Sstevel@tonic-gate {PM_GET_NUM_CMPTS, "PM_GET_NUM_CMPTS", 0}, 3737c478bd9Sstevel@tonic-gate {PM_GET_THRESHOLD, "PM_GET_THRESHOLD", 0}, 3747c478bd9Sstevel@tonic-gate {PM_SET_THRESHOLD, "PM_SET_THRESHOLD", 0}, 3757c478bd9Sstevel@tonic-gate {PM_GET_NORM_PWR, "PM_GET_NORM_PWR", 0}, 3767c478bd9Sstevel@tonic-gate {PM_SET_CUR_PWR, "PM_SET_CUR_PWR", 0}, 3777c478bd9Sstevel@tonic-gate {PM_GET_CUR_PWR, "PM_GET_CUR_PWR", 0}, 3787c478bd9Sstevel@tonic-gate {PM_GET_NUM_DEPS, "PM_GET_NUM_DEPS", 0}, 3797c478bd9Sstevel@tonic-gate {PM_GET_DEP, "PM_GET_DEP", 0}, 3807c478bd9Sstevel@tonic-gate {PM_ADD_DEP, "PM_ADD_DEP", 0}, 3817c478bd9Sstevel@tonic-gate {PM_REM_DEP, "PM_REM_DEP", 0}, 3827c478bd9Sstevel@tonic-gate {PM_REM_DEVICE, "PM_REM_DEVICE", 0}, 3837c478bd9Sstevel@tonic-gate {PM_REM_DEVICES, "PM_REM_DEVICES", 0}, 3847c478bd9Sstevel@tonic-gate {PM_REPARSE_PM_PROPS, "PM_REPARSE_PM_PROPS", 1, PM_REQ, INWHO, DIP, 3857c478bd9Sstevel@tonic-gate NODEP}, 3867c478bd9Sstevel@tonic-gate {PM_DISABLE_AUTOPM, "PM_DISABLE_AUTOPM", 0}, 3877c478bd9Sstevel@tonic-gate {PM_REENABLE_AUTOPM, "PM_REENABLE_AUTOPM", 0}, 3887c478bd9Sstevel@tonic-gate {PM_SET_NORM_PWR, "PM_SET_NORM_PWR", 0 }, 3897c478bd9Sstevel@tonic-gate {PM_SET_DEVICE_THRESHOLD, "PM_SET_DEVICE_THRESHOLD", 1, PM_REQ, 3907c478bd9Sstevel@tonic-gate INWHO, NODIP, NODEP, SU}, 3917c478bd9Sstevel@tonic-gate {PM_GET_SYSTEM_THRESHOLD, "PM_GET_SYSTEM_THRESHOLD", 1, NOSTRUCT}, 3927c478bd9Sstevel@tonic-gate {PM_GET_DEFAULT_SYSTEM_THRESHOLD, "PM_GET_DEFAULT_SYSTEM_THRESHOLD", 3937c478bd9Sstevel@tonic-gate 1, NOSTRUCT}, 3947c478bd9Sstevel@tonic-gate {PM_SET_SYSTEM_THRESHOLD, "PM_SET_SYSTEM_THRESHOLD", 1, NOSTRUCT, 3957c478bd9Sstevel@tonic-gate 0, 0, 0, SU}, 3967c478bd9Sstevel@tonic-gate {PM_START_PM, "PM_START_PM", 1, NOSTRUCT, 0, 0, 0, SU}, 3977c478bd9Sstevel@tonic-gate {PM_STOP_PM, "PM_STOP_PM", 1, NOSTRUCT, 0, 0, 0, SU}, 3987c478bd9Sstevel@tonic-gate {PM_RESET_PM, "PM_RESET_PM", 1, NOSTRUCT, 0, 0, 0, SU}, 3997c478bd9Sstevel@tonic-gate {PM_GET_STATS, "PM_GET_STATS", 1, PM_REQ, INWHO | INDATAOUT, 4007c478bd9Sstevel@tonic-gate DIP, NODEP}, 4017c478bd9Sstevel@tonic-gate {PM_GET_DEVICE_THRESHOLD, "PM_GET_DEVICE_THRESHOLD", 1, PM_REQ, INWHO, 4027c478bd9Sstevel@tonic-gate DIP, NODEP}, 4037c478bd9Sstevel@tonic-gate {PM_GET_POWER_NAME, "PM_GET_POWER_NAME", 1, PM_REQ, INWHO | INDATAOUT, 4047c478bd9Sstevel@tonic-gate DIP, NODEP}, 4057c478bd9Sstevel@tonic-gate {PM_GET_POWER_LEVELS, "PM_GET_POWER_LEVELS", 1, PM_REQ, 4067c478bd9Sstevel@tonic-gate INWHO | INDATAOUT, DIP, NODEP}, 4077c478bd9Sstevel@tonic-gate {PM_GET_NUM_COMPONENTS, "PM_GET_NUM_COMPONENTS", 1, PM_REQ, INWHO, 4087c478bd9Sstevel@tonic-gate DIP, NODEP}, 4097c478bd9Sstevel@tonic-gate {PM_GET_COMPONENT_NAME, "PM_GET_COMPONENT_NAME", 1, PM_REQ, 4107c478bd9Sstevel@tonic-gate INWHO | INDATAOUT, DIP, NODEP}, 4117c478bd9Sstevel@tonic-gate {PM_GET_NUM_POWER_LEVELS, "PM_GET_NUM_POWER_LEVELS", 1, PM_REQ, INWHO, 4127c478bd9Sstevel@tonic-gate DIP, NODEP}, 4137c478bd9Sstevel@tonic-gate {PM_GET_STATE_CHANGE, "PM_GET_STATE_CHANGE", 1, PM_PSC}, 4147c478bd9Sstevel@tonic-gate {PM_GET_STATE_CHANGE_WAIT, "PM_GET_STATE_CHANGE_WAIT", 1, PM_PSC}, 4157c478bd9Sstevel@tonic-gate {PM_DIRECT_PM, "PM_DIRECT_PM", 1, PM_REQ, INWHO, DIP, NODEP, 4167c478bd9Sstevel@tonic-gate (SU | SG)}, 4177c478bd9Sstevel@tonic-gate {PM_RELEASE_DIRECT_PM, "PM_RELEASE_DIRECT_PM", 1, PM_REQ, INWHO, 4187c478bd9Sstevel@tonic-gate DIP, NODEP}, 4197c478bd9Sstevel@tonic-gate {PM_DIRECT_NOTIFY, "PM_DIRECT_NOTIFY", 1, PM_PSC}, 4207c478bd9Sstevel@tonic-gate {PM_DIRECT_NOTIFY_WAIT, "PM_DIRECT_NOTIFY_WAIT", 1, PM_PSC}, 4217c478bd9Sstevel@tonic-gate {PM_RESET_DEVICE_THRESHOLD, "PM_RESET_DEVICE_THRESHOLD", 1, PM_REQ, 4227c478bd9Sstevel@tonic-gate INWHO, DIP, NODEP, SU}, 4237c478bd9Sstevel@tonic-gate {PM_GET_PM_STATE, "PM_GET_PM_STATE", 1, NOSTRUCT}, 424*2df1fe9cSrandyf {PM_GET_AUTOS3_STATE, "PM_GET_AUTOS3_STATE", 1, NOSTRUCT}, 425*2df1fe9cSrandyf {PM_GET_S3_SUPPORT_STATE, "PM_GET_S3_SUPPORT_STATE", 1, NOSTRUCT}, 4267c478bd9Sstevel@tonic-gate {PM_GET_DEVICE_TYPE, "PM_GET_DEVICE_TYPE", 1, PM_REQ, INWHO, 4277c478bd9Sstevel@tonic-gate DIP, NODEP}, 4287c478bd9Sstevel@tonic-gate {PM_SET_COMPONENT_THRESHOLDS, "PM_SET_COMPONENT_THRESHOLDS", 1, PM_REQ, 4297c478bd9Sstevel@tonic-gate INWHO | INDATAINT, NODIP, NODEP, SU}, 4307c478bd9Sstevel@tonic-gate {PM_GET_COMPONENT_THRESHOLDS, "PM_GET_COMPONENT_THRESHOLDS", 1, PM_REQ, 4317c478bd9Sstevel@tonic-gate INWHO | INDATAOUT, DIP, NODEP}, 4327c478bd9Sstevel@tonic-gate {PM_IDLE_DOWN, "PM_IDLE_DOWN", 1, NOSTRUCT, 0, 0, 0, SU}, 4337c478bd9Sstevel@tonic-gate {PM_GET_DEVICE_THRESHOLD_BASIS, "PM_GET_DEVICE_THRESHOLD_BASIS", 1, 4347c478bd9Sstevel@tonic-gate PM_REQ, INWHO, DIP, NODEP}, 4357c478bd9Sstevel@tonic-gate {PM_SET_CURRENT_POWER, "PM_SET_CURRENT_POWER", 1, PM_REQ, INWHO, DIP, 4367c478bd9Sstevel@tonic-gate NODEP}, 4377c478bd9Sstevel@tonic-gate {PM_GET_CURRENT_POWER, "PM_GET_CURRENT_POWER", 1, PM_REQ, INWHO, DIP, 4387c478bd9Sstevel@tonic-gate NODEP}, 4397c478bd9Sstevel@tonic-gate {PM_GET_FULL_POWER, "PM_GET_FULL_POWER", 1, PM_REQ, INWHO, DIP, 4407c478bd9Sstevel@tonic-gate NODEP}, 4417c478bd9Sstevel@tonic-gate {PM_ADD_DEPENDENT, "PM_ADD_DEPENDENT", 1, PM_REQ, INWHO | INDATASTRING, 4427c478bd9Sstevel@tonic-gate DIP, DEP, SU}, 4437c478bd9Sstevel@tonic-gate {PM_GET_TIME_IDLE, "PM_GET_TIME_IDLE", 1, PM_REQ, INWHO, DIP, NODEP}, 4447c478bd9Sstevel@tonic-gate {PM_ADD_DEPENDENT_PROPERTY, "PM_ADD_DEPENDENT_PROPERTY", 1, PM_REQ, 4457c478bd9Sstevel@tonic-gate INWHO | INDATASTRING, NODIP, DEP, SU}, 446c42872d4Smh27603 {PM_START_CPUPM, "PM_START_CPUPM", 1, NOSTRUCT, 0, 0, 0, SU}, 447c42872d4Smh27603 {PM_STOP_CPUPM, "PM_STOP_CPUPM", 1, NOSTRUCT, 0, 0, 0, SU}, 448c42872d4Smh27603 {PM_GET_CPU_THRESHOLD, "PM_GET_CPU_THRESHOLD", 1, NOSTRUCT}, 449c42872d4Smh27603 {PM_SET_CPU_THRESHOLD, "PM_SET_CPU_THRESHOLD", 1, NOSTRUCT, 450c42872d4Smh27603 0, 0, 0, SU}, 451c42872d4Smh27603 {PM_GET_CPUPM_STATE, "PM_GET_CPUPM_STATE", 1, NOSTRUCT}, 452*2df1fe9cSrandyf {PM_START_AUTOS3, "PM_START_AUTOS3", 1, NOSTRUCT, 0, 0, 0, SU}, 453*2df1fe9cSrandyf {PM_STOP_AUTOS3, "PM_STOP_AUTOS3", 1, NOSTRUCT, 0, 0, 0, SU}, 454*2df1fe9cSrandyf {PM_ENABLE_S3, "PM_ENABLE_S3", 1, NOSTRUCT, 0, 0, 0, SU}, 455*2df1fe9cSrandyf {PM_DISABLE_S3, "PM_DISABLE_S3", 1, NOSTRUCT, 0, 0, 0, SU}, 456*2df1fe9cSrandyf {PM_ENTER_S3, "PM_ENTER_S3", 1, NOSTRUCT, 0, 0, 0, SU}, 457*2df1fe9cSrandyf {PM_SEARCH_LIST, "PM_SEARCH_LIST", 1, PM_SRCH, 0, 0, 0, SU}, 458*2df1fe9cSrandyf {PM_GET_CMD_NAME, "PM_GET_CMD_NAME", 1, PM_REQ, INDATAOUT, NODIP, 459*2df1fe9cSrandyf NODEP, 0}, 4607c478bd9Sstevel@tonic-gate {0, NULL} 4617c478bd9Sstevel@tonic-gate }; 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate struct pm_cmd_info * 4647c478bd9Sstevel@tonic-gate pc_info(int cmd) 4657c478bd9Sstevel@tonic-gate { 4667c478bd9Sstevel@tonic-gate struct pm_cmd_info *pcip; 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate for (pcip = pmci; pcip->name; pcip++) { 4697c478bd9Sstevel@tonic-gate if (cmd == pcip->cmd) 4707c478bd9Sstevel@tonic-gate return (pcip); 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate return (NULL); 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate static char * 4767c478bd9Sstevel@tonic-gate pm_decode_cmd(int cmd) 4777c478bd9Sstevel@tonic-gate { 4787c478bd9Sstevel@tonic-gate static char invbuf[64]; 4797c478bd9Sstevel@tonic-gate struct pm_cmd_info *pcip = pc_info(cmd); 4807c478bd9Sstevel@tonic-gate if (pcip != NULL) 4817c478bd9Sstevel@tonic-gate return (pcip->name); 4827c478bd9Sstevel@tonic-gate (void) sprintf(invbuf, "ioctl: invalid command %d\n", cmd); 4837c478bd9Sstevel@tonic-gate return (invbuf); 4847c478bd9Sstevel@tonic-gate } 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate /* 4877c478bd9Sstevel@tonic-gate * Allocate scan resource, create taskq, then dispatch scan, 4887c478bd9Sstevel@tonic-gate * called only if autopm is enabled. 4897c478bd9Sstevel@tonic-gate */ 4907c478bd9Sstevel@tonic-gate int 4917c478bd9Sstevel@tonic-gate pm_start_pm_walk(dev_info_t *dip, void *arg) 4927c478bd9Sstevel@tonic-gate { 493c42872d4Smh27603 int cmd = *((int *)arg); 4949681b4a1Skchow #ifdef PMDDEBUG 495c42872d4Smh27603 char *cmdstr = pm_decode_cmd(cmd); 4969681b4a1Skchow #endif 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate if (!PM_GET_PM_INFO(dip) || PM_ISBC(dip)) 4997c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 5007c478bd9Sstevel@tonic-gate 501c42872d4Smh27603 switch (cmd) { 502c42872d4Smh27603 case PM_START_CPUPM: 503c42872d4Smh27603 if (!PM_ISCPU(dip)) 504c42872d4Smh27603 return (DDI_WALK_CONTINUE); 5057c478bd9Sstevel@tonic-gate mutex_enter(&pm_scan_lock); 506c42872d4Smh27603 if (!PM_CPUPM_DISABLED) 507c42872d4Smh27603 pm_scan_init(dip); 508c42872d4Smh27603 mutex_exit(&pm_scan_lock); 509c42872d4Smh27603 break; 510c42872d4Smh27603 case PM_START_PM: 511c42872d4Smh27603 mutex_enter(&pm_scan_lock); 512c42872d4Smh27603 if (PM_ISCPU(dip) && PM_CPUPM_DISABLED) { 513c42872d4Smh27603 mutex_exit(&pm_scan_lock); 514c42872d4Smh27603 return (DDI_WALK_CONTINUE); 515c42872d4Smh27603 } 5167c478bd9Sstevel@tonic-gate if (autopm_enabled) 5177c478bd9Sstevel@tonic-gate pm_scan_init(dip); 5187c478bd9Sstevel@tonic-gate mutex_exit(&pm_scan_lock); 519c42872d4Smh27603 break; 520c42872d4Smh27603 } 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate /* 5237c478bd9Sstevel@tonic-gate * Start doing pm on device: ensure pm_scan data structure initiated, 524c42872d4Smh27603 * no need to guarantee a successful scan run. 5257c478bd9Sstevel@tonic-gate */ 5267c478bd9Sstevel@tonic-gate PMD(PMD_SCAN | PMD_IOCTL, ("ioctl: %s: scan %s@%s(%s#%d)\n", cmdstr, 5277c478bd9Sstevel@tonic-gate PM_DEVICE(dip))) 5287c478bd9Sstevel@tonic-gate pm_rescan(dip); 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 5317c478bd9Sstevel@tonic-gate } 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate /* 5347c478bd9Sstevel@tonic-gate * Bring devices to full power level, then stop scan 5357c478bd9Sstevel@tonic-gate */ 5367c478bd9Sstevel@tonic-gate int 5377c478bd9Sstevel@tonic-gate pm_stop_pm_walk(dev_info_t *dip, void *arg) 5387c478bd9Sstevel@tonic-gate { 5397c478bd9Sstevel@tonic-gate pm_info_t *info = PM_GET_PM_INFO(dip); 540c42872d4Smh27603 int cmd = *((int *)arg); 5419681b4a1Skchow #ifdef PMDDEBUG 542c42872d4Smh27603 char *cmdstr = pm_decode_cmd(cmd); 5439681b4a1Skchow #endif 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate if (!info) 5467c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 547c42872d4Smh27603 548c42872d4Smh27603 switch (cmd) { 549c42872d4Smh27603 case PM_STOP_PM: 550c42872d4Smh27603 /* 551c42872d4Smh27603 * If CPU devices are being managed independently, then don't 552c42872d4Smh27603 * stop them as part of PM_STOP_PM. Only stop them as part of 553c42872d4Smh27603 * PM_STOP_CPUPM and PM_RESET_PM. 554c42872d4Smh27603 */ 555c42872d4Smh27603 if (PM_ISCPU(dip) && PM_CPUPM_ENABLED) 556c42872d4Smh27603 return (DDI_WALK_CONTINUE); 557c42872d4Smh27603 break; 558c42872d4Smh27603 case PM_STOP_CPUPM: 559c42872d4Smh27603 /* 560c42872d4Smh27603 * If stopping CPU devices and this device is not marked 561c42872d4Smh27603 * as a CPU device, then skip. 562c42872d4Smh27603 */ 563c42872d4Smh27603 if (!PM_ISCPU(dip)) 564c42872d4Smh27603 return (DDI_WALK_CONTINUE); 565c42872d4Smh27603 break; 566c42872d4Smh27603 } 567c42872d4Smh27603 5687c478bd9Sstevel@tonic-gate /* 5697c478bd9Sstevel@tonic-gate * Stop the current scan, and then bring it back to normal power. 5707c478bd9Sstevel@tonic-gate */ 5717c478bd9Sstevel@tonic-gate if (!PM_ISBC(dip)) { 5727c478bd9Sstevel@tonic-gate PMD(PMD_SCAN | PMD_IOCTL, ("ioctl: %s: stop scan for " 5737c478bd9Sstevel@tonic-gate "%s@%s(%s#%d)\n", cmdstr, PM_DEVICE(dip))) 5747c478bd9Sstevel@tonic-gate pm_scan_stop(dip); 5757c478bd9Sstevel@tonic-gate } 5767c478bd9Sstevel@tonic-gate 5777c478bd9Sstevel@tonic-gate if (!PM_ISBC(dip) && !PM_ISDIRECT(dip) && 5787c478bd9Sstevel@tonic-gate !pm_all_at_normal(dip)) { 5797c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 5807c478bd9Sstevel@tonic-gate if (info->pmi_dev_pm_state & PM_DETACHING) { 5817c478bd9Sstevel@tonic-gate PMD(PMD_ALLNORM, ("ioctl: %s: deferring " 5827c478bd9Sstevel@tonic-gate "all_to_normal because %s@%s(%s#%d) is detaching\n", 5837c478bd9Sstevel@tonic-gate cmdstr, PM_DEVICE(dip))) 5847c478bd9Sstevel@tonic-gate info->pmi_dev_pm_state |= PM_ALLNORM_DEFERRED; 5857c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 5867c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 5897c478bd9Sstevel@tonic-gate if (pm_all_to_normal(dip, PM_CANBLOCK_FAIL) != DDI_SUCCESS) { 5907c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: could not bring %s@%s" 5917c478bd9Sstevel@tonic-gate "(%s#%d) to normal\n", cmdstr, PM_DEVICE(dip))) 5927c478bd9Sstevel@tonic-gate } 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 5967c478bd9Sstevel@tonic-gate } 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate static int 5997c478bd9Sstevel@tonic-gate pm_start_idledown(dev_info_t *dip, void *arg) 6007c478bd9Sstevel@tonic-gate { 6017c478bd9Sstevel@tonic-gate int flag = (int)(intptr_t)arg; 6027c478bd9Sstevel@tonic-gate pm_scan_t *scanp = PM_GET_PM_SCAN(dip); 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate if (!scanp) 6057c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 6087c478bd9Sstevel@tonic-gate scanp->ps_idle_down |= flag; 6097c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 6107c478bd9Sstevel@tonic-gate pm_rescan(dip); 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 6137c478bd9Sstevel@tonic-gate } 6147c478bd9Sstevel@tonic-gate 6157c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6167c478bd9Sstevel@tonic-gate static int 6177c478bd9Sstevel@tonic-gate pm_end_idledown(dev_info_t *dip, void *ignore) 6187c478bd9Sstevel@tonic-gate { 6197c478bd9Sstevel@tonic-gate pm_scan_t *scanp = PM_GET_PM_SCAN(dip); 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate if (!scanp) 6227c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 6257c478bd9Sstevel@tonic-gate /* 6267c478bd9Sstevel@tonic-gate * The PMID_TIMERS bits are place holder till idledown expires. 6277c478bd9Sstevel@tonic-gate * The bits are also the base for regenerating PMID_SCANS bits. 6287c478bd9Sstevel@tonic-gate * While it's up to scan thread to clear up the PMID_SCANS bits 6297c478bd9Sstevel@tonic-gate * after each scan run, PMID_TIMERS ensure aggressive scan down 6307c478bd9Sstevel@tonic-gate * performance throughout the idledown period. 6317c478bd9Sstevel@tonic-gate */ 6327c478bd9Sstevel@tonic-gate scanp->ps_idle_down &= ~PMID_TIMERS; 6337c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 6367c478bd9Sstevel@tonic-gate } 6377c478bd9Sstevel@tonic-gate 6387c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6397c478bd9Sstevel@tonic-gate static void 6407c478bd9Sstevel@tonic-gate pm_end_idledown_walk(void *ignore) 6417c478bd9Sstevel@tonic-gate { 6427c478bd9Sstevel@tonic-gate PMD(PMD_IDLEDOWN, ("ioctl: end_idledown: idledown_id(%lx) timer is " 6437c478bd9Sstevel@tonic-gate "off\n", (ulong_t)pmstp->pm_idledown_id)); 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate mutex_enter(&pm_scan_lock); 6467c478bd9Sstevel@tonic-gate pmstp->pm_idledown_id = 0; 6477c478bd9Sstevel@tonic-gate mutex_exit(&pm_scan_lock); 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), pm_end_idledown, NULL); 6507c478bd9Sstevel@tonic-gate } 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate /* 6537c478bd9Sstevel@tonic-gate * pm_timeout_idledown - keep idledown effect for 10 seconds. 6547c478bd9Sstevel@tonic-gate * 6557c478bd9Sstevel@tonic-gate * Return 0 if another competing caller scheduled idledown timeout, 6567c478bd9Sstevel@tonic-gate * otherwise, return idledown timeout_id. 6577c478bd9Sstevel@tonic-gate */ 6587c478bd9Sstevel@tonic-gate static timeout_id_t 6597c478bd9Sstevel@tonic-gate pm_timeout_idledown(void) 6607c478bd9Sstevel@tonic-gate { 6617c478bd9Sstevel@tonic-gate timeout_id_t to_id; 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate /* 6647c478bd9Sstevel@tonic-gate * Keep idle-down in effect for either 10 seconds 6657c478bd9Sstevel@tonic-gate * or length of a scan interval, which ever is greater. 6667c478bd9Sstevel@tonic-gate */ 6677c478bd9Sstevel@tonic-gate mutex_enter(&pm_scan_lock); 6687c478bd9Sstevel@tonic-gate if (pmstp->pm_idledown_id != 0) { 6697c478bd9Sstevel@tonic-gate to_id = pmstp->pm_idledown_id; 6707c478bd9Sstevel@tonic-gate pmstp->pm_idledown_id = 0; 6717c478bd9Sstevel@tonic-gate mutex_exit(&pm_scan_lock); 6727c478bd9Sstevel@tonic-gate (void) untimeout(to_id); 6737c478bd9Sstevel@tonic-gate mutex_enter(&pm_scan_lock); 6747c478bd9Sstevel@tonic-gate if (pmstp->pm_idledown_id != 0) { 6757c478bd9Sstevel@tonic-gate PMD(PMD_IDLEDOWN, ("ioctl: timeout_idledown: " 6767c478bd9Sstevel@tonic-gate "another caller got it, idledown_id(%lx)!\n", 6777c478bd9Sstevel@tonic-gate (ulong_t)pmstp->pm_idledown_id)) 6787c478bd9Sstevel@tonic-gate mutex_exit(&pm_scan_lock); 6797c478bd9Sstevel@tonic-gate return (0); 6807c478bd9Sstevel@tonic-gate } 6817c478bd9Sstevel@tonic-gate } 6827c478bd9Sstevel@tonic-gate pmstp->pm_idledown_id = timeout(pm_end_idledown_walk, NULL, 6837c478bd9Sstevel@tonic-gate PM_IDLEDOWN_TIME * hz); 6847c478bd9Sstevel@tonic-gate PMD(PMD_IDLEDOWN, ("ioctl: timeout_idledown: idledown_id(%lx)\n", 6857c478bd9Sstevel@tonic-gate (ulong_t)pmstp->pm_idledown_id)) 6867c478bd9Sstevel@tonic-gate mutex_exit(&pm_scan_lock); 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate return (pmstp->pm_idledown_id); 6897c478bd9Sstevel@tonic-gate } 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate static int 6927c478bd9Sstevel@tonic-gate pm_chpoll(dev_t dev, short events, int anyyet, short *reventsp, 6937c478bd9Sstevel@tonic-gate struct pollhead **phpp) 6947c478bd9Sstevel@tonic-gate { 6957c478bd9Sstevel@tonic-gate extern struct pollhead pm_pollhead; /* common/os/sunpm.c */ 6967c478bd9Sstevel@tonic-gate int clone; 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate clone = PM_MINOR_TO_CLONE(getminor(dev)); 6997c478bd9Sstevel@tonic-gate PMD(PMD_IOCTL, ("ioctl: pm_chpoll: clone %d\n", clone)) 7007c478bd9Sstevel@tonic-gate if ((events & (POLLIN | POLLRDNORM)) && pm_poll_cnt[clone]) { 7017c478bd9Sstevel@tonic-gate *reventsp |= (POLLIN | POLLRDNORM); 7027c478bd9Sstevel@tonic-gate PMD(PMD_IOCTL, ("ioctl: pm_chpoll: reventsp set\n")) 7037c478bd9Sstevel@tonic-gate } else { 7047c478bd9Sstevel@tonic-gate *reventsp = 0; 7057c478bd9Sstevel@tonic-gate if (!anyyet) { 7067c478bd9Sstevel@tonic-gate PMD(PMD_IOCTL, ("ioctl: pm_chpoll: not anyyet\n")) 7077c478bd9Sstevel@tonic-gate *phpp = &pm_pollhead; 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate #ifdef DEBUG 7107c478bd9Sstevel@tonic-gate else { 7117c478bd9Sstevel@tonic-gate PMD(PMD_IOCTL, ("ioctl: pm_chpoll: anyyet\n")) 7127c478bd9Sstevel@tonic-gate } 7137c478bd9Sstevel@tonic-gate #endif 7147c478bd9Sstevel@tonic-gate } 7157c478bd9Sstevel@tonic-gate return (0); 7167c478bd9Sstevel@tonic-gate } 7177c478bd9Sstevel@tonic-gate 7187c478bd9Sstevel@tonic-gate /* 7197c478bd9Sstevel@tonic-gate * called by pm_dicard_entries to free up the memory. It also decrements 7207c478bd9Sstevel@tonic-gate * pm_poll_cnt, if direct is non zero. 7217c478bd9Sstevel@tonic-gate */ 7227c478bd9Sstevel@tonic-gate static void 7237c478bd9Sstevel@tonic-gate pm_free_entries(psce_t *pscep, int clone, int direct) 7247c478bd9Sstevel@tonic-gate { 7257c478bd9Sstevel@tonic-gate pm_state_change_t *p; 7267c478bd9Sstevel@tonic-gate 7277c478bd9Sstevel@tonic-gate if (pscep) { 7287c478bd9Sstevel@tonic-gate p = pscep->psce_out; 7297c478bd9Sstevel@tonic-gate while (p->size) { 7307c478bd9Sstevel@tonic-gate if (direct) { 7317c478bd9Sstevel@tonic-gate PMD(PMD_IOCTL, ("ioctl: discard: " 7327c478bd9Sstevel@tonic-gate "pm_poll_cnt[%d] is %d before " 7337c478bd9Sstevel@tonic-gate "ASSERT\n", clone, 7347c478bd9Sstevel@tonic-gate pm_poll_cnt[clone])) 7357c478bd9Sstevel@tonic-gate ASSERT(pm_poll_cnt[clone]); 7367c478bd9Sstevel@tonic-gate pm_poll_cnt[clone]--; 7377c478bd9Sstevel@tonic-gate } 7387c478bd9Sstevel@tonic-gate kmem_free(p->physpath, p->size); 7397c478bd9Sstevel@tonic-gate p->size = 0; 7407c478bd9Sstevel@tonic-gate if (p == pscep->psce_last) 7417c478bd9Sstevel@tonic-gate p = pscep->psce_first; 7427c478bd9Sstevel@tonic-gate else 7437c478bd9Sstevel@tonic-gate p++; 7447c478bd9Sstevel@tonic-gate } 7457c478bd9Sstevel@tonic-gate pscep->psce_out = pscep->psce_first; 7467c478bd9Sstevel@tonic-gate pscep->psce_in = pscep->psce_first; 7477c478bd9Sstevel@tonic-gate mutex_exit(&pscep->psce_lock); 7487c478bd9Sstevel@tonic-gate } 7497c478bd9Sstevel@tonic-gate } 7507c478bd9Sstevel@tonic-gate 7517c478bd9Sstevel@tonic-gate /* 7527c478bd9Sstevel@tonic-gate * Discard entries for this clone. Calls pm_free_entries to free up memory. 7537c478bd9Sstevel@tonic-gate */ 7547c478bd9Sstevel@tonic-gate static void 7557c478bd9Sstevel@tonic-gate pm_discard_entries(int clone) 7567c478bd9Sstevel@tonic-gate { 7577c478bd9Sstevel@tonic-gate psce_t *pscep; 7587c478bd9Sstevel@tonic-gate int direct = 0; 7597c478bd9Sstevel@tonic-gate 7607c478bd9Sstevel@tonic-gate mutex_enter(&pm_clone_lock); 7617c478bd9Sstevel@tonic-gate if ((pscep = pm_psc_clone_to_direct(clone)) != NULL) 7627c478bd9Sstevel@tonic-gate direct = 1; 7637c478bd9Sstevel@tonic-gate pm_free_entries(pscep, clone, direct); 7647c478bd9Sstevel@tonic-gate pscep = pm_psc_clone_to_interest(clone); 7657c478bd9Sstevel@tonic-gate pm_free_entries(pscep, clone, 0); 7667c478bd9Sstevel@tonic-gate mutex_exit(&pm_clone_lock); 7677c478bd9Sstevel@tonic-gate } 7687c478bd9Sstevel@tonic-gate 769c42872d4Smh27603 770c42872d4Smh27603 static void 771c42872d4Smh27603 pm_set_idle_threshold(dev_info_t *dip, int thresh, int flag) 7727c478bd9Sstevel@tonic-gate { 7737c478bd9Sstevel@tonic-gate if (!PM_ISBC(dip) && !PM_ISDIRECT(dip)) { 7747c478bd9Sstevel@tonic-gate switch (DEVI(dip)->devi_pm_flags & PMC_THRESH_ALL) { 7757c478bd9Sstevel@tonic-gate case PMC_DEF_THRESH: 776c42872d4Smh27603 case PMC_CPU_THRESH: 777c42872d4Smh27603 PMD(PMD_IOCTL, ("ioctl: set_idle_threshold: set " 7787c478bd9Sstevel@tonic-gate "%s@%s(%s#%d) default thresh to 0t%d\n", 779c42872d4Smh27603 PM_DEVICE(dip), thresh)) 780c42872d4Smh27603 pm_set_device_threshold(dip, thresh, flag); 7817c478bd9Sstevel@tonic-gate break; 7827c478bd9Sstevel@tonic-gate default: 7837c478bd9Sstevel@tonic-gate break; 7847c478bd9Sstevel@tonic-gate } 7857c478bd9Sstevel@tonic-gate } 786c42872d4Smh27603 } 7877c478bd9Sstevel@tonic-gate 788c42872d4Smh27603 static int 789c42872d4Smh27603 pm_set_idle_thresh_walk(dev_info_t *dip, void *arg) 790c42872d4Smh27603 { 791c42872d4Smh27603 int cmd = *((int *)arg); 792c42872d4Smh27603 793c42872d4Smh27603 if (!PM_GET_PM_INFO(dip)) 794c42872d4Smh27603 return (DDI_WALK_CONTINUE); 795c42872d4Smh27603 796c42872d4Smh27603 switch (cmd) { 797c42872d4Smh27603 case PM_SET_SYSTEM_THRESHOLD: 798c42872d4Smh27603 if (DEVI(dip)->devi_pm_flags & PMC_CPU_THRESH) 799c42872d4Smh27603 break; 800c42872d4Smh27603 pm_set_idle_threshold(dip, pm_system_idle_threshold, 801c42872d4Smh27603 PMC_DEF_THRESH); 8027c478bd9Sstevel@tonic-gate pm_rescan(dip); 803c42872d4Smh27603 break; 804c42872d4Smh27603 case PM_SET_CPU_THRESHOLD: 805c42872d4Smh27603 if (!PM_ISCPU(dip)) 806c42872d4Smh27603 break; 807c42872d4Smh27603 pm_set_idle_threshold(dip, pm_cpu_idle_threshold, 808c42872d4Smh27603 PMC_CPU_THRESH); 809c42872d4Smh27603 pm_rescan(dip); 810c42872d4Smh27603 break; 811c42872d4Smh27603 } 8127c478bd9Sstevel@tonic-gate 8137c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 8147c478bd9Sstevel@tonic-gate } 8157c478bd9Sstevel@tonic-gate 8167c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8177c478bd9Sstevel@tonic-gate static int 8187c478bd9Sstevel@tonic-gate pm_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 8197c478bd9Sstevel@tonic-gate { 8207c478bd9Sstevel@tonic-gate dev_t dev; 8217c478bd9Sstevel@tonic-gate int instance; 8227c478bd9Sstevel@tonic-gate 8237c478bd9Sstevel@tonic-gate switch (infocmd) { 8247c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 8257c478bd9Sstevel@tonic-gate if (pmstp->pm_instance == -1) 8267c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8277c478bd9Sstevel@tonic-gate *result = pmstp->pm_dip; 8287c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 8297c478bd9Sstevel@tonic-gate 8307c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 8317c478bd9Sstevel@tonic-gate dev = (dev_t)arg; 8327c478bd9Sstevel@tonic-gate instance = getminor(dev) >> 8; 8337c478bd9Sstevel@tonic-gate *result = (void *)(uintptr_t)instance; 8347c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 8357c478bd9Sstevel@tonic-gate 8367c478bd9Sstevel@tonic-gate default: 8377c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8387c478bd9Sstevel@tonic-gate } 8397c478bd9Sstevel@tonic-gate } 8407c478bd9Sstevel@tonic-gate 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate /*ARGSUSED1*/ 8437c478bd9Sstevel@tonic-gate static int 8447c478bd9Sstevel@tonic-gate pm_open(dev_t *devp, int flag, int otyp, cred_t *cr) 8457c478bd9Sstevel@tonic-gate { 8467c478bd9Sstevel@tonic-gate int clone; 8477c478bd9Sstevel@tonic-gate 8487c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 8497c478bd9Sstevel@tonic-gate return (EINVAL); 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate mutex_enter(&pm_clone_lock); 8527c478bd9Sstevel@tonic-gate for (clone = 1; clone < PM_MAX_CLONE; clone++) 8537c478bd9Sstevel@tonic-gate if (!pmstp->pm_clones[clone]) 8547c478bd9Sstevel@tonic-gate break; 8557c478bd9Sstevel@tonic-gate 8567c478bd9Sstevel@tonic-gate if (clone == PM_MAX_CLONE) { 8577c478bd9Sstevel@tonic-gate mutex_exit(&pm_clone_lock); 8587c478bd9Sstevel@tonic-gate return (ENXIO); 8597c478bd9Sstevel@tonic-gate } 8607c478bd9Sstevel@tonic-gate pmstp->pm_cred[clone] = cr; 8617c478bd9Sstevel@tonic-gate crhold(cr); 8627c478bd9Sstevel@tonic-gate 8637c478bd9Sstevel@tonic-gate *devp = makedevice(getmajor(*devp), (pmstp->pm_instance << 8) + clone); 8647c478bd9Sstevel@tonic-gate pmstp->pm_clones[clone] = 1; 8657c478bd9Sstevel@tonic-gate mutex_exit(&pm_clone_lock); 8667c478bd9Sstevel@tonic-gate 8677c478bd9Sstevel@tonic-gate return (0); 8687c478bd9Sstevel@tonic-gate } 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate /*ARGSUSED1*/ 8717c478bd9Sstevel@tonic-gate static int 8727c478bd9Sstevel@tonic-gate pm_close(dev_t dev, int flag, int otyp, cred_t *cr) 8737c478bd9Sstevel@tonic-gate { 8747c478bd9Sstevel@tonic-gate int clone; 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 8777c478bd9Sstevel@tonic-gate return (EINVAL); 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate clone = PM_MINOR_TO_CLONE(getminor(dev)); 8807c478bd9Sstevel@tonic-gate PMD(PMD_CLOSE, ("pm_close: minor %x, clone %x\n", getminor(dev), 8817c478bd9Sstevel@tonic-gate clone)) 8827c478bd9Sstevel@tonic-gate 8837c478bd9Sstevel@tonic-gate /* 8847c478bd9Sstevel@tonic-gate * Walk the entire device tree to find the corresponding 8857c478bd9Sstevel@tonic-gate * device and operate on it. 8867c478bd9Sstevel@tonic-gate */ 8877c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), pm_close_direct_pm_device, 8887c478bd9Sstevel@tonic-gate (void *) &clone); 8897c478bd9Sstevel@tonic-gate 8907c478bd9Sstevel@tonic-gate crfree(pmstp->pm_cred[clone]); 8917c478bd9Sstevel@tonic-gate pmstp->pm_cred[clone] = 0; 8927c478bd9Sstevel@tonic-gate pmstp->pm_clones[clone] = 0; 8937c478bd9Sstevel@tonic-gate pm_discard_entries(clone); 8947c478bd9Sstevel@tonic-gate ASSERT(pm_poll_cnt[clone] == 0); 8957c478bd9Sstevel@tonic-gate pm_deregister_watcher(clone, NULL); 8967c478bd9Sstevel@tonic-gate return (0); 8977c478bd9Sstevel@tonic-gate } 8987c478bd9Sstevel@tonic-gate 8997c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 9007c478bd9Sstevel@tonic-gate static int 9017c478bd9Sstevel@tonic-gate pm_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *cr, int *rval_p) 9027c478bd9Sstevel@tonic-gate { 9037c478bd9Sstevel@tonic-gate struct pm_cmd_info *pc_info(int); 9047c478bd9Sstevel@tonic-gate struct pm_cmd_info *pcip = pc_info(cmd); 9057c478bd9Sstevel@tonic-gate pm_req_t req; 9067c478bd9Sstevel@tonic-gate dev_info_t *dip = NULL; 9077c478bd9Sstevel@tonic-gate pm_info_t *info = NULL; 9087c478bd9Sstevel@tonic-gate int clone; 9097c478bd9Sstevel@tonic-gate char *cmdstr = pm_decode_cmd(cmd); 9107c478bd9Sstevel@tonic-gate /* 9117c478bd9Sstevel@tonic-gate * To keep devinfo nodes from going away while we're holding a 9127c478bd9Sstevel@tonic-gate * pointer to their dip, pm_name_to_dip() optionally holds 9137c478bd9Sstevel@tonic-gate * the devinfo node. If we've done that, we set dipheld 9147c478bd9Sstevel@tonic-gate * so we know at the end of the ioctl processing to release the 9157c478bd9Sstevel@tonic-gate * node again. 9167c478bd9Sstevel@tonic-gate */ 9177c478bd9Sstevel@tonic-gate int dipheld = 0; 9187c478bd9Sstevel@tonic-gate int icount = 0; 9197c478bd9Sstevel@tonic-gate int i; 9207c478bd9Sstevel@tonic-gate int comps; 9217c478bd9Sstevel@tonic-gate size_t lencopied; 9227c478bd9Sstevel@tonic-gate int ret = ENOTTY; 9237c478bd9Sstevel@tonic-gate int curpower; 9247c478bd9Sstevel@tonic-gate char who[MAXNAMELEN]; 9257c478bd9Sstevel@tonic-gate size_t wholen; /* copyinstr length */ 9267c478bd9Sstevel@tonic-gate size_t deplen = MAXNAMELEN; 9277c478bd9Sstevel@tonic-gate char *dep, i_dep_buf[MAXNAMELEN]; 928*2df1fe9cSrandyf char pathbuf[MAXNAMELEN]; 9297c478bd9Sstevel@tonic-gate struct pm_component *cp; 9307c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 9317c478bd9Sstevel@tonic-gate pm_state_change32_t *pscp32; 9327c478bd9Sstevel@tonic-gate pm_state_change32_t psc32; 933*2df1fe9cSrandyf pm_searchargs32_t psa32; 9347c478bd9Sstevel@tonic-gate size_t copysize32; 9357c478bd9Sstevel@tonic-gate #endif 9367c478bd9Sstevel@tonic-gate pm_state_change_t *pscp; 9377c478bd9Sstevel@tonic-gate pm_state_change_t psc; 938*2df1fe9cSrandyf pm_searchargs_t psa; 939*2df1fe9cSrandyf char listname[MAXCOPYBUF]; 940*2df1fe9cSrandyf char manufacturer[MAXCOPYBUF]; 941*2df1fe9cSrandyf char product[MAXCOPYBUF]; 9427c478bd9Sstevel@tonic-gate size_t copysize; 9437c478bd9Sstevel@tonic-gate 9447c478bd9Sstevel@tonic-gate PMD(PMD_IOCTL, ("ioctl: %s: begin\n", cmdstr)) 9457c478bd9Sstevel@tonic-gate 9467c478bd9Sstevel@tonic-gate #ifdef DEBUG 9477c478bd9Sstevel@tonic-gate if (cmd == 666) { 9487c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), print_info, NULL); 9497c478bd9Sstevel@tonic-gate return (0); 9507c478bd9Sstevel@tonic-gate } 9517c478bd9Sstevel@tonic-gate ret = 0x0badcafe; /* sanity checking */ 9527c478bd9Sstevel@tonic-gate pm_cmd = cmd; /* for ASSERT debugging */ 9537c478bd9Sstevel@tonic-gate pm_cmd_string = cmdstr; /* for ASSERT debugging */ 9547c478bd9Sstevel@tonic-gate #endif 9557c478bd9Sstevel@tonic-gate 9567c478bd9Sstevel@tonic-gate 9577c478bd9Sstevel@tonic-gate if (pcip == NULL) { 9587c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: unknown command %d\n", cmd)) 9597c478bd9Sstevel@tonic-gate return (ENOTTY); 9607c478bd9Sstevel@tonic-gate } 9617c478bd9Sstevel@tonic-gate if (pcip == NULL || pcip->supported == 0) { 9627c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: command %s no longer supported\n", 9637c478bd9Sstevel@tonic-gate pcip->name)) 9647c478bd9Sstevel@tonic-gate return (ENOTTY); 9657c478bd9Sstevel@tonic-gate } 9667c478bd9Sstevel@tonic-gate 9677c478bd9Sstevel@tonic-gate wholen = 0; 9687c478bd9Sstevel@tonic-gate dep = i_dep_buf; 9697c478bd9Sstevel@tonic-gate i_dep_buf[0] = 0; 9707c478bd9Sstevel@tonic-gate clone = PM_MINOR_TO_CLONE(getminor(dev)); 9717c478bd9Sstevel@tonic-gate if (!pm_perms(pcip->permission, pmstp->pm_cred[clone])) { 9727c478bd9Sstevel@tonic-gate ret = EPERM; 9737c478bd9Sstevel@tonic-gate return (ret); 9747c478bd9Sstevel@tonic-gate } 9757c478bd9Sstevel@tonic-gate switch (pcip->str_type) { 9767c478bd9Sstevel@tonic-gate case PM_REQ: 977*2df1fe9cSrandyf { 9787c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 9797c478bd9Sstevel@tonic-gate if ((mode & DATAMODEL_MASK) == DATAMODEL_ILP32) { 9807c478bd9Sstevel@tonic-gate pm_req32_t req32; 9817c478bd9Sstevel@tonic-gate 9827c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, &req32, 9837c478bd9Sstevel@tonic-gate sizeof (req32), mode) != 0) { 9847c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: ddi_copyin " 9857c478bd9Sstevel@tonic-gate "EFAULT\n\n", cmdstr)) 9867c478bd9Sstevel@tonic-gate ret = EFAULT; 9877c478bd9Sstevel@tonic-gate break; 9887c478bd9Sstevel@tonic-gate } 9897c478bd9Sstevel@tonic-gate req.component = req32.component; 9907c478bd9Sstevel@tonic-gate req.value = req32.value; 9917c478bd9Sstevel@tonic-gate req.datasize = req32.datasize; 9927c478bd9Sstevel@tonic-gate if (pcip->inargs & INWHO) { 9937c478bd9Sstevel@tonic-gate ret = copyinstr((char *)(uintptr_t) 9947c478bd9Sstevel@tonic-gate req32.physpath, who, MAXNAMELEN, &wholen); 9957c478bd9Sstevel@tonic-gate if (ret) { 9967c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: " 9977c478bd9Sstevel@tonic-gate "copyinstr fails returning %d\n", 9987c478bd9Sstevel@tonic-gate cmdstr, ret)) 9997c478bd9Sstevel@tonic-gate break; 10007c478bd9Sstevel@tonic-gate } 10017c478bd9Sstevel@tonic-gate req.physpath = who; 1002*2df1fe9cSrandyf PMD(PMD_IOCTL, ("ioctl: %s: physpath=%s\n", 1003*2df1fe9cSrandyf cmdstr, req.physpath)) 10047c478bd9Sstevel@tonic-gate } 10057c478bd9Sstevel@tonic-gate if (pcip->inargs & INDATA) { 10067c478bd9Sstevel@tonic-gate req.data = (void *)(uintptr_t)req32.data; 10077c478bd9Sstevel@tonic-gate req.datasize = req32.datasize; 10087c478bd9Sstevel@tonic-gate } else { 10097c478bd9Sstevel@tonic-gate req.data = NULL; 10107c478bd9Sstevel@tonic-gate req.datasize = 0; 10117c478bd9Sstevel@tonic-gate } 10127c478bd9Sstevel@tonic-gate switch (pcip->diptype) { 10137c478bd9Sstevel@tonic-gate case DIP: 10147c478bd9Sstevel@tonic-gate if (!(dip = 10157c478bd9Sstevel@tonic-gate pm_name_to_dip(req.physpath, 1))) { 10167c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: " 10177c478bd9Sstevel@tonic-gate "pm_name_to_dip for %s failed\n", 10187c478bd9Sstevel@tonic-gate cmdstr, req.physpath)) 10197c478bd9Sstevel@tonic-gate return (ENODEV); 10207c478bd9Sstevel@tonic-gate } 10217c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 10227c478bd9Sstevel@tonic-gate dipheld++; 10237c478bd9Sstevel@tonic-gate break; 10247c478bd9Sstevel@tonic-gate case NODIP: 10257c478bd9Sstevel@tonic-gate break; 10267c478bd9Sstevel@tonic-gate default: 10277c478bd9Sstevel@tonic-gate /* 10287c478bd9Sstevel@tonic-gate * Internal error, invalid ioctl description 10297c478bd9Sstevel@tonic-gate * force debug entry even if pm_debug not set 10307c478bd9Sstevel@tonic-gate */ 10317c478bd9Sstevel@tonic-gate #ifdef DEBUG 10327c478bd9Sstevel@tonic-gate pm_log("invalid diptype %d for cmd %d (%s)\n", 10337c478bd9Sstevel@tonic-gate pcip->diptype, cmd, pcip->name); 10347c478bd9Sstevel@tonic-gate #endif 10357c478bd9Sstevel@tonic-gate ASSERT(0); 10367c478bd9Sstevel@tonic-gate return (EIO); 10377c478bd9Sstevel@tonic-gate } 10387c478bd9Sstevel@tonic-gate if (pcip->inargs & INDATAINT) { 10397c478bd9Sstevel@tonic-gate int32_t int32buf; 10407c478bd9Sstevel@tonic-gate int32_t *i32p; 10417c478bd9Sstevel@tonic-gate int *ip; 10427c478bd9Sstevel@tonic-gate icount = req32.datasize / sizeof (int32_t); 10437c478bd9Sstevel@tonic-gate if (icount <= 0) { 10447c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: datasize" 10457c478bd9Sstevel@tonic-gate " 0 or neg EFAULT\n\n", cmdstr)) 10467c478bd9Sstevel@tonic-gate ret = EFAULT; 10477c478bd9Sstevel@tonic-gate break; 10487c478bd9Sstevel@tonic-gate } 10497c478bd9Sstevel@tonic-gate ASSERT(!(pcip->inargs & INDATASTRING)); 10507c478bd9Sstevel@tonic-gate req.datasize = icount * sizeof (int); 10517c478bd9Sstevel@tonic-gate req.data = kmem_alloc(req.datasize, KM_SLEEP); 10527c478bd9Sstevel@tonic-gate ip = req.data; 10537c478bd9Sstevel@tonic-gate ret = 0; 10547c478bd9Sstevel@tonic-gate for (i = 0, 10557c478bd9Sstevel@tonic-gate i32p = (int32_t *)(uintptr_t)req32.data; 10567c478bd9Sstevel@tonic-gate i < icount; i++, i32p++) { 10577c478bd9Sstevel@tonic-gate if (ddi_copyin((void *)i32p, &int32buf, 10587c478bd9Sstevel@tonic-gate sizeof (int32_t), mode)) { 10597c478bd9Sstevel@tonic-gate kmem_free(req.data, 10607c478bd9Sstevel@tonic-gate req.datasize); 10617c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: " 10627c478bd9Sstevel@tonic-gate "entry %d EFAULT\n", 10637c478bd9Sstevel@tonic-gate cmdstr, i)) 10647c478bd9Sstevel@tonic-gate ret = EFAULT; 10657c478bd9Sstevel@tonic-gate break; 10667c478bd9Sstevel@tonic-gate } 10677c478bd9Sstevel@tonic-gate *ip++ = (int)int32buf; 10687c478bd9Sstevel@tonic-gate } 10697c478bd9Sstevel@tonic-gate if (ret) 10707c478bd9Sstevel@tonic-gate break; 10717c478bd9Sstevel@tonic-gate } 10727c478bd9Sstevel@tonic-gate if (pcip->inargs & INDATASTRING) { 10737c478bd9Sstevel@tonic-gate ASSERT(!(pcip->inargs & INDATAINT)); 10747c478bd9Sstevel@tonic-gate ASSERT(pcip->deptype == DEP); 10757c478bd9Sstevel@tonic-gate if (req32.data != NULL) { 10767c478bd9Sstevel@tonic-gate if (copyinstr((void *)(uintptr_t) 1077*2df1fe9cSrandyf req32.data, dep, deplen, NULL)) { 10787c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: " 10797c478bd9Sstevel@tonic-gate "0x%p dep size %lx, EFAULT" 10807c478bd9Sstevel@tonic-gate "\n", cmdstr, 10817c478bd9Sstevel@tonic-gate (void *)req.data, deplen)) 10827c478bd9Sstevel@tonic-gate ret = EFAULT; 10837c478bd9Sstevel@tonic-gate break; 10847c478bd9Sstevel@tonic-gate } 10857c478bd9Sstevel@tonic-gate #ifdef DEBUG 10867c478bd9Sstevel@tonic-gate else { 10877c478bd9Sstevel@tonic-gate PMD(PMD_DEP, ("ioctl: %s: " 10887c478bd9Sstevel@tonic-gate "dep %s\n", cmdstr, dep)) 10897c478bd9Sstevel@tonic-gate } 10907c478bd9Sstevel@tonic-gate #endif 10917c478bd9Sstevel@tonic-gate } else { 10927c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: no " 10937c478bd9Sstevel@tonic-gate "dependent\n", cmdstr)) 10947c478bd9Sstevel@tonic-gate ret = EINVAL; 10957c478bd9Sstevel@tonic-gate break; 10967c478bd9Sstevel@tonic-gate } 10977c478bd9Sstevel@tonic-gate } 10987c478bd9Sstevel@tonic-gate } else 10997c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 11007c478bd9Sstevel@tonic-gate { 11017c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, 11027c478bd9Sstevel@tonic-gate &req, sizeof (req), mode) != 0) { 11037c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: ddi_copyin " 11047c478bd9Sstevel@tonic-gate "EFAULT\n\n", cmdstr)) 11057c478bd9Sstevel@tonic-gate ret = EFAULT; 11067c478bd9Sstevel@tonic-gate break; 11077c478bd9Sstevel@tonic-gate } 11087c478bd9Sstevel@tonic-gate if (pcip->inargs & INWHO) { 11097c478bd9Sstevel@tonic-gate ret = copyinstr((char *)req.physpath, who, 11107c478bd9Sstevel@tonic-gate MAXNAMELEN, &wholen); 11117c478bd9Sstevel@tonic-gate if (ret) { 11127c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s copyinstr" 11137c478bd9Sstevel@tonic-gate " fails returning %d\n", cmdstr, 11147c478bd9Sstevel@tonic-gate ret)) 11157c478bd9Sstevel@tonic-gate break; 11167c478bd9Sstevel@tonic-gate } 11177c478bd9Sstevel@tonic-gate req.physpath = who; 1118*2df1fe9cSrandyf PMD(PMD_IOCTL, ("ioctl: %s: physpath=%s\n", 1119*2df1fe9cSrandyf cmdstr, req.physpath)) 11207c478bd9Sstevel@tonic-gate } 11217c478bd9Sstevel@tonic-gate if (!(pcip->inargs & INDATA)) { 11227c478bd9Sstevel@tonic-gate req.data = NULL; 11237c478bd9Sstevel@tonic-gate req.datasize = 0; 11247c478bd9Sstevel@tonic-gate } 11257c478bd9Sstevel@tonic-gate switch (pcip->diptype) { 11267c478bd9Sstevel@tonic-gate case DIP: 11277c478bd9Sstevel@tonic-gate if (!(dip = 11287c478bd9Sstevel@tonic-gate pm_name_to_dip(req.physpath, 1))) { 11297c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: " 11307c478bd9Sstevel@tonic-gate "pm_name_to_dip for %s failed\n", 11317c478bd9Sstevel@tonic-gate cmdstr, req.physpath)) 11327c478bd9Sstevel@tonic-gate return (ENODEV); 11337c478bd9Sstevel@tonic-gate } 11347c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 11357c478bd9Sstevel@tonic-gate dipheld++; 11367c478bd9Sstevel@tonic-gate break; 11377c478bd9Sstevel@tonic-gate case NODIP: 11387c478bd9Sstevel@tonic-gate break; 11397c478bd9Sstevel@tonic-gate default: 11407c478bd9Sstevel@tonic-gate /* 11417c478bd9Sstevel@tonic-gate * Internal error, invalid ioctl description 11427c478bd9Sstevel@tonic-gate * force debug entry even if pm_debug not set 11437c478bd9Sstevel@tonic-gate */ 11447c478bd9Sstevel@tonic-gate #ifdef DEBUG 11457c478bd9Sstevel@tonic-gate pm_log("invalid diptype %d for cmd %d (%s)\n", 11467c478bd9Sstevel@tonic-gate pcip->diptype, cmd, pcip->name); 11477c478bd9Sstevel@tonic-gate #endif 11487c478bd9Sstevel@tonic-gate ASSERT(0); 11497c478bd9Sstevel@tonic-gate return (EIO); 11507c478bd9Sstevel@tonic-gate } 11517c478bd9Sstevel@tonic-gate if (pcip->inargs & INDATAINT) { 11527c478bd9Sstevel@tonic-gate int *ip; 11537c478bd9Sstevel@tonic-gate 11547c478bd9Sstevel@tonic-gate ASSERT(!(pcip->inargs & INDATASTRING)); 11557c478bd9Sstevel@tonic-gate ip = req.data; 11567c478bd9Sstevel@tonic-gate icount = req.datasize / sizeof (int); 11577c478bd9Sstevel@tonic-gate if (icount <= 0) { 11587c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: datasize" 11597c478bd9Sstevel@tonic-gate " 0 or neg EFAULT\n\n", cmdstr)) 11607c478bd9Sstevel@tonic-gate ret = EFAULT; 11617c478bd9Sstevel@tonic-gate break; 11627c478bd9Sstevel@tonic-gate } 11637c478bd9Sstevel@tonic-gate req.data = kmem_alloc(req.datasize, KM_SLEEP); 11647c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)ip, req.data, 11657c478bd9Sstevel@tonic-gate req.datasize, mode) != 0) { 11667c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: ddi_copyin " 11677c478bd9Sstevel@tonic-gate "EFAULT\n\n", cmdstr)) 11687c478bd9Sstevel@tonic-gate ret = EFAULT; 11697c478bd9Sstevel@tonic-gate break; 11707c478bd9Sstevel@tonic-gate } 11717c478bd9Sstevel@tonic-gate } 11727c478bd9Sstevel@tonic-gate if (pcip->inargs & INDATASTRING) { 11737c478bd9Sstevel@tonic-gate ASSERT(!(pcip->inargs & INDATAINT)); 11747c478bd9Sstevel@tonic-gate ASSERT(pcip->deptype == DEP); 11757c478bd9Sstevel@tonic-gate if (req.data != NULL) { 11767c478bd9Sstevel@tonic-gate if (copyinstr((caddr_t)req.data, 1177*2df1fe9cSrandyf dep, deplen, NULL)) { 11787c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: " 11797c478bd9Sstevel@tonic-gate "0x%p dep size %lu, " 11807c478bd9Sstevel@tonic-gate "EFAULT\n", cmdstr, 11817c478bd9Sstevel@tonic-gate (void *)req.data, deplen)) 11827c478bd9Sstevel@tonic-gate ret = EFAULT; 11837c478bd9Sstevel@tonic-gate break; 11847c478bd9Sstevel@tonic-gate } 11857c478bd9Sstevel@tonic-gate #ifdef DEBUG 11867c478bd9Sstevel@tonic-gate else { 11877c478bd9Sstevel@tonic-gate PMD(PMD_DEP, ("ioctl: %s: " 11887c478bd9Sstevel@tonic-gate "dep %s\n", cmdstr, dep)) 11897c478bd9Sstevel@tonic-gate } 11907c478bd9Sstevel@tonic-gate #endif 11917c478bd9Sstevel@tonic-gate } else { 11927c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: no " 11937c478bd9Sstevel@tonic-gate "dependent\n", cmdstr)) 11947c478bd9Sstevel@tonic-gate ret = EINVAL; 11957c478bd9Sstevel@tonic-gate break; 11967c478bd9Sstevel@tonic-gate } 11977c478bd9Sstevel@tonic-gate } 11987c478bd9Sstevel@tonic-gate } 11997c478bd9Sstevel@tonic-gate /* 12007c478bd9Sstevel@tonic-gate * Now we've got all the args in for the commands that 12017c478bd9Sstevel@tonic-gate * use the new pm_req struct. 12027c478bd9Sstevel@tonic-gate */ 12037c478bd9Sstevel@tonic-gate switch (cmd) { 12047c478bd9Sstevel@tonic-gate case PM_REPARSE_PM_PROPS: 12057c478bd9Sstevel@tonic-gate { 12067c478bd9Sstevel@tonic-gate struct dev_ops *drv; 12077c478bd9Sstevel@tonic-gate struct cb_ops *cb; 12087c478bd9Sstevel@tonic-gate void *propval; 12097c478bd9Sstevel@tonic-gate int length; 12107c478bd9Sstevel@tonic-gate /* 12117c478bd9Sstevel@tonic-gate * This ioctl is provided only for the ddivs pm test. 12127c478bd9Sstevel@tonic-gate * We only do it to a driver which explicitly allows 12137c478bd9Sstevel@tonic-gate * us to do so by exporting a pm-reparse-ok property. 12147c478bd9Sstevel@tonic-gate * We only care whether the property exists or not. 12157c478bd9Sstevel@tonic-gate */ 12167c478bd9Sstevel@tonic-gate if ((drv = ddi_get_driver(dip)) == NULL) { 12177c478bd9Sstevel@tonic-gate ret = EINVAL; 12187c478bd9Sstevel@tonic-gate break; 12197c478bd9Sstevel@tonic-gate } 12207c478bd9Sstevel@tonic-gate if ((cb = drv->devo_cb_ops) != NULL) { 12217c478bd9Sstevel@tonic-gate if ((*cb->cb_prop_op)(DDI_DEV_T_ANY, dip, 12227c478bd9Sstevel@tonic-gate PROP_LEN_AND_VAL_ALLOC, (DDI_PROP_CANSLEEP | 12237c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_NOTPROM), 12247c478bd9Sstevel@tonic-gate "pm-reparse-ok", (caddr_t)&propval, 12257c478bd9Sstevel@tonic-gate &length) != DDI_SUCCESS) { 12267c478bd9Sstevel@tonic-gate ret = EINVAL; 12277c478bd9Sstevel@tonic-gate break; 12287c478bd9Sstevel@tonic-gate } 12297c478bd9Sstevel@tonic-gate } else if (ddi_prop_op(DDI_DEV_T_ANY, dip, 12307c478bd9Sstevel@tonic-gate PROP_LEN_AND_VAL_ALLOC, (DDI_PROP_CANSLEEP | 12317c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_NOTPROM), 12327c478bd9Sstevel@tonic-gate "pm-reparse-ok", (caddr_t)&propval, 12337c478bd9Sstevel@tonic-gate &length) != DDI_SUCCESS) { 12347c478bd9Sstevel@tonic-gate ret = EINVAL; 12357c478bd9Sstevel@tonic-gate break; 12367c478bd9Sstevel@tonic-gate } 12377c478bd9Sstevel@tonic-gate kmem_free(propval, length); 12387c478bd9Sstevel@tonic-gate ret = e_new_pm_props(dip); 12397c478bd9Sstevel@tonic-gate break; 12407c478bd9Sstevel@tonic-gate } 12417c478bd9Sstevel@tonic-gate 12427c478bd9Sstevel@tonic-gate case PM_GET_DEVICE_THRESHOLD: 1243*2df1fe9cSrandyf { 12447c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 12457c478bd9Sstevel@tonic-gate if (!PM_GET_PM_INFO(dip) || PM_ISBC(dip)) { 12467c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 12477c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: ENODEV\n", 12487c478bd9Sstevel@tonic-gate cmdstr)) 12497c478bd9Sstevel@tonic-gate ret = ENODEV; 12507c478bd9Sstevel@tonic-gate break; 12517c478bd9Sstevel@tonic-gate } 12527c478bd9Sstevel@tonic-gate *rval_p = DEVI(dip)->devi_pm_dev_thresh; 12537c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 12547c478bd9Sstevel@tonic-gate ret = 0; 12557c478bd9Sstevel@tonic-gate break; 1256*2df1fe9cSrandyf } 12577c478bd9Sstevel@tonic-gate 12587c478bd9Sstevel@tonic-gate case PM_DIRECT_PM: 12597c478bd9Sstevel@tonic-gate { 12607c478bd9Sstevel@tonic-gate int has_dep; 12617c478bd9Sstevel@tonic-gate if ((info = PM_GET_PM_INFO(dip)) == NULL) { 12627c478bd9Sstevel@tonic-gate PMD(PMD_ERROR | PMD_DPM, ("ioctl: %s: " 12637c478bd9Sstevel@tonic-gate "ENODEV\n", cmdstr)) 12647c478bd9Sstevel@tonic-gate ret = ENODEV; 12657c478bd9Sstevel@tonic-gate break; 12667c478bd9Sstevel@tonic-gate } 12677c478bd9Sstevel@tonic-gate /* 12687c478bd9Sstevel@tonic-gate * Check to see if we are there is a dependency on 12697c478bd9Sstevel@tonic-gate * this kept device, if so, return EBUSY. 12707c478bd9Sstevel@tonic-gate */ 12717c478bd9Sstevel@tonic-gate (void) ddi_pathname(dip, pathbuf); 12727c478bd9Sstevel@tonic-gate pm_dispatch_to_dep_thread(PM_DEP_WK_CHECK_KEPT, 12737c478bd9Sstevel@tonic-gate NULL, pathbuf, PM_DEP_WAIT, &has_dep, 0); 12747c478bd9Sstevel@tonic-gate if (has_dep) { 12757c478bd9Sstevel@tonic-gate PMD(PMD_ERROR | PMD_DPM, ("%s EBUSY\n", 12767c478bd9Sstevel@tonic-gate cmdstr)) 12777c478bd9Sstevel@tonic-gate ret = EBUSY; 12787c478bd9Sstevel@tonic-gate break; 12797c478bd9Sstevel@tonic-gate } 12807c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 12817c478bd9Sstevel@tonic-gate if (PM_ISDIRECT(dip) || (info->pmi_clone != 0)) { 12827c478bd9Sstevel@tonic-gate PMD(PMD_ERROR | PMD_DPM, ("ioctl: %s: " 12837c478bd9Sstevel@tonic-gate "%s@%s(%s#%d): EBUSY\n", cmdstr, 12847c478bd9Sstevel@tonic-gate PM_DEVICE(dip))) 12857c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 12867c478bd9Sstevel@tonic-gate ret = EBUSY; 12877c478bd9Sstevel@tonic-gate break; 12887c478bd9Sstevel@tonic-gate } 12897c478bd9Sstevel@tonic-gate info->pmi_dev_pm_state |= PM_DIRECT; 12907c478bd9Sstevel@tonic-gate info->pmi_clone = clone; 12917c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 12927c478bd9Sstevel@tonic-gate PMD(PMD_DPM, ("ioctl: %s: info %p, pmi_clone %d\n", 12937c478bd9Sstevel@tonic-gate cmdstr, (void *)info, clone)) 12947c478bd9Sstevel@tonic-gate mutex_enter(&pm_clone_lock); 12957c478bd9Sstevel@tonic-gate pm_register_watcher(clone, dip); 12967c478bd9Sstevel@tonic-gate mutex_exit(&pm_clone_lock); 12977c478bd9Sstevel@tonic-gate ret = 0; 12987c478bd9Sstevel@tonic-gate break; 12997c478bd9Sstevel@tonic-gate } 13007c478bd9Sstevel@tonic-gate 13017c478bd9Sstevel@tonic-gate case PM_RELEASE_DIRECT_PM: 13027c478bd9Sstevel@tonic-gate { 13037c478bd9Sstevel@tonic-gate if ((info = PM_GET_PM_INFO(dip)) == NULL) { 13047c478bd9Sstevel@tonic-gate PMD(PMD_ERROR | PMD_DPM, ("ioctl: %s: " 13057c478bd9Sstevel@tonic-gate "ENODEV\n", cmdstr)) 13067c478bd9Sstevel@tonic-gate ret = ENODEV; 13077c478bd9Sstevel@tonic-gate break; 13087c478bd9Sstevel@tonic-gate } 13097c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 13107c478bd9Sstevel@tonic-gate if (info->pmi_clone != clone) { 13117c478bd9Sstevel@tonic-gate PMD(PMD_ERROR | PMD_DPM, ("ioctl: %s: " 13127c478bd9Sstevel@tonic-gate "%s@%s(%s#%d) EINVAL\n", cmdstr, 13137c478bd9Sstevel@tonic-gate PM_DEVICE(dip))) 13147c478bd9Sstevel@tonic-gate ret = EINVAL; 13157c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 13167c478bd9Sstevel@tonic-gate break; 13177c478bd9Sstevel@tonic-gate } 13187c478bd9Sstevel@tonic-gate ASSERT(PM_ISDIRECT(dip)); 13197c478bd9Sstevel@tonic-gate info->pmi_dev_pm_state &= ~PM_DIRECT; 13207c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 13217c478bd9Sstevel@tonic-gate /* Bring ourselves up if there is a keeper. */ 13227c478bd9Sstevel@tonic-gate (void) ddi_pathname(dip, pathbuf); 13237c478bd9Sstevel@tonic-gate pm_dispatch_to_dep_thread(PM_DEP_WK_BRINGUP_SELF, 13247c478bd9Sstevel@tonic-gate NULL, pathbuf, PM_DEP_WAIT, NULL, 0); 13257c478bd9Sstevel@tonic-gate pm_discard_entries(clone); 13267c478bd9Sstevel@tonic-gate pm_deregister_watcher(clone, dip); 13277c478bd9Sstevel@tonic-gate /* 13287c478bd9Sstevel@tonic-gate * Now we could let the other threads that are 13297c478bd9Sstevel@tonic-gate * trying to do a DIRECT_PM thru 13307c478bd9Sstevel@tonic-gate */ 13317c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 13327c478bd9Sstevel@tonic-gate info->pmi_clone = 0; 13337c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 13347c478bd9Sstevel@tonic-gate pm_proceed(dip, PMP_RELEASE, -1, -1); 13357c478bd9Sstevel@tonic-gate PMD(PMD_RESCAN | PMD_DPM, ("ioctl: %s: rescan\n", 13367c478bd9Sstevel@tonic-gate cmdstr)) 13377c478bd9Sstevel@tonic-gate pm_rescan(dip); 13387c478bd9Sstevel@tonic-gate ret = 0; 13397c478bd9Sstevel@tonic-gate break; 13407c478bd9Sstevel@tonic-gate } 13417c478bd9Sstevel@tonic-gate 13427c478bd9Sstevel@tonic-gate case PM_SET_CURRENT_POWER: 13437c478bd9Sstevel@tonic-gate { 13447c478bd9Sstevel@tonic-gate int comp = req.component; 13457c478bd9Sstevel@tonic-gate int value = req.value; 13467c478bd9Sstevel@tonic-gate PMD(PMD_DPM, ("ioctl: %s: %s component %d to value " 13477c478bd9Sstevel@tonic-gate "%d\n", cmdstr, req.physpath, comp, value)) 13487c478bd9Sstevel@tonic-gate if (!e_pm_valid_comp(dip, comp, NULL) || 13497c478bd9Sstevel@tonic-gate !e_pm_valid_power(dip, comp, value)) { 13507c478bd9Sstevel@tonic-gate PMD(PMD_ERROR | PMD_DPM, ("ioctl: %s: " 13517c478bd9Sstevel@tonic-gate "physpath=%s, comp=%d, level=%d, fails\n", 13527c478bd9Sstevel@tonic-gate cmdstr, req.physpath, comp, value)) 13537c478bd9Sstevel@tonic-gate ret = EINVAL; 13547c478bd9Sstevel@tonic-gate break; 13557c478bd9Sstevel@tonic-gate } 13567c478bd9Sstevel@tonic-gate 13577c478bd9Sstevel@tonic-gate if ((info = PM_GET_PM_INFO(dip)) == NULL) { 13587c478bd9Sstevel@tonic-gate PMD(PMD_ERROR | PMD_DPM, ("ioctl: %s: " 13597c478bd9Sstevel@tonic-gate "ENODEV\n", cmdstr)) 13607c478bd9Sstevel@tonic-gate ret = ENODEV; 13617c478bd9Sstevel@tonic-gate break; 13627c478bd9Sstevel@tonic-gate } 13637c478bd9Sstevel@tonic-gate if (info->pmi_clone != clone) { 13647c478bd9Sstevel@tonic-gate PMD(PMD_ERROR | PMD_DPM, ("ioctl: %s: " 13657c478bd9Sstevel@tonic-gate "(not owner) %s fails; clone %d, owner %d" 13667c478bd9Sstevel@tonic-gate "\n", cmdstr, req.physpath, clone, 13677c478bd9Sstevel@tonic-gate info->pmi_clone)) 13687c478bd9Sstevel@tonic-gate ret = EINVAL; 13697c478bd9Sstevel@tonic-gate break; 13707c478bd9Sstevel@tonic-gate } 13717c478bd9Sstevel@tonic-gate ASSERT(PM_ISDIRECT(dip)); 13727c478bd9Sstevel@tonic-gate 13737c478bd9Sstevel@tonic-gate if (pm_set_power(dip, comp, value, PM_LEVEL_EXACT, 13747c478bd9Sstevel@tonic-gate PM_CANBLOCK_BLOCK, 0, &ret) != DDI_SUCCESS) { 13757c478bd9Sstevel@tonic-gate PMD(PMD_ERROR | PMD_DPM, ("ioctl: %s: " 13767c478bd9Sstevel@tonic-gate "pm_set_power for %s fails, errno=%d\n", 13777c478bd9Sstevel@tonic-gate cmdstr, req.physpath, ret)) 13787c478bd9Sstevel@tonic-gate break; 13797c478bd9Sstevel@tonic-gate } 13807c478bd9Sstevel@tonic-gate 13817c478bd9Sstevel@tonic-gate pm_proceed(dip, PMP_SETPOWER, comp, value); 13827c478bd9Sstevel@tonic-gate 13837c478bd9Sstevel@tonic-gate /* 13847c478bd9Sstevel@tonic-gate * Power down all idle components if console framebuffer 13857c478bd9Sstevel@tonic-gate * is powered off. 13867c478bd9Sstevel@tonic-gate */ 13877c478bd9Sstevel@tonic-gate if (PM_IS_CFB(dip) && (pm_system_idle_threshold == 13887c478bd9Sstevel@tonic-gate pm_default_idle_threshold)) { 13897c478bd9Sstevel@tonic-gate dev_info_t *root = ddi_root_node(); 13907c478bd9Sstevel@tonic-gate if (PM_ISBC(dip)) { 13917c478bd9Sstevel@tonic-gate if (comp == 0 && value == 0 && 13927c478bd9Sstevel@tonic-gate (pm_timeout_idledown() != 0)) { 13937c478bd9Sstevel@tonic-gate ddi_walk_devs(root, 13947c478bd9Sstevel@tonic-gate pm_start_idledown, 13957c478bd9Sstevel@tonic-gate (void *)PMID_CFB); 13967c478bd9Sstevel@tonic-gate } 13977c478bd9Sstevel@tonic-gate } else { 13987c478bd9Sstevel@tonic-gate int count = 0; 13997c478bd9Sstevel@tonic-gate for (i = 0; i < PM_NUMCMPTS(dip); i++) { 14007c478bd9Sstevel@tonic-gate ret = pm_get_current_power(dip, 14017c478bd9Sstevel@tonic-gate i, &curpower); 14027c478bd9Sstevel@tonic-gate if (ret == DDI_SUCCESS && 14037c478bd9Sstevel@tonic-gate curpower == 0) 14047c478bd9Sstevel@tonic-gate count++; 14057c478bd9Sstevel@tonic-gate } 14067c478bd9Sstevel@tonic-gate if ((count == PM_NUMCMPTS(dip)) && 14077c478bd9Sstevel@tonic-gate (pm_timeout_idledown() != 0)) { 14087c478bd9Sstevel@tonic-gate ddi_walk_devs(root, 14097c478bd9Sstevel@tonic-gate pm_start_idledown, 14107c478bd9Sstevel@tonic-gate (void *)PMID_CFB); 14117c478bd9Sstevel@tonic-gate } 14127c478bd9Sstevel@tonic-gate } 14137c478bd9Sstevel@tonic-gate } 14147c478bd9Sstevel@tonic-gate 14157c478bd9Sstevel@tonic-gate PMD(PMD_RESCAN | PMD_DPM, ("ioctl: %s: rescan\n", 14167c478bd9Sstevel@tonic-gate cmdstr)) 14177c478bd9Sstevel@tonic-gate pm_rescan(dip); 14187c478bd9Sstevel@tonic-gate *rval_p = 0; 14197c478bd9Sstevel@tonic-gate ret = 0; 14207c478bd9Sstevel@tonic-gate break; 14217c478bd9Sstevel@tonic-gate } 14227c478bd9Sstevel@tonic-gate 14237c478bd9Sstevel@tonic-gate case PM_GET_FULL_POWER: 14247c478bd9Sstevel@tonic-gate { 14257c478bd9Sstevel@tonic-gate int normal; 14267c478bd9Sstevel@tonic-gate ASSERT(dip); 14277c478bd9Sstevel@tonic-gate PMD(PMD_NORM, ("ioctl: %s: %s component %d\n", 14287c478bd9Sstevel@tonic-gate cmdstr, req.physpath, req.component)) 14297c478bd9Sstevel@tonic-gate normal = pm_get_normal_power(dip, req.component); 14307c478bd9Sstevel@tonic-gate 14317c478bd9Sstevel@tonic-gate if (normal == DDI_FAILURE) { 14327c478bd9Sstevel@tonic-gate PMD(PMD_ERROR | PMD_NORM, ("ioctl: %s: " 14337c478bd9Sstevel@tonic-gate "returns EINVAL\n", cmdstr)) 14347c478bd9Sstevel@tonic-gate ret = EINVAL; 14357c478bd9Sstevel@tonic-gate break; 14367c478bd9Sstevel@tonic-gate } 14377c478bd9Sstevel@tonic-gate *rval_p = normal; 14387c478bd9Sstevel@tonic-gate PMD(PMD_NORM, ("ioctl: %s: returns %d\n", 14397c478bd9Sstevel@tonic-gate cmdstr, normal)) 14407c478bd9Sstevel@tonic-gate ret = 0; 14417c478bd9Sstevel@tonic-gate break; 14427c478bd9Sstevel@tonic-gate } 14437c478bd9Sstevel@tonic-gate 14447c478bd9Sstevel@tonic-gate case PM_GET_CURRENT_POWER: 1445*2df1fe9cSrandyf { 14467c478bd9Sstevel@tonic-gate if (pm_get_current_power(dip, req.component, 14477c478bd9Sstevel@tonic-gate rval_p) != DDI_SUCCESS) { 14487c478bd9Sstevel@tonic-gate PMD(PMD_ERROR | PMD_DPM, ("ioctl: %s " 14497c478bd9Sstevel@tonic-gate "EINVAL\n", cmdstr)) 14507c478bd9Sstevel@tonic-gate ret = EINVAL; 14517c478bd9Sstevel@tonic-gate break; 14527c478bd9Sstevel@tonic-gate } 14537c478bd9Sstevel@tonic-gate PMD(PMD_DPM, ("ioctl: %s: %s comp %d returns %d\n", 14547c478bd9Sstevel@tonic-gate cmdstr, req.physpath, req.component, *rval_p)) 14557c478bd9Sstevel@tonic-gate if (*rval_p == PM_LEVEL_UNKNOWN) 14567c478bd9Sstevel@tonic-gate ret = EAGAIN; 14577c478bd9Sstevel@tonic-gate else 14587c478bd9Sstevel@tonic-gate ret = 0; 14597c478bd9Sstevel@tonic-gate break; 1460*2df1fe9cSrandyf } 14617c478bd9Sstevel@tonic-gate 14627c478bd9Sstevel@tonic-gate case PM_GET_TIME_IDLE: 14637c478bd9Sstevel@tonic-gate { 14647c478bd9Sstevel@tonic-gate time_t timestamp; 14657c478bd9Sstevel@tonic-gate int comp = req.component; 14667c478bd9Sstevel@tonic-gate pm_component_t *cp; 14677c478bd9Sstevel@tonic-gate if (!e_pm_valid_comp(dip, comp, &cp)) { 14687c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s(%s#%d) " 14697c478bd9Sstevel@tonic-gate "component %d > numcmpts - 1 %d--EINVAL\n", 14707c478bd9Sstevel@tonic-gate cmdstr, PM_DEVICE(dip), comp, 14717c478bd9Sstevel@tonic-gate PM_NUMCMPTS(dip) - 1)) 14727c478bd9Sstevel@tonic-gate ret = EINVAL; 14737c478bd9Sstevel@tonic-gate break; 14747c478bd9Sstevel@tonic-gate } 14757c478bd9Sstevel@tonic-gate timestamp = cp->pmc_timestamp; 14767c478bd9Sstevel@tonic-gate if (timestamp) { 14777c478bd9Sstevel@tonic-gate time_t now; 14787c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, &now); 14797c478bd9Sstevel@tonic-gate *rval_p = (now - timestamp); 14807c478bd9Sstevel@tonic-gate } else { 14817c478bd9Sstevel@tonic-gate *rval_p = 0; 14827c478bd9Sstevel@tonic-gate } 14837c478bd9Sstevel@tonic-gate ret = 0; 14847c478bd9Sstevel@tonic-gate break; 14857c478bd9Sstevel@tonic-gate } 14867c478bd9Sstevel@tonic-gate 14877c478bd9Sstevel@tonic-gate case PM_ADD_DEPENDENT: 14887c478bd9Sstevel@tonic-gate { 14897c478bd9Sstevel@tonic-gate dev_info_t *kept_dip; 14907c478bd9Sstevel@tonic-gate 14917c478bd9Sstevel@tonic-gate PMD(PMD_KEEPS, ("%s, kept %s, keeper %s\n", cmdstr, 14927c478bd9Sstevel@tonic-gate dep, req.physpath)) 14937c478bd9Sstevel@tonic-gate 14947c478bd9Sstevel@tonic-gate /* 14957c478bd9Sstevel@tonic-gate * hold and install kept while processing dependency 14967c478bd9Sstevel@tonic-gate * keeper (in .physpath) has already been held. 14977c478bd9Sstevel@tonic-gate */ 14987c478bd9Sstevel@tonic-gate if (dep[0] == '\0') { 14997c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("kept NULL or null\n")) 15007c478bd9Sstevel@tonic-gate ret = EINVAL; 15017c478bd9Sstevel@tonic-gate break; 15027c478bd9Sstevel@tonic-gate } else if ((kept_dip = 15037c478bd9Sstevel@tonic-gate pm_name_to_dip(dep, 1)) == NULL) { 15047c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("no dip for kept %s\n", dep)) 15057c478bd9Sstevel@tonic-gate ret = ENODEV; 15067c478bd9Sstevel@tonic-gate break; 15077c478bd9Sstevel@tonic-gate } else if (kept_dip == dip) { 15087c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("keeper(%s, %p) - kept(%s, %p) " 15097c478bd9Sstevel@tonic-gate "self-dependency not allowed.\n", 15107c478bd9Sstevel@tonic-gate dep, (void *)kept_dip, req.physpath, 15117c478bd9Sstevel@tonic-gate (void *) dip)) 15127c478bd9Sstevel@tonic-gate PM_RELE(dip); /* release "double" hold */ 15137c478bd9Sstevel@tonic-gate ret = EINVAL; 15147c478bd9Sstevel@tonic-gate break; 15157c478bd9Sstevel@tonic-gate } 15167c478bd9Sstevel@tonic-gate ASSERT(!(strcmp(req.physpath, (char *)dep) == 0)); 15177c478bd9Sstevel@tonic-gate 15187c478bd9Sstevel@tonic-gate /* 15197c478bd9Sstevel@tonic-gate * record dependency, then walk through device tree 15207c478bd9Sstevel@tonic-gate * independently on behalf of kept and keeper to 15217c478bd9Sstevel@tonic-gate * establish newly created dependency. 15227c478bd9Sstevel@tonic-gate */ 15237c478bd9Sstevel@tonic-gate pm_dispatch_to_dep_thread(PM_DEP_WK_RECORD_KEEPER, 15247c478bd9Sstevel@tonic-gate req.physpath, dep, PM_DEP_WAIT, NULL, 0); 15257c478bd9Sstevel@tonic-gate 15267c478bd9Sstevel@tonic-gate /* 15277c478bd9Sstevel@tonic-gate * release kept after establishing dependency, keeper 15287c478bd9Sstevel@tonic-gate * is released as part of ioctl exit processing. 15297c478bd9Sstevel@tonic-gate */ 15307c478bd9Sstevel@tonic-gate PM_RELE(kept_dip); 15317c478bd9Sstevel@tonic-gate *rval_p = 0; 15327c478bd9Sstevel@tonic-gate ret = 0; 15337c478bd9Sstevel@tonic-gate break; 15347c478bd9Sstevel@tonic-gate } 15357c478bd9Sstevel@tonic-gate 15367c478bd9Sstevel@tonic-gate case PM_ADD_DEPENDENT_PROPERTY: 15377c478bd9Sstevel@tonic-gate { 15387c478bd9Sstevel@tonic-gate char *keeper, *kept; 15397c478bd9Sstevel@tonic-gate 15407c478bd9Sstevel@tonic-gate if (dep[0] == '\0') { 15417c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: dep NULL or " 15427c478bd9Sstevel@tonic-gate "null\n", cmdstr)) 15437c478bd9Sstevel@tonic-gate ret = EINVAL; 15447c478bd9Sstevel@tonic-gate break; 15457c478bd9Sstevel@tonic-gate } 15467c478bd9Sstevel@tonic-gate kept = dep; 15477c478bd9Sstevel@tonic-gate keeper = req.physpath; 15487c478bd9Sstevel@tonic-gate /* 15497c478bd9Sstevel@tonic-gate * record keeper - kept dependency, then walk through 15507c478bd9Sstevel@tonic-gate * device tree to find out all attached keeper, walk 15517c478bd9Sstevel@tonic-gate * through again to apply dependency to all the 15527c478bd9Sstevel@tonic-gate * potential kept. 15537c478bd9Sstevel@tonic-gate */ 15547c478bd9Sstevel@tonic-gate pm_dispatch_to_dep_thread( 15557c478bd9Sstevel@tonic-gate PM_DEP_WK_RECORD_KEEPER_PROP, keeper, kept, 15567c478bd9Sstevel@tonic-gate PM_DEP_WAIT, NULL, 0); 15577c478bd9Sstevel@tonic-gate 15587c478bd9Sstevel@tonic-gate *rval_p = 0; 15597c478bd9Sstevel@tonic-gate ret = 0; 15607c478bd9Sstevel@tonic-gate break; 15617c478bd9Sstevel@tonic-gate } 15627c478bd9Sstevel@tonic-gate 15637c478bd9Sstevel@tonic-gate case PM_SET_DEVICE_THRESHOLD: 15647c478bd9Sstevel@tonic-gate { 15657c478bd9Sstevel@tonic-gate pm_thresh_rec_t *rp; 15667c478bd9Sstevel@tonic-gate pm_pte_t *ep; /* threshold header storage */ 15677c478bd9Sstevel@tonic-gate int *tp; /* threshold storage */ 15687c478bd9Sstevel@tonic-gate size_t size; 15697c478bd9Sstevel@tonic-gate extern int pm_thresh_specd(dev_info_t *); 15707c478bd9Sstevel@tonic-gate 15717c478bd9Sstevel@tonic-gate /* 15727c478bd9Sstevel@tonic-gate * The header struct plus one entry struct plus one 15737c478bd9Sstevel@tonic-gate * threshold plus the length of the string 15747c478bd9Sstevel@tonic-gate */ 15757c478bd9Sstevel@tonic-gate size = sizeof (pm_thresh_rec_t) + 15767c478bd9Sstevel@tonic-gate (sizeof (pm_pte_t) * 1) + 15777c478bd9Sstevel@tonic-gate (1 * sizeof (int)) + 15787c478bd9Sstevel@tonic-gate strlen(req.physpath) + 1; 15797c478bd9Sstevel@tonic-gate 15807c478bd9Sstevel@tonic-gate rp = kmem_zalloc(size, KM_SLEEP); 15817c478bd9Sstevel@tonic-gate rp->ptr_size = size; 15827c478bd9Sstevel@tonic-gate rp->ptr_numcomps = 0; /* means device threshold */ 15837c478bd9Sstevel@tonic-gate ep = (pm_pte_t *)((intptr_t)rp + sizeof (*rp)); 15847c478bd9Sstevel@tonic-gate rp->ptr_entries = ep; 15857c478bd9Sstevel@tonic-gate tp = (int *)((intptr_t)ep + 15867c478bd9Sstevel@tonic-gate (1 * sizeof (pm_pte_t))); 15877c478bd9Sstevel@tonic-gate ep->pte_numthresh = 1; 15887c478bd9Sstevel@tonic-gate ep->pte_thresh = tp; 15897c478bd9Sstevel@tonic-gate *tp++ = req.value; 15907c478bd9Sstevel@tonic-gate (void) strcat((char *)tp, req.physpath); 15917c478bd9Sstevel@tonic-gate rp->ptr_physpath = (char *)tp; 15927c478bd9Sstevel@tonic-gate ASSERT((intptr_t)tp + strlen(req.physpath) + 1 == 15937c478bd9Sstevel@tonic-gate (intptr_t)rp + rp->ptr_size); 15947c478bd9Sstevel@tonic-gate PMD(PMD_THRESH, ("ioctl: %s: record thresh %d for " 15957c478bd9Sstevel@tonic-gate "%s\n", cmdstr, req.value, req.physpath)) 15967c478bd9Sstevel@tonic-gate pm_record_thresh(rp); 15977c478bd9Sstevel@tonic-gate /* 15987c478bd9Sstevel@tonic-gate * Don't free rp, pm_record_thresh() keeps it. 15997c478bd9Sstevel@tonic-gate * We don't try to apply it ourselves because we'd need 16007c478bd9Sstevel@tonic-gate * to know too much about locking. Since we don't 16017c478bd9Sstevel@tonic-gate * hold a lock the entry could be removed before 16027c478bd9Sstevel@tonic-gate * we get here 16037c478bd9Sstevel@tonic-gate */ 16047c478bd9Sstevel@tonic-gate ASSERT(dip == NULL); 16057c478bd9Sstevel@tonic-gate ret = 0; /* can't fail now */ 16067c478bd9Sstevel@tonic-gate if (!(dip = pm_name_to_dip(req.physpath, 1))) { 16077c478bd9Sstevel@tonic-gate break; 16087c478bd9Sstevel@tonic-gate } 16097c478bd9Sstevel@tonic-gate (void) pm_thresh_specd(dip); 16107c478bd9Sstevel@tonic-gate PMD(PMD_DHR, ("ioctl: %s: releasing %s@%s(%s#%d)\n", 16117c478bd9Sstevel@tonic-gate cmdstr, PM_DEVICE(dip))) 16127c478bd9Sstevel@tonic-gate PM_RELE(dip); 16137c478bd9Sstevel@tonic-gate break; 16147c478bd9Sstevel@tonic-gate } 16157c478bd9Sstevel@tonic-gate 16167c478bd9Sstevel@tonic-gate case PM_RESET_DEVICE_THRESHOLD: 16177c478bd9Sstevel@tonic-gate { 16187c478bd9Sstevel@tonic-gate /* 16197c478bd9Sstevel@tonic-gate * This only applies to a currently attached and power 16207c478bd9Sstevel@tonic-gate * managed node 16217c478bd9Sstevel@tonic-gate */ 16227c478bd9Sstevel@tonic-gate /* 16237c478bd9Sstevel@tonic-gate * We don't do this to old-style drivers 16247c478bd9Sstevel@tonic-gate */ 16257c478bd9Sstevel@tonic-gate info = PM_GET_PM_INFO(dip); 16267c478bd9Sstevel@tonic-gate if (info == NULL) { 16277c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s not power " 16287c478bd9Sstevel@tonic-gate "managed\n", cmdstr, req.physpath)) 16297c478bd9Sstevel@tonic-gate ret = EINVAL; 16307c478bd9Sstevel@tonic-gate break; 16317c478bd9Sstevel@tonic-gate } 16327c478bd9Sstevel@tonic-gate if (PM_ISBC(dip)) { 16337c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s is BC\n", 16347c478bd9Sstevel@tonic-gate cmdstr, req.physpath)) 16357c478bd9Sstevel@tonic-gate ret = EINVAL; 16367c478bd9Sstevel@tonic-gate break; 16377c478bd9Sstevel@tonic-gate } 16387c478bd9Sstevel@tonic-gate pm_unrecord_threshold(req.physpath); 1639c42872d4Smh27603 if (DEVI(dip)->devi_pm_flags & PMC_CPU_THRESH) 1640c42872d4Smh27603 pm_set_device_threshold(dip, 1641c42872d4Smh27603 pm_cpu_idle_threshold, PMC_CPU_THRESH); 1642c42872d4Smh27603 else 1643c42872d4Smh27603 pm_set_device_threshold(dip, 1644c42872d4Smh27603 pm_system_idle_threshold, PMC_DEF_THRESH); 16457c478bd9Sstevel@tonic-gate ret = 0; 16467c478bd9Sstevel@tonic-gate break; 16477c478bd9Sstevel@tonic-gate } 16487c478bd9Sstevel@tonic-gate 16497c478bd9Sstevel@tonic-gate case PM_GET_NUM_COMPONENTS: 1650*2df1fe9cSrandyf { 16517c478bd9Sstevel@tonic-gate ret = 0; 16527c478bd9Sstevel@tonic-gate *rval_p = PM_NUMCMPTS(dip); 16537c478bd9Sstevel@tonic-gate break; 1654*2df1fe9cSrandyf } 16557c478bd9Sstevel@tonic-gate 16567c478bd9Sstevel@tonic-gate case PM_GET_DEVICE_TYPE: 1657*2df1fe9cSrandyf { 16587c478bd9Sstevel@tonic-gate ret = 0; 16597c478bd9Sstevel@tonic-gate if ((info = PM_GET_PM_INFO(dip)) == NULL) { 16607c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: " 16617c478bd9Sstevel@tonic-gate "PM_NO_PM_COMPONENTS\n", cmdstr)) 16627c478bd9Sstevel@tonic-gate *rval_p = PM_NO_PM_COMPONENTS; 16637c478bd9Sstevel@tonic-gate break; 16647c478bd9Sstevel@tonic-gate } 16657c478bd9Sstevel@tonic-gate if (PM_ISBC(dip)) { 16667c478bd9Sstevel@tonic-gate *rval_p = PM_CREATE_COMPONENTS; 16677c478bd9Sstevel@tonic-gate } else { 16687c478bd9Sstevel@tonic-gate *rval_p = PM_AUTOPM; 16697c478bd9Sstevel@tonic-gate } 16707c478bd9Sstevel@tonic-gate break; 1671*2df1fe9cSrandyf } 16727c478bd9Sstevel@tonic-gate 16737c478bd9Sstevel@tonic-gate case PM_SET_COMPONENT_THRESHOLDS: 16747c478bd9Sstevel@tonic-gate { 16757c478bd9Sstevel@tonic-gate int comps = 0; 16767c478bd9Sstevel@tonic-gate int *end = (int *)req.data + icount; 16777c478bd9Sstevel@tonic-gate pm_thresh_rec_t *rp; 16787c478bd9Sstevel@tonic-gate pm_pte_t *ep; /* threshold header storage */ 16797c478bd9Sstevel@tonic-gate int *tp; /* threshold storage */ 16807c478bd9Sstevel@tonic-gate int *ip; 16817c478bd9Sstevel@tonic-gate int j; 16827c478bd9Sstevel@tonic-gate size_t size; 16837c478bd9Sstevel@tonic-gate extern int pm_thresh_specd(dev_info_t *); 16847c478bd9Sstevel@tonic-gate extern int pm_valid_thresh(dev_info_t *, 16857c478bd9Sstevel@tonic-gate pm_thresh_rec_t *); 16867c478bd9Sstevel@tonic-gate 16877c478bd9Sstevel@tonic-gate for (ip = req.data; *ip; ip++) { 16887c478bd9Sstevel@tonic-gate if (ip >= end) { 16897c478bd9Sstevel@tonic-gate ret = EFAULT; 16907c478bd9Sstevel@tonic-gate break; 16917c478bd9Sstevel@tonic-gate } 16927c478bd9Sstevel@tonic-gate comps++; 16937c478bd9Sstevel@tonic-gate /* skip over indicated number of entries */ 16947c478bd9Sstevel@tonic-gate for (j = *ip; j; j--) { 16957c478bd9Sstevel@tonic-gate if (++ip >= end) { 16967c478bd9Sstevel@tonic-gate ret = EFAULT; 16977c478bd9Sstevel@tonic-gate break; 16987c478bd9Sstevel@tonic-gate } 16997c478bd9Sstevel@tonic-gate } 17007c478bd9Sstevel@tonic-gate if (ret) 17017c478bd9Sstevel@tonic-gate break; 17027c478bd9Sstevel@tonic-gate } 17037c478bd9Sstevel@tonic-gate if (ret) 17047c478bd9Sstevel@tonic-gate break; 17057c478bd9Sstevel@tonic-gate if ((intptr_t)ip != (intptr_t)end - sizeof (int)) { 17067c478bd9Sstevel@tonic-gate /* did not exactly fill buffer */ 17077c478bd9Sstevel@tonic-gate ret = EINVAL; 17087c478bd9Sstevel@tonic-gate break; 17097c478bd9Sstevel@tonic-gate } 17107c478bd9Sstevel@tonic-gate if (comps == 0) { 17117c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s 0 components" 17127c478bd9Sstevel@tonic-gate "--EINVAL\n", cmdstr, req.physpath)) 17137c478bd9Sstevel@tonic-gate ret = EINVAL; 17147c478bd9Sstevel@tonic-gate break; 17157c478bd9Sstevel@tonic-gate } 17167c478bd9Sstevel@tonic-gate /* 17177c478bd9Sstevel@tonic-gate * The header struct plus one entry struct per component 17187c478bd9Sstevel@tonic-gate * plus the size of the lists minus the counts 17197c478bd9Sstevel@tonic-gate * plus the length of the string 17207c478bd9Sstevel@tonic-gate */ 17217c478bd9Sstevel@tonic-gate size = sizeof (pm_thresh_rec_t) + 17227c478bd9Sstevel@tonic-gate (sizeof (pm_pte_t) * comps) + req.datasize - 17237c478bd9Sstevel@tonic-gate ((comps + 1) * sizeof (int)) + 17247c478bd9Sstevel@tonic-gate strlen(req.physpath) + 1; 17257c478bd9Sstevel@tonic-gate 17267c478bd9Sstevel@tonic-gate rp = kmem_zalloc(size, KM_SLEEP); 17277c478bd9Sstevel@tonic-gate rp->ptr_size = size; 17287c478bd9Sstevel@tonic-gate rp->ptr_numcomps = comps; 17297c478bd9Sstevel@tonic-gate ep = (pm_pte_t *)((intptr_t)rp + sizeof (*rp)); 17307c478bd9Sstevel@tonic-gate rp->ptr_entries = ep; 17317c478bd9Sstevel@tonic-gate tp = (int *)((intptr_t)ep + 17327c478bd9Sstevel@tonic-gate (comps * sizeof (pm_pte_t))); 17337c478bd9Sstevel@tonic-gate for (ip = req.data; *ip; ep++) { 17347c478bd9Sstevel@tonic-gate ep->pte_numthresh = *ip; 17357c478bd9Sstevel@tonic-gate ep->pte_thresh = tp; 17367c478bd9Sstevel@tonic-gate for (j = *ip++; j; j--) { 17377c478bd9Sstevel@tonic-gate *tp++ = *ip++; 17387c478bd9Sstevel@tonic-gate } 17397c478bd9Sstevel@tonic-gate } 17407c478bd9Sstevel@tonic-gate (void) strcat((char *)tp, req.physpath); 17417c478bd9Sstevel@tonic-gate rp->ptr_physpath = (char *)tp; 17427c478bd9Sstevel@tonic-gate ASSERT((intptr_t)end == (intptr_t)ip + sizeof (int)); 17437c478bd9Sstevel@tonic-gate ASSERT((intptr_t)tp + strlen(req.physpath) + 1 == 17447c478bd9Sstevel@tonic-gate (intptr_t)rp + rp->ptr_size); 17457c478bd9Sstevel@tonic-gate 17467c478bd9Sstevel@tonic-gate ASSERT(dip == NULL); 17477c478bd9Sstevel@tonic-gate /* 17487c478bd9Sstevel@tonic-gate * If this is not a currently power managed node, 17497c478bd9Sstevel@tonic-gate * then we can't check for validity of the thresholds 17507c478bd9Sstevel@tonic-gate */ 17517c478bd9Sstevel@tonic-gate if (!(dip = pm_name_to_dip(req.physpath, 1))) { 17527c478bd9Sstevel@tonic-gate /* don't free rp, pm_record_thresh uses it */ 17537c478bd9Sstevel@tonic-gate pm_record_thresh(rp); 17547c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: pm_name_to_dip " 17557c478bd9Sstevel@tonic-gate "for %s failed\n", cmdstr, req.physpath)) 17567c478bd9Sstevel@tonic-gate ret = 0; 17577c478bd9Sstevel@tonic-gate break; 17587c478bd9Sstevel@tonic-gate } 17597c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 17607c478bd9Sstevel@tonic-gate dipheld++; 17617c478bd9Sstevel@tonic-gate 17627c478bd9Sstevel@tonic-gate if (!pm_valid_thresh(dip, rp)) { 17637c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: invalid thresh " 17647c478bd9Sstevel@tonic-gate "for %s@%s(%s#%d)\n", cmdstr, 17657c478bd9Sstevel@tonic-gate PM_DEVICE(dip))) 17667c478bd9Sstevel@tonic-gate kmem_free(rp, size); 17677c478bd9Sstevel@tonic-gate ret = EINVAL; 17687c478bd9Sstevel@tonic-gate break; 17697c478bd9Sstevel@tonic-gate } 17707c478bd9Sstevel@tonic-gate /* 17717c478bd9Sstevel@tonic-gate * We don't just apply it ourselves because we'd need 17727c478bd9Sstevel@tonic-gate * to know too much about locking. Since we don't 17737c478bd9Sstevel@tonic-gate * hold a lock the entry could be removed before 17747c478bd9Sstevel@tonic-gate * we get here 17757c478bd9Sstevel@tonic-gate */ 17767c478bd9Sstevel@tonic-gate pm_record_thresh(rp); 17777c478bd9Sstevel@tonic-gate (void) pm_thresh_specd(dip); 17787c478bd9Sstevel@tonic-gate ret = 0; 17797c478bd9Sstevel@tonic-gate break; 17807c478bd9Sstevel@tonic-gate } 17817c478bd9Sstevel@tonic-gate 17827c478bd9Sstevel@tonic-gate case PM_GET_COMPONENT_THRESHOLDS: 17837c478bd9Sstevel@tonic-gate { 17847c478bd9Sstevel@tonic-gate int musthave; 17857c478bd9Sstevel@tonic-gate int numthresholds = 0; 17867c478bd9Sstevel@tonic-gate int wordsize; 17877c478bd9Sstevel@tonic-gate int numcomps; 17887c478bd9Sstevel@tonic-gate caddr_t uaddr = req.data; /* user address */ 17897c478bd9Sstevel@tonic-gate int val; /* int value to be copied out */ 17907c478bd9Sstevel@tonic-gate int32_t val32; /* int32 value to be copied out */ 17917c478bd9Sstevel@tonic-gate caddr_t vaddr; /* address to copyout from */ 17927c478bd9Sstevel@tonic-gate int j; 17937c478bd9Sstevel@tonic-gate 17947c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 17957c478bd9Sstevel@tonic-gate if ((mode & DATAMODEL_MASK) == DATAMODEL_ILP32) { 17967c478bd9Sstevel@tonic-gate wordsize = sizeof (int32_t); 17977c478bd9Sstevel@tonic-gate } else 17987c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 17997c478bd9Sstevel@tonic-gate { 18007c478bd9Sstevel@tonic-gate wordsize = sizeof (int); 18017c478bd9Sstevel@tonic-gate } 18027c478bd9Sstevel@tonic-gate 18037c478bd9Sstevel@tonic-gate ASSERT(dip); 18047c478bd9Sstevel@tonic-gate 18057c478bd9Sstevel@tonic-gate numcomps = PM_NUMCMPTS(dip); 18067c478bd9Sstevel@tonic-gate for (i = 0; i < numcomps; i++) { 18077c478bd9Sstevel@tonic-gate cp = PM_CP(dip, i); 18087c478bd9Sstevel@tonic-gate numthresholds += cp->pmc_comp.pmc_numlevels - 1; 18097c478bd9Sstevel@tonic-gate } 18107c478bd9Sstevel@tonic-gate musthave = (numthresholds + numcomps + 1) * wordsize; 18117c478bd9Sstevel@tonic-gate if (req.datasize < musthave) { 18127c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: size %ld, need " 18137c478bd9Sstevel@tonic-gate "%d--EINVAL\n", cmdstr, req.datasize, 18147c478bd9Sstevel@tonic-gate musthave)) 18157c478bd9Sstevel@tonic-gate ret = EINVAL; 18167c478bd9Sstevel@tonic-gate break; 18177c478bd9Sstevel@tonic-gate } 18187c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 18197c478bd9Sstevel@tonic-gate for (i = 0; i < numcomps; i++) { 18207c478bd9Sstevel@tonic-gate int *thp; 18217c478bd9Sstevel@tonic-gate cp = PM_CP(dip, i); 18227c478bd9Sstevel@tonic-gate thp = cp->pmc_comp.pmc_thresh; 18237c478bd9Sstevel@tonic-gate /* first copyout the count */ 18247c478bd9Sstevel@tonic-gate if (wordsize == sizeof (int32_t)) { 18257c478bd9Sstevel@tonic-gate val32 = cp->pmc_comp.pmc_numlevels - 1; 18267c478bd9Sstevel@tonic-gate vaddr = (caddr_t)&val32; 18277c478bd9Sstevel@tonic-gate } else { 18287c478bd9Sstevel@tonic-gate val = cp->pmc_comp.pmc_numlevels - 1; 18297c478bd9Sstevel@tonic-gate vaddr = (caddr_t)&val; 18307c478bd9Sstevel@tonic-gate } 18317c478bd9Sstevel@tonic-gate if (ddi_copyout(vaddr, (void *)uaddr, 18327c478bd9Sstevel@tonic-gate wordsize, mode) != 0) { 18337c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 18347c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s" 18357c478bd9Sstevel@tonic-gate "(%s#%d) vaddr %p EFAULT\n", 18367c478bd9Sstevel@tonic-gate cmdstr, PM_DEVICE(dip), 18377c478bd9Sstevel@tonic-gate (void*)vaddr)) 18387c478bd9Sstevel@tonic-gate ret = EFAULT; 18397c478bd9Sstevel@tonic-gate break; 18407c478bd9Sstevel@tonic-gate } 18417c478bd9Sstevel@tonic-gate vaddr = uaddr; 18427c478bd9Sstevel@tonic-gate vaddr += wordsize; 18437c478bd9Sstevel@tonic-gate uaddr = (caddr_t)vaddr; 18447c478bd9Sstevel@tonic-gate /* then copyout each threshold value */ 18457c478bd9Sstevel@tonic-gate for (j = 0; j < cp->pmc_comp.pmc_numlevels - 1; 18467c478bd9Sstevel@tonic-gate j++) { 18477c478bd9Sstevel@tonic-gate if (wordsize == sizeof (int32_t)) { 18487c478bd9Sstevel@tonic-gate val32 = thp[j + 1]; 18497c478bd9Sstevel@tonic-gate vaddr = (caddr_t)&val32; 18507c478bd9Sstevel@tonic-gate } else { 18517c478bd9Sstevel@tonic-gate val = thp[i + 1]; 18527c478bd9Sstevel@tonic-gate vaddr = (caddr_t)&val; 18537c478bd9Sstevel@tonic-gate } 18547c478bd9Sstevel@tonic-gate if (ddi_copyout(vaddr, (void *) uaddr, 18557c478bd9Sstevel@tonic-gate wordsize, mode) != 0) { 18567c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 18577c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: " 18587c478bd9Sstevel@tonic-gate "%s@%s(%s#%d) uaddr %p " 18597c478bd9Sstevel@tonic-gate "EFAULT\n", cmdstr, 18607c478bd9Sstevel@tonic-gate PM_DEVICE(dip), 18617c478bd9Sstevel@tonic-gate (void *)uaddr)) 18627c478bd9Sstevel@tonic-gate ret = EFAULT; 18637c478bd9Sstevel@tonic-gate break; 18647c478bd9Sstevel@tonic-gate } 18657c478bd9Sstevel@tonic-gate vaddr = uaddr; 18667c478bd9Sstevel@tonic-gate vaddr += wordsize; 18677c478bd9Sstevel@tonic-gate uaddr = (caddr_t)vaddr; 18687c478bd9Sstevel@tonic-gate } 18697c478bd9Sstevel@tonic-gate } 18707c478bd9Sstevel@tonic-gate if (ret) 18717c478bd9Sstevel@tonic-gate break; 18727c478bd9Sstevel@tonic-gate /* last copyout a terminating 0 count */ 18737c478bd9Sstevel@tonic-gate if (wordsize == sizeof (int32_t)) { 18747c478bd9Sstevel@tonic-gate val32 = 0; 18757c478bd9Sstevel@tonic-gate vaddr = (caddr_t)&val32; 18767c478bd9Sstevel@tonic-gate } else { 18777c478bd9Sstevel@tonic-gate ASSERT(wordsize == sizeof (int)); 18787c478bd9Sstevel@tonic-gate val = 0; 18797c478bd9Sstevel@tonic-gate vaddr = (caddr_t)&val; 18807c478bd9Sstevel@tonic-gate } 18817c478bd9Sstevel@tonic-gate if (ddi_copyout(vaddr, uaddr, wordsize, mode) != 0) { 18827c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 18837c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s(%s#%d) " 18847c478bd9Sstevel@tonic-gate "vaddr %p (0 count) EFAULT\n", cmdstr, 18857c478bd9Sstevel@tonic-gate PM_DEVICE(dip), (void *)vaddr)) 18867c478bd9Sstevel@tonic-gate ret = EFAULT; 18877c478bd9Sstevel@tonic-gate break; 18887c478bd9Sstevel@tonic-gate } 18897c478bd9Sstevel@tonic-gate /* finished, so don't need to increment addresses */ 18907c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 18917c478bd9Sstevel@tonic-gate ret = 0; 18927c478bd9Sstevel@tonic-gate break; 18937c478bd9Sstevel@tonic-gate } 18947c478bd9Sstevel@tonic-gate 18957c478bd9Sstevel@tonic-gate case PM_GET_STATS: 18967c478bd9Sstevel@tonic-gate { 18977c478bd9Sstevel@tonic-gate time_t now; 18987c478bd9Sstevel@tonic-gate time_t *timestamp; 18997c478bd9Sstevel@tonic-gate extern int pm_cur_power(pm_component_t *cp); 19007c478bd9Sstevel@tonic-gate int musthave; 19017c478bd9Sstevel@tonic-gate int wordsize; 19027c478bd9Sstevel@tonic-gate 19037c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 19047c478bd9Sstevel@tonic-gate if ((mode & DATAMODEL_MASK) == DATAMODEL_ILP32) { 19057c478bd9Sstevel@tonic-gate wordsize = sizeof (int32_t); 19067c478bd9Sstevel@tonic-gate } else 19077c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 19087c478bd9Sstevel@tonic-gate { 19097c478bd9Sstevel@tonic-gate wordsize = sizeof (int); 19107c478bd9Sstevel@tonic-gate } 19117c478bd9Sstevel@tonic-gate 19127c478bd9Sstevel@tonic-gate comps = PM_NUMCMPTS(dip); 19137c478bd9Sstevel@tonic-gate if (comps == 0 || PM_GET_PM_INFO(dip) == NULL) { 19147c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s no components" 19157c478bd9Sstevel@tonic-gate " or not power managed--EINVAL\n", cmdstr, 19167c478bd9Sstevel@tonic-gate req.physpath)) 19177c478bd9Sstevel@tonic-gate ret = EINVAL; 19187c478bd9Sstevel@tonic-gate break; 19197c478bd9Sstevel@tonic-gate } 19207c478bd9Sstevel@tonic-gate musthave = comps * 2 * wordsize; 19217c478bd9Sstevel@tonic-gate if (req.datasize < musthave) { 19227c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: size %lu, need " 19237c478bd9Sstevel@tonic-gate "%d--EINVAL\n", cmdstr, req.datasize, 19247c478bd9Sstevel@tonic-gate musthave)) 19257c478bd9Sstevel@tonic-gate ret = EINVAL; 19267c478bd9Sstevel@tonic-gate break; 19277c478bd9Sstevel@tonic-gate } 19287c478bd9Sstevel@tonic-gate 19297c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 19307c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, &now); 19317c478bd9Sstevel@tonic-gate timestamp = kmem_zalloc(comps * sizeof (time_t), 19327c478bd9Sstevel@tonic-gate KM_SLEEP); 19337c478bd9Sstevel@tonic-gate pm_get_timestamps(dip, timestamp); 19347c478bd9Sstevel@tonic-gate /* 19357c478bd9Sstevel@tonic-gate * First the current power levels 19367c478bd9Sstevel@tonic-gate */ 19377c478bd9Sstevel@tonic-gate for (i = 0; i < comps; i++) { 19387c478bd9Sstevel@tonic-gate int curpwr; 19397c478bd9Sstevel@tonic-gate int32_t curpwr32; 19407c478bd9Sstevel@tonic-gate caddr_t cpaddr; 19417c478bd9Sstevel@tonic-gate 19427c478bd9Sstevel@tonic-gate cp = PM_CP(dip, i); 19437c478bd9Sstevel@tonic-gate if (wordsize == sizeof (int)) { 19447c478bd9Sstevel@tonic-gate curpwr = pm_cur_power(cp); 19457c478bd9Sstevel@tonic-gate cpaddr = (caddr_t)&curpwr; 19467c478bd9Sstevel@tonic-gate } else { 19477c478bd9Sstevel@tonic-gate ASSERT(wordsize == sizeof (int32_t)); 19487c478bd9Sstevel@tonic-gate curpwr32 = pm_cur_power(cp); 19497c478bd9Sstevel@tonic-gate cpaddr = (caddr_t)&curpwr32; 19507c478bd9Sstevel@tonic-gate } 19517c478bd9Sstevel@tonic-gate if (ddi_copyout(cpaddr, (void *) req.data, 19527c478bd9Sstevel@tonic-gate wordsize, mode) != 0) { 19537c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 19547c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s" 19557c478bd9Sstevel@tonic-gate "(%s#%d) req.data %p EFAULT\n", 19567c478bd9Sstevel@tonic-gate cmdstr, PM_DEVICE(dip), 19577c478bd9Sstevel@tonic-gate (void *)req.data)) 19587c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 19597c478bd9Sstevel@tonic-gate return (EFAULT); 19607c478bd9Sstevel@tonic-gate } 19617c478bd9Sstevel@tonic-gate cpaddr = (caddr_t)req.data; 19627c478bd9Sstevel@tonic-gate cpaddr += wordsize; 19637c478bd9Sstevel@tonic-gate req.data = cpaddr; 19647c478bd9Sstevel@tonic-gate } 19657c478bd9Sstevel@tonic-gate /* 19667c478bd9Sstevel@tonic-gate * Then the times remaining 19677c478bd9Sstevel@tonic-gate */ 19687c478bd9Sstevel@tonic-gate for (i = 0; i < comps; i++) { 19697c478bd9Sstevel@tonic-gate int retval; 19707c478bd9Sstevel@tonic-gate int32_t retval32; 19717c478bd9Sstevel@tonic-gate caddr_t rvaddr; 19727c478bd9Sstevel@tonic-gate int curpwr; 19737c478bd9Sstevel@tonic-gate 19747c478bd9Sstevel@tonic-gate cp = PM_CP(dip, i); 19757c478bd9Sstevel@tonic-gate curpwr = cp->pmc_cur_pwr; 19767c478bd9Sstevel@tonic-gate if (curpwr == 0 || timestamp[i] == 0) { 19777c478bd9Sstevel@tonic-gate PMD(PMD_STATS, ("ioctl: %s: " 19787c478bd9Sstevel@tonic-gate "cur_pwer %x, timestamp %lx\n", 19797c478bd9Sstevel@tonic-gate cmdstr, curpwr, timestamp[i])) 19807c478bd9Sstevel@tonic-gate retval = INT_MAX; 19817c478bd9Sstevel@tonic-gate } else { 19827c478bd9Sstevel@tonic-gate int thresh; 19837c478bd9Sstevel@tonic-gate (void) pm_current_threshold(dip, i, 19847c478bd9Sstevel@tonic-gate &thresh); 19857c478bd9Sstevel@tonic-gate retval = thresh - (now - timestamp[i]); 19867c478bd9Sstevel@tonic-gate PMD(PMD_STATS, ("ioctl: %s: current " 19877c478bd9Sstevel@tonic-gate "thresh %x, now %lx, timestamp %lx," 19887c478bd9Sstevel@tonic-gate " retval %x\n", cmdstr, thresh, now, 19897c478bd9Sstevel@tonic-gate timestamp[i], retval)) 19907c478bd9Sstevel@tonic-gate } 19917c478bd9Sstevel@tonic-gate if (wordsize == sizeof (int)) { 19927c478bd9Sstevel@tonic-gate rvaddr = (caddr_t)&retval; 19937c478bd9Sstevel@tonic-gate } else { 19947c478bd9Sstevel@tonic-gate ASSERT(wordsize == sizeof (int32_t)); 19957c478bd9Sstevel@tonic-gate retval32 = retval; 19967c478bd9Sstevel@tonic-gate rvaddr = (caddr_t)&retval32; 19977c478bd9Sstevel@tonic-gate } 19987c478bd9Sstevel@tonic-gate if (ddi_copyout(rvaddr, (void *) req.data, 19997c478bd9Sstevel@tonic-gate wordsize, mode) != 0) { 20007c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 20017c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s" 20027c478bd9Sstevel@tonic-gate "(%s#%d) req.data %p EFAULT\n", 20037c478bd9Sstevel@tonic-gate cmdstr, PM_DEVICE(dip), 20047c478bd9Sstevel@tonic-gate (void *)req.data)) 20057c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 2006*2df1fe9cSrandyf kmem_free(timestamp, 2007*2df1fe9cSrandyf comps * sizeof (time_t)); 20087c478bd9Sstevel@tonic-gate return (EFAULT); 20097c478bd9Sstevel@tonic-gate } 20107c478bd9Sstevel@tonic-gate rvaddr = (caddr_t)req.data; 20117c478bd9Sstevel@tonic-gate rvaddr += wordsize; 20127c478bd9Sstevel@tonic-gate req.data = (int *)rvaddr; 20137c478bd9Sstevel@tonic-gate } 20147c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 20157c478bd9Sstevel@tonic-gate *rval_p = comps; 20167c478bd9Sstevel@tonic-gate ret = 0; 20177c478bd9Sstevel@tonic-gate kmem_free(timestamp, comps * sizeof (time_t)); 20187c478bd9Sstevel@tonic-gate break; 20197c478bd9Sstevel@tonic-gate } 20207c478bd9Sstevel@tonic-gate 2021*2df1fe9cSrandyf case PM_GET_CMD_NAME: 2022*2df1fe9cSrandyf { 2023*2df1fe9cSrandyf PMD(PMD_IOCTL, ("%s: %s\n", cmdstr, 2024*2df1fe9cSrandyf pm_decode_cmd(req.value))) 2025*2df1fe9cSrandyf if (ret = copyoutstr(pm_decode_cmd(req.value), 2026*2df1fe9cSrandyf (char *)req.data, req.datasize, &lencopied)) { 2027*2df1fe9cSrandyf PMD(PMD_ERROR, ("ioctl: %s: %s@%s(%s#%d) " 2028*2df1fe9cSrandyf "copyoutstr %p failed--EFAULT\n", cmdstr, 2029*2df1fe9cSrandyf PM_DEVICE(dip), (void *)req.data)) 2030*2df1fe9cSrandyf break; 2031*2df1fe9cSrandyf } 2032*2df1fe9cSrandyf *rval_p = lencopied; 2033*2df1fe9cSrandyf ret = 0; 2034*2df1fe9cSrandyf break; 2035*2df1fe9cSrandyf } 2036*2df1fe9cSrandyf 20377c478bd9Sstevel@tonic-gate case PM_GET_COMPONENT_NAME: 2038*2df1fe9cSrandyf { 20397c478bd9Sstevel@tonic-gate ASSERT(dip); 20407c478bd9Sstevel@tonic-gate if (!e_pm_valid_comp(dip, req.component, &cp)) { 20417c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s(%s#%d) " 20427c478bd9Sstevel@tonic-gate "component %d > numcmpts - 1 %d--EINVAL\n", 20437c478bd9Sstevel@tonic-gate cmdstr, PM_DEVICE(dip), req.component, 20447c478bd9Sstevel@tonic-gate PM_NUMCMPTS(dip) - 1)) 20457c478bd9Sstevel@tonic-gate ret = EINVAL; 20467c478bd9Sstevel@tonic-gate break; 20477c478bd9Sstevel@tonic-gate } 20487c478bd9Sstevel@tonic-gate if (ret = copyoutstr(cp->pmc_comp.pmc_name, 20497c478bd9Sstevel@tonic-gate (char *)req.data, req.datasize, &lencopied)) { 20507c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s(%s#%d) " 20517c478bd9Sstevel@tonic-gate "copyoutstr %p failed--EFAULT\n", cmdstr, 20527c478bd9Sstevel@tonic-gate PM_DEVICE(dip), (void *)req.data)) 20537c478bd9Sstevel@tonic-gate break; 20547c478bd9Sstevel@tonic-gate } 20557c478bd9Sstevel@tonic-gate *rval_p = lencopied; 20567c478bd9Sstevel@tonic-gate ret = 0; 20577c478bd9Sstevel@tonic-gate break; 2058*2df1fe9cSrandyf } 20597c478bd9Sstevel@tonic-gate 20607c478bd9Sstevel@tonic-gate case PM_GET_POWER_NAME: 20617c478bd9Sstevel@tonic-gate { 20627c478bd9Sstevel@tonic-gate int i; 20637c478bd9Sstevel@tonic-gate 20647c478bd9Sstevel@tonic-gate ASSERT(dip); 20657c478bd9Sstevel@tonic-gate if (!e_pm_valid_comp(dip, req.component, &cp)) { 20667c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s(%s#%d) " 20677c478bd9Sstevel@tonic-gate "component %d > numcmpts - 1 %d--EINVAL\n", 20687c478bd9Sstevel@tonic-gate cmdstr, PM_DEVICE(dip), req.component, 20697c478bd9Sstevel@tonic-gate PM_NUMCMPTS(dip) - 1)) 20707c478bd9Sstevel@tonic-gate ret = EINVAL; 20717c478bd9Sstevel@tonic-gate break; 20727c478bd9Sstevel@tonic-gate } 20737c478bd9Sstevel@tonic-gate if ((i = req.value) < 0 || 20747c478bd9Sstevel@tonic-gate i > cp->pmc_comp.pmc_numlevels - 1) { 20757c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s(%s#%d) " 20767c478bd9Sstevel@tonic-gate "value %d > num_levels - 1 %d--EINVAL\n", 20777c478bd9Sstevel@tonic-gate cmdstr, PM_DEVICE(dip), req.value, 20787c478bd9Sstevel@tonic-gate cp->pmc_comp.pmc_numlevels - 1)) 20797c478bd9Sstevel@tonic-gate ret = EINVAL; 20807c478bd9Sstevel@tonic-gate break; 20817c478bd9Sstevel@tonic-gate } 20827c478bd9Sstevel@tonic-gate dep = cp->pmc_comp.pmc_lnames[req.value]; 20837c478bd9Sstevel@tonic-gate if (ret = copyoutstr(dep, 20847c478bd9Sstevel@tonic-gate req.data, req.datasize, &lencopied)) { 20857c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s(%s#%d) " 20867c478bd9Sstevel@tonic-gate "copyoutstr %p failed--EFAULT\n", cmdstr, 20877c478bd9Sstevel@tonic-gate PM_DEVICE(dip), (void *)req.data)) 20887c478bd9Sstevel@tonic-gate break; 20897c478bd9Sstevel@tonic-gate } 20907c478bd9Sstevel@tonic-gate *rval_p = lencopied; 20917c478bd9Sstevel@tonic-gate ret = 0; 20927c478bd9Sstevel@tonic-gate break; 20937c478bd9Sstevel@tonic-gate } 20947c478bd9Sstevel@tonic-gate 20957c478bd9Sstevel@tonic-gate case PM_GET_POWER_LEVELS: 20967c478bd9Sstevel@tonic-gate { 20977c478bd9Sstevel@tonic-gate int musthave; 20987c478bd9Sstevel@tonic-gate int numlevels; 20997c478bd9Sstevel@tonic-gate int wordsize; 21007c478bd9Sstevel@tonic-gate 21017c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 21027c478bd9Sstevel@tonic-gate if ((mode & DATAMODEL_MASK) == DATAMODEL_ILP32) { 21037c478bd9Sstevel@tonic-gate wordsize = sizeof (int32_t); 21047c478bd9Sstevel@tonic-gate } else 21057c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 21067c478bd9Sstevel@tonic-gate { 21077c478bd9Sstevel@tonic-gate wordsize = sizeof (int); 21087c478bd9Sstevel@tonic-gate } 21097c478bd9Sstevel@tonic-gate ASSERT(dip); 21107c478bd9Sstevel@tonic-gate 21117c478bd9Sstevel@tonic-gate if (!e_pm_valid_comp(dip, req.component, &cp)) { 21127c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s(%s#%d) " 21137c478bd9Sstevel@tonic-gate "has %d components, component %d requested" 21147c478bd9Sstevel@tonic-gate "--EINVAL\n", cmdstr, PM_DEVICE(dip), 21157c478bd9Sstevel@tonic-gate PM_NUMCMPTS(dip), req.component)) 21167c478bd9Sstevel@tonic-gate ret = EINVAL; 21177c478bd9Sstevel@tonic-gate break; 21187c478bd9Sstevel@tonic-gate } 21197c478bd9Sstevel@tonic-gate numlevels = cp->pmc_comp.pmc_numlevels; 21207c478bd9Sstevel@tonic-gate musthave = numlevels * wordsize; 21217c478bd9Sstevel@tonic-gate if (req.datasize < musthave) { 21227c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: size %lu, need " 21237c478bd9Sstevel@tonic-gate "%d--EINVAL\n", cmdstr, req.datasize, 21247c478bd9Sstevel@tonic-gate musthave)) 21257c478bd9Sstevel@tonic-gate ret = EINVAL; 21267c478bd9Sstevel@tonic-gate break; 21277c478bd9Sstevel@tonic-gate } 21287c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 21297c478bd9Sstevel@tonic-gate for (i = 0; i < numlevels; i++) { 21307c478bd9Sstevel@tonic-gate int level; 21317c478bd9Sstevel@tonic-gate int32_t level32; 21327c478bd9Sstevel@tonic-gate caddr_t laddr; 21337c478bd9Sstevel@tonic-gate 21347c478bd9Sstevel@tonic-gate if (wordsize == sizeof (int)) { 21357c478bd9Sstevel@tonic-gate level = cp->pmc_comp.pmc_lvals[i]; 21367c478bd9Sstevel@tonic-gate laddr = (caddr_t)&level; 21377c478bd9Sstevel@tonic-gate } else { 21387c478bd9Sstevel@tonic-gate level32 = cp->pmc_comp.pmc_lvals[i]; 21397c478bd9Sstevel@tonic-gate laddr = (caddr_t)&level32; 21407c478bd9Sstevel@tonic-gate } 21417c478bd9Sstevel@tonic-gate if (ddi_copyout(laddr, (void *) req.data, 21427c478bd9Sstevel@tonic-gate wordsize, mode) != 0) { 21437c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 21447c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s" 21457c478bd9Sstevel@tonic-gate "(%s#%d) laddr %p EFAULT\n", 21467c478bd9Sstevel@tonic-gate cmdstr, PM_DEVICE(dip), 21477c478bd9Sstevel@tonic-gate (void *)laddr)) 21487c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 21497c478bd9Sstevel@tonic-gate return (EFAULT); 21507c478bd9Sstevel@tonic-gate } 21517c478bd9Sstevel@tonic-gate laddr = (caddr_t)req.data; 21527c478bd9Sstevel@tonic-gate laddr += wordsize; 21537c478bd9Sstevel@tonic-gate req.data = (int *)laddr; 21547c478bd9Sstevel@tonic-gate } 21557c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 21567c478bd9Sstevel@tonic-gate *rval_p = numlevels; 21577c478bd9Sstevel@tonic-gate ret = 0; 21587c478bd9Sstevel@tonic-gate break; 21597c478bd9Sstevel@tonic-gate } 21607c478bd9Sstevel@tonic-gate 21617c478bd9Sstevel@tonic-gate 21627c478bd9Sstevel@tonic-gate case PM_GET_NUM_POWER_LEVELS: 2163*2df1fe9cSrandyf { 21647c478bd9Sstevel@tonic-gate if (!e_pm_valid_comp(dip, req.component, &cp)) { 21657c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: %s@%s(%s#%d) " 21667c478bd9Sstevel@tonic-gate "component %d > numcmpts - 1 %d--EINVAL\n", 21677c478bd9Sstevel@tonic-gate cmdstr, PM_DEVICE(dip), req.component, 21687c478bd9Sstevel@tonic-gate PM_NUMCMPTS(dip) - 1)) 21697c478bd9Sstevel@tonic-gate ret = EINVAL; 21707c478bd9Sstevel@tonic-gate break; 21717c478bd9Sstevel@tonic-gate } 21727c478bd9Sstevel@tonic-gate *rval_p = cp->pmc_comp.pmc_numlevels; 21737c478bd9Sstevel@tonic-gate ret = 0; 21747c478bd9Sstevel@tonic-gate break; 2175*2df1fe9cSrandyf } 21767c478bd9Sstevel@tonic-gate 21777c478bd9Sstevel@tonic-gate case PM_GET_DEVICE_THRESHOLD_BASIS: 2178*2df1fe9cSrandyf { 21797c478bd9Sstevel@tonic-gate ret = 0; 21807c478bd9Sstevel@tonic-gate PM_LOCK_DIP(dip); 21817c478bd9Sstevel@tonic-gate if ((info = PM_GET_PM_INFO(dip)) == NULL) { 21827c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 21837c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: " 21847c478bd9Sstevel@tonic-gate "PM_NO_PM_COMPONENTS\n", cmdstr)) 21857c478bd9Sstevel@tonic-gate *rval_p = PM_NO_PM_COMPONENTS; 21867c478bd9Sstevel@tonic-gate break; 21877c478bd9Sstevel@tonic-gate } 21887c478bd9Sstevel@tonic-gate if (PM_ISDIRECT(dip)) { 21897c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 21907c478bd9Sstevel@tonic-gate *rval_p = PM_DIRECTLY_MANAGED; 21917c478bd9Sstevel@tonic-gate break; 21927c478bd9Sstevel@tonic-gate } 21937c478bd9Sstevel@tonic-gate switch (DEVI(dip)->devi_pm_flags & PMC_THRESH_ALL) { 21947c478bd9Sstevel@tonic-gate case PMC_DEF_THRESH: 21957c478bd9Sstevel@tonic-gate case PMC_NEXDEF_THRESH: 21967c478bd9Sstevel@tonic-gate *rval_p = PM_DEFAULT_THRESHOLD; 21977c478bd9Sstevel@tonic-gate break; 21987c478bd9Sstevel@tonic-gate case PMC_DEV_THRESH: 21997c478bd9Sstevel@tonic-gate *rval_p = PM_DEVICE_THRESHOLD; 22007c478bd9Sstevel@tonic-gate break; 22017c478bd9Sstevel@tonic-gate case PMC_COMP_THRESH: 22027c478bd9Sstevel@tonic-gate *rval_p = PM_COMPONENT_THRESHOLD; 22037c478bd9Sstevel@tonic-gate break; 2204c42872d4Smh27603 case PMC_CPU_THRESH: 2205c42872d4Smh27603 *rval_p = PM_CPU_THRESHOLD; 2206c42872d4Smh27603 break; 22077c478bd9Sstevel@tonic-gate default: 22087c478bd9Sstevel@tonic-gate if (PM_ISBC(dip)) { 22097c478bd9Sstevel@tonic-gate *rval_p = PM_OLD_THRESHOLD; 22107c478bd9Sstevel@tonic-gate break; 22117c478bd9Sstevel@tonic-gate } 22127c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: default, not " 22137c478bd9Sstevel@tonic-gate "BC--EINVAL", cmdstr)) 22147c478bd9Sstevel@tonic-gate ret = EINVAL; 22157c478bd9Sstevel@tonic-gate break; 22167c478bd9Sstevel@tonic-gate } 22177c478bd9Sstevel@tonic-gate PM_UNLOCK_DIP(dip); 22187c478bd9Sstevel@tonic-gate break; 22197c478bd9Sstevel@tonic-gate } 2220*2df1fe9cSrandyf default: 2221*2df1fe9cSrandyf /* 2222*2df1fe9cSrandyf * Internal error, invalid ioctl description 2223*2df1fe9cSrandyf * force debug entry even if pm_debug not set 2224*2df1fe9cSrandyf */ 2225*2df1fe9cSrandyf #ifdef DEBUG 2226*2df1fe9cSrandyf pm_log("invalid diptype %d for cmd %d (%s)\n", 2227*2df1fe9cSrandyf pcip->diptype, cmd, pcip->name); 2228*2df1fe9cSrandyf #endif 2229*2df1fe9cSrandyf ASSERT(0); 2230*2df1fe9cSrandyf return (EIO); 2231*2df1fe9cSrandyf } 22327c478bd9Sstevel@tonic-gate break; 2233*2df1fe9cSrandyf } 22347c478bd9Sstevel@tonic-gate 22357c478bd9Sstevel@tonic-gate case PM_PSC: 2236*2df1fe9cSrandyf { 22377c478bd9Sstevel@tonic-gate /* 22387c478bd9Sstevel@tonic-gate * Commands that require pm_state_change_t as arg 22397c478bd9Sstevel@tonic-gate */ 22407c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 22417c478bd9Sstevel@tonic-gate if ((mode & DATAMODEL_MASK) == DATAMODEL_ILP32) { 22427c478bd9Sstevel@tonic-gate pscp32 = (pm_state_change32_t *)arg; 22437c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, &psc32, 22447c478bd9Sstevel@tonic-gate sizeof (psc32), mode) != 0) { 22457c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: ddi_copyin " 22467c478bd9Sstevel@tonic-gate "EFAULT\n\n", cmdstr)) 22477c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 22487c478bd9Sstevel@tonic-gate return (EFAULT); 22497c478bd9Sstevel@tonic-gate } 22507c478bd9Sstevel@tonic-gate psc.physpath = (caddr_t)(uintptr_t)psc32.physpath; 22517c478bd9Sstevel@tonic-gate psc.size = psc32.size; 22527c478bd9Sstevel@tonic-gate } else 22537c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 22547c478bd9Sstevel@tonic-gate { 22557c478bd9Sstevel@tonic-gate pscp = (pm_state_change_t *)arg; 22567c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, &psc, 22577c478bd9Sstevel@tonic-gate sizeof (psc), mode) != 0) { 22587c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: ddi_copyin " 22597c478bd9Sstevel@tonic-gate "EFAULT\n\n", cmdstr)) 22607c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 22617c478bd9Sstevel@tonic-gate return (EFAULT); 22627c478bd9Sstevel@tonic-gate } 22637c478bd9Sstevel@tonic-gate } 22647c478bd9Sstevel@tonic-gate switch (cmd) { 22657c478bd9Sstevel@tonic-gate 22667c478bd9Sstevel@tonic-gate case PM_GET_STATE_CHANGE: 22677c478bd9Sstevel@tonic-gate case PM_GET_STATE_CHANGE_WAIT: 22687c478bd9Sstevel@tonic-gate { 22697c478bd9Sstevel@tonic-gate psce_t *pscep; 22707c478bd9Sstevel@tonic-gate pm_state_change_t *p; 22717c478bd9Sstevel@tonic-gate caddr_t physpath; 22727c478bd9Sstevel@tonic-gate size_t physlen; 22737c478bd9Sstevel@tonic-gate 22747c478bd9Sstevel@tonic-gate /* 22757c478bd9Sstevel@tonic-gate * We want to know if any device has changed state. 22767c478bd9Sstevel@tonic-gate * We look up by clone. In case we have another thread 22777c478bd9Sstevel@tonic-gate * from the same process, we loop. 22787c478bd9Sstevel@tonic-gate * pm_psc_clone_to_interest() returns a locked entry. 22797c478bd9Sstevel@tonic-gate * We create an internal copy of the event entry prior 22807c478bd9Sstevel@tonic-gate * to copyout to user space because we don't want to 22817c478bd9Sstevel@tonic-gate * hold the psce_lock while doing copyout as we might 22827c478bd9Sstevel@tonic-gate * hit page fault which eventually brings us back 22837c478bd9Sstevel@tonic-gate * here requesting the same lock. 22847c478bd9Sstevel@tonic-gate */ 22857c478bd9Sstevel@tonic-gate mutex_enter(&pm_clone_lock); 22867c478bd9Sstevel@tonic-gate if (!pm_interest_registered(clone)) 22877c478bd9Sstevel@tonic-gate pm_register_watcher(clone, NULL); 22887c478bd9Sstevel@tonic-gate while ((pscep = 22897c478bd9Sstevel@tonic-gate pm_psc_clone_to_interest(clone)) == NULL) { 22907c478bd9Sstevel@tonic-gate if (cmd == PM_GET_STATE_CHANGE) { 22917c478bd9Sstevel@tonic-gate PMD(PMD_IOCTL, ("ioctl: %s: " 22927c478bd9Sstevel@tonic-gate "EWOULDBLOCK\n", cmdstr)) 22937c478bd9Sstevel@tonic-gate mutex_exit(&pm_clone_lock); 22947c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 22957c478bd9Sstevel@tonic-gate return (EWOULDBLOCK); 22967c478bd9Sstevel@tonic-gate } else { 22977c478bd9Sstevel@tonic-gate if (cv_wait_sig(&pm_clones_cv[clone], 22987c478bd9Sstevel@tonic-gate &pm_clone_lock) == 0) { 22997c478bd9Sstevel@tonic-gate mutex_exit(&pm_clone_lock); 23007c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s " 23017c478bd9Sstevel@tonic-gate "EINTR\n", cmdstr)) 23027c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 23037c478bd9Sstevel@tonic-gate return (EINTR); 23047c478bd9Sstevel@tonic-gate } 23057c478bd9Sstevel@tonic-gate } 23067c478bd9Sstevel@tonic-gate } 23077c478bd9Sstevel@tonic-gate mutex_exit(&pm_clone_lock); 23087c478bd9Sstevel@tonic-gate 23097c478bd9Sstevel@tonic-gate physlen = pscep->psce_out->size; 23107c478bd9Sstevel@tonic-gate physpath = NULL; 23117c478bd9Sstevel@tonic-gate /* 23127c478bd9Sstevel@tonic-gate * If we were unable to store the path while bringing 23137c478bd9Sstevel@tonic-gate * up the console fb upon entering the prom, we give 23147c478bd9Sstevel@tonic-gate * a "" name with the overrun event set 23157c478bd9Sstevel@tonic-gate */ 23167c478bd9Sstevel@tonic-gate if (physlen == (size_t)-1) { /* kmemalloc failed */ 23177c478bd9Sstevel@tonic-gate physpath = kmem_zalloc(1, KM_SLEEP); 23187c478bd9Sstevel@tonic-gate physlen = 1; 23197c478bd9Sstevel@tonic-gate } 23207c478bd9Sstevel@tonic-gate if ((psc.physpath == NULL) || (psc.size < physlen)) { 23217c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: EFAULT\n", cmdstr)) 23227c478bd9Sstevel@tonic-gate mutex_exit(&pscep->psce_lock); 23237c478bd9Sstevel@tonic-gate ret = EFAULT; 23247c478bd9Sstevel@tonic-gate break; 23257c478bd9Sstevel@tonic-gate } 23267c478bd9Sstevel@tonic-gate if (physpath == NULL) { 23277c478bd9Sstevel@tonic-gate physpath = kmem_zalloc(physlen, KM_SLEEP); 23287c478bd9Sstevel@tonic-gate bcopy((const void *) pscep->psce_out->physpath, 23297c478bd9Sstevel@tonic-gate (void *) physpath, physlen); 23307c478bd9Sstevel@tonic-gate } 23317c478bd9Sstevel@tonic-gate 23327c478bd9Sstevel@tonic-gate p = pscep->psce_out; 23337c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 23347c478bd9Sstevel@tonic-gate if ((mode & DATAMODEL_MASK) == DATAMODEL_ILP32) { 23357c478bd9Sstevel@tonic-gate #ifdef DEBUG 23367c478bd9Sstevel@tonic-gate size_t usrcopysize; 23377c478bd9Sstevel@tonic-gate #endif 23387c478bd9Sstevel@tonic-gate psc32.flags = (ushort_t)p->flags; 23397c478bd9Sstevel@tonic-gate psc32.event = (ushort_t)p->event; 23407c478bd9Sstevel@tonic-gate psc32.timestamp = (int32_t)p->timestamp; 23417c478bd9Sstevel@tonic-gate psc32.component = (int32_t)p->component; 23427c478bd9Sstevel@tonic-gate psc32.old_level = (int32_t)p->old_level; 23437c478bd9Sstevel@tonic-gate psc32.new_level = (int32_t)p->new_level; 23447c478bd9Sstevel@tonic-gate copysize32 = ((intptr_t)&psc32.size - 23457c478bd9Sstevel@tonic-gate (intptr_t)&psc32.component); 23467c478bd9Sstevel@tonic-gate #ifdef DEBUG 23477c478bd9Sstevel@tonic-gate usrcopysize = ((intptr_t)&pscp32->size - 23487c478bd9Sstevel@tonic-gate (intptr_t)&pscp32->component); 23497c478bd9Sstevel@tonic-gate ASSERT(usrcopysize == copysize32); 23507c478bd9Sstevel@tonic-gate #endif 23517c478bd9Sstevel@tonic-gate } else 23527c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 23537c478bd9Sstevel@tonic-gate { 23547c478bd9Sstevel@tonic-gate psc.flags = p->flags; 23557c478bd9Sstevel@tonic-gate psc.event = p->event; 23567c478bd9Sstevel@tonic-gate psc.timestamp = p->timestamp; 23577c478bd9Sstevel@tonic-gate psc.component = p->component; 23587c478bd9Sstevel@tonic-gate psc.old_level = p->old_level; 23597c478bd9Sstevel@tonic-gate psc.new_level = p->new_level; 23607c478bd9Sstevel@tonic-gate copysize = ((long)&p->size - 23617c478bd9Sstevel@tonic-gate (long)&p->component); 23627c478bd9Sstevel@tonic-gate } 23637c478bd9Sstevel@tonic-gate if (p->size != (size_t)-1) 23647c478bd9Sstevel@tonic-gate kmem_free(p->physpath, p->size); 23657c478bd9Sstevel@tonic-gate p->size = 0; 23667c478bd9Sstevel@tonic-gate p->physpath = NULL; 23677c478bd9Sstevel@tonic-gate if (pscep->psce_out == pscep->psce_last) 23687c478bd9Sstevel@tonic-gate p = pscep->psce_first; 23697c478bd9Sstevel@tonic-gate else 23707c478bd9Sstevel@tonic-gate p++; 23717c478bd9Sstevel@tonic-gate pscep->psce_out = p; 23727c478bd9Sstevel@tonic-gate mutex_exit(&pscep->psce_lock); 23737c478bd9Sstevel@tonic-gate 23747c478bd9Sstevel@tonic-gate ret = copyoutstr(physpath, psc.physpath, 23757c478bd9Sstevel@tonic-gate physlen, &lencopied); 23767c478bd9Sstevel@tonic-gate kmem_free(physpath, physlen); 23777c478bd9Sstevel@tonic-gate if (ret) { 23787c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: copyoutstr %p " 23797c478bd9Sstevel@tonic-gate "failed--EFAULT\n", cmdstr, 23807c478bd9Sstevel@tonic-gate (void *)psc.physpath)) 23817c478bd9Sstevel@tonic-gate break; 23827c478bd9Sstevel@tonic-gate } 23837c478bd9Sstevel@tonic-gate 23847c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 23857c478bd9Sstevel@tonic-gate if ((mode & DATAMODEL_MASK) == DATAMODEL_ILP32) { 23867c478bd9Sstevel@tonic-gate if (ddi_copyout(&psc32.component, 23877c478bd9Sstevel@tonic-gate &pscp32->component, copysize32, mode) 23887c478bd9Sstevel@tonic-gate != 0) { 23897c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: copyout " 23907c478bd9Sstevel@tonic-gate "failed--EFAULT\n", cmdstr)) 23917c478bd9Sstevel@tonic-gate ret = EFAULT; 23927c478bd9Sstevel@tonic-gate break; 23937c478bd9Sstevel@tonic-gate } 23947c478bd9Sstevel@tonic-gate } else 23957c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 23967c478bd9Sstevel@tonic-gate { 23977c478bd9Sstevel@tonic-gate if (ddi_copyout(&psc.component, 23987c478bd9Sstevel@tonic-gate &pscp->component, copysize, mode) != 0) { 23997c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: copyout " 24007c478bd9Sstevel@tonic-gate "failed--EFAULT\n", cmdstr)) 24017c478bd9Sstevel@tonic-gate ret = EFAULT; 24027c478bd9Sstevel@tonic-gate break; 24037c478bd9Sstevel@tonic-gate } 24047c478bd9Sstevel@tonic-gate } 24057c478bd9Sstevel@tonic-gate ret = 0; 24067c478bd9Sstevel@tonic-gate break; 24077c478bd9Sstevel@tonic-gate } 24087c478bd9Sstevel@tonic-gate 24097c478bd9Sstevel@tonic-gate case PM_DIRECT_NOTIFY: 24107c478bd9Sstevel@tonic-gate case PM_DIRECT_NOTIFY_WAIT: 24117c478bd9Sstevel@tonic-gate { 24127c478bd9Sstevel@tonic-gate psce_t *pscep; 24137c478bd9Sstevel@tonic-gate pm_state_change_t *p; 24147c478bd9Sstevel@tonic-gate caddr_t physpath; 24157c478bd9Sstevel@tonic-gate size_t physlen; 24167c478bd9Sstevel@tonic-gate /* 24177c478bd9Sstevel@tonic-gate * We want to know if any direct device of ours has 24187c478bd9Sstevel@tonic-gate * something we should know about. We look up by clone. 24197c478bd9Sstevel@tonic-gate * In case we have another thread from the same process, 24207c478bd9Sstevel@tonic-gate * we loop. 24217c478bd9Sstevel@tonic-gate * pm_psc_clone_to_direct() returns a locked entry. 24227c478bd9Sstevel@tonic-gate */ 24237c478bd9Sstevel@tonic-gate mutex_enter(&pm_clone_lock); 24247c478bd9Sstevel@tonic-gate while (pm_poll_cnt[clone] == 0 || 24257c478bd9Sstevel@tonic-gate (pscep = pm_psc_clone_to_direct(clone)) == NULL) { 24267c478bd9Sstevel@tonic-gate if (cmd == PM_DIRECT_NOTIFY) { 24277c478bd9Sstevel@tonic-gate PMD(PMD_IOCTL, ("ioctl: %s: " 24287c478bd9Sstevel@tonic-gate "EWOULDBLOCK\n", cmdstr)) 24297c478bd9Sstevel@tonic-gate mutex_exit(&pm_clone_lock); 24307c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 24317c478bd9Sstevel@tonic-gate return (EWOULDBLOCK); 24327c478bd9Sstevel@tonic-gate } else { 24337c478bd9Sstevel@tonic-gate if (cv_wait_sig(&pm_clones_cv[clone], 24347c478bd9Sstevel@tonic-gate &pm_clone_lock) == 0) { 24357c478bd9Sstevel@tonic-gate mutex_exit(&pm_clone_lock); 24367c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: " 24377c478bd9Sstevel@tonic-gate "EINTR\n", cmdstr)) 24387c478bd9Sstevel@tonic-gate ASSERT(!dipheld); 24397c478bd9Sstevel@tonic-gate return (EINTR); 24407c478bd9Sstevel@tonic-gate } 24417c478bd9Sstevel@tonic-gate } 24427c478bd9Sstevel@tonic-gate } 24437c478bd9Sstevel@tonic-gate mutex_exit(&pm_clone_lock); 24447c478bd9Sstevel@tonic-gate physlen = pscep->psce_out->size; 24457c478bd9Sstevel@tonic-gate if ((psc.physpath == NULL) || (psc.size < physlen)) { 24467c478bd9Sstevel@tonic-gate mutex_exit(&pscep->psce_lock); 24477c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: EFAULT\n", 24487c478bd9Sstevel@tonic-gate cmdstr)) 24497c478bd9Sstevel@tonic-gate ret = EFAULT; 24507c478bd9Sstevel@tonic-gate break; 24517c478bd9Sstevel@tonic-gate } 24527c478bd9Sstevel@tonic-gate physpath = kmem_zalloc(physlen, KM_SLEEP); 24537c478bd9Sstevel@tonic-gate bcopy((const void *) pscep->psce_out->physpath, 24547c478bd9Sstevel@tonic-gate (void *) physpath, physlen); 24557c478bd9Sstevel@tonic-gate 24567c478bd9Sstevel@tonic-gate p = pscep->psce_out; 24577c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 24587c478bd9Sstevel@tonic-gate if ((mode & DATAMODEL_MASK) == DATAMODEL_ILP32) { 24597c478bd9Sstevel@tonic-gate #ifdef DEBUG 24607c478bd9Sstevel@tonic-gate size_t usrcopysize; 24617c478bd9Sstevel@tonic-gate #endif 24627c478bd9Sstevel@tonic-gate psc32.component = (int32_t)p->component; 24637c478bd9Sstevel@tonic-gate psc32.flags = (ushort_t)p->flags; 24647c478bd9Sstevel@tonic-gate psc32.event = (ushort_t)p->event; 24657c478bd9Sstevel@tonic-gate psc32.timestamp = (int32_t)p->timestamp; 24667c478bd9Sstevel@tonic-gate psc32.old_level = (int32_t)p->old_level; 24677c478bd9Sstevel@tonic-gate psc32.new_level = (int32_t)p->new_level; 24687c478bd9Sstevel@tonic-gate copysize32 = (intptr_t)&psc32.size - 24697c478bd9Sstevel@tonic-gate (intptr_t)&psc32.component; 24707c478bd9Sstevel@tonic-gate PMD(PMD_DPM, ("ioctl: %s: PDN32 %s, comp %d " 24717c478bd9Sstevel@tonic-gate "%d -> %d\n", cmdstr, physpath, 24727c478bd9Sstevel@tonic-gate p->component, p->old_level, p->new_level)) 24737c478bd9Sstevel@tonic-gate #ifdef DEBUG 24747c478bd9Sstevel@tonic-gate usrcopysize = (intptr_t)&pscp32->size - 24757c478bd9Sstevel@tonic-gate (intptr_t)&pscp32->component; 24767c478bd9Sstevel@tonic-gate ASSERT(usrcopysize == copysize32); 24777c478bd9Sstevel@tonic-gate #endif 24787c478bd9Sstevel@tonic-gate } else 24797c478bd9Sstevel@tonic-gate #endif 24807c478bd9Sstevel@tonic-gate { 24817c478bd9Sstevel@tonic-gate psc.component = p->component; 24827c478bd9Sstevel@tonic-gate psc.flags = p->flags; 24837c478bd9Sstevel@tonic-gate psc.event = p->event; 24847c478bd9Sstevel@tonic-gate psc.timestamp = p->timestamp; 24857c478bd9Sstevel@tonic-gate psc.old_level = p->old_level; 24867c478bd9Sstevel@tonic-gate psc.new_level = p->new_level; 24877c478bd9Sstevel@tonic-gate copysize = (intptr_t)&p->size - 24887c478bd9Sstevel@tonic-gate (intptr_t)&p->component; 24897c478bd9Sstevel@tonic-gate PMD(PMD_DPM, ("ioctl: %s: PDN %s, comp %d " 24907c478bd9Sstevel@tonic-gate "%d -> %d\n", cmdstr, physpath, 24917c478bd9Sstevel@tonic-gate p->component, p->old_level, p->new_level)) 24927c478bd9Sstevel@tonic-gate } 24937c478bd9Sstevel@tonic-gate mutex_enter(&pm_clone_lock); 24947c478bd9Sstevel@tonic-gate PMD(PMD_IOCTL, ("ioctl: %s: pm_poll_cnt[%d] is %d " 24957c478bd9Sstevel@tonic-gate "before decrement\n", cmdstr, clone, 24967c478bd9Sstevel@tonic-gate pm_poll_cnt[clone])) 24977c478bd9Sstevel@tonic-gate pm_poll_cnt[clone]--; 24987c478bd9Sstevel@tonic-gate mutex_exit(&pm_clone_lock); 24997c478bd9Sstevel@tonic-gate kmem_free(p->physpath, p->size); 25007c478bd9Sstevel@tonic-gate p->size = 0; 25017c478bd9Sstevel@tonic-gate p->physpath = NULL; 25027c478bd9Sstevel@tonic-gate if (pscep->psce_out == pscep->psce_last) 25037c478bd9Sstevel@tonic-gate p = pscep->psce_first; 25047c478bd9Sstevel@tonic-gate else 25057c478bd9Sstevel@tonic-gate p++; 25067c478bd9Sstevel@tonic-gate pscep->psce_out = p; 25077c478bd9Sstevel@tonic-gate mutex_exit(&pscep->psce_lock); 25087c478bd9Sstevel@tonic-gate 25097c478bd9Sstevel@tonic-gate ret = copyoutstr(physpath, psc.physpath, 25107c478bd9Sstevel@tonic-gate physlen, &lencopied); 25117c478bd9Sstevel@tonic-gate kmem_free(physpath, physlen); 25127c478bd9Sstevel@tonic-gate if (ret) { 25137c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: copyoutstr %p " 25147c478bd9Sstevel@tonic-gate "failed--EFAULT\n", cmdstr, 25157c478bd9Sstevel@tonic-gate (void *)psc.physpath)) 25167c478bd9Sstevel@tonic-gate break; 25177c478bd9Sstevel@tonic-gate } 25187c478bd9Sstevel@tonic-gate 25197c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 25207c478bd9Sstevel@tonic-gate if ((mode & DATAMODEL_MASK) == DATAMODEL_ILP32) { 25217c478bd9Sstevel@tonic-gate if (ddi_copyout(&psc32.component, 25227c478bd9Sstevel@tonic-gate &pscp32->component, copysize32, mode) 25237c478bd9Sstevel@tonic-gate != 0) { 25247c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: copyout " 25257c478bd9Sstevel@tonic-gate "failed--EFAULT\n", cmdstr)) 25267c478bd9Sstevel@tonic-gate ret = EFAULT; 25277c478bd9Sstevel@tonic-gate break; 25287c478bd9Sstevel@tonic-gate } 25297c478bd9Sstevel@tonic-gate } else 25307c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 25317c478bd9Sstevel@tonic-gate { 25327c478bd9Sstevel@tonic-gate if (ddi_copyout(&psc.component, 25337c478bd9Sstevel@tonic-gate &pscp->component, copysize, mode) != 0) { 25347c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: copyout " 25357c478bd9Sstevel@tonic-gate "failed--EFAULT\n", cmdstr)) 25367c478bd9Sstevel@tonic-gate ret = EFAULT; 25377c478bd9Sstevel@tonic-gate break; 25387c478bd9Sstevel@tonic-gate } 25397c478bd9Sstevel@tonic-gate } 25407c478bd9Sstevel@tonic-gate ret = 0; 25417c478bd9Sstevel@tonic-gate break; 25427c478bd9Sstevel@tonic-gate } 25437c478bd9Sstevel@tonic-gate default: 2544*2df1fe9cSrandyf /* 2545*2df1fe9cSrandyf * Internal error, invalid ioctl description 2546*2df1fe9cSrandyf * force debug entry even if pm_debug not set 2547*2df1fe9cSrandyf */ 2548*2df1fe9cSrandyf #ifdef DEBUG 2549*2df1fe9cSrandyf pm_log("invalid diptype %d for cmd %d (%s)\n", 2550*2df1fe9cSrandyf pcip->diptype, cmd, pcip->name); 2551*2df1fe9cSrandyf #endif 25527c478bd9Sstevel@tonic-gate ASSERT(0); 2553*2df1fe9cSrandyf return (EIO); 25547c478bd9Sstevel@tonic-gate } 25557c478bd9Sstevel@tonic-gate break; 2556*2df1fe9cSrandyf } 2557*2df1fe9cSrandyf 2558*2df1fe9cSrandyf case PM_SRCH: /* command that takes a pm_searchargs_t arg */ 2559*2df1fe9cSrandyf { 2560*2df1fe9cSrandyf /* 2561*2df1fe9cSrandyf * If no ppm, then there is nothing to search. 2562*2df1fe9cSrandyf */ 2563*2df1fe9cSrandyf if (DEVI(ddi_root_node())->devi_pm_ppm == NULL) { 2564*2df1fe9cSrandyf ret = ENODEV; 2565*2df1fe9cSrandyf break; 2566*2df1fe9cSrandyf } 2567*2df1fe9cSrandyf 2568*2df1fe9cSrandyf #ifdef _MULTI_DATAMODEL 2569*2df1fe9cSrandyf if ((mode & DATAMODEL_MASK) == DATAMODEL_ILP32) { 2570*2df1fe9cSrandyf if (ddi_copyin((caddr_t)arg, &psa32, 2571*2df1fe9cSrandyf sizeof (psa32), mode) != 0) { 2572*2df1fe9cSrandyf PMD(PMD_ERROR, ("ioctl: %s: ddi_copyin " 2573*2df1fe9cSrandyf "EFAULT\n\n", cmdstr)) 2574*2df1fe9cSrandyf return (EFAULT); 2575*2df1fe9cSrandyf } 2576*2df1fe9cSrandyf if (copyinstr((void *)(uintptr_t)psa32.pms_listname, 2577*2df1fe9cSrandyf listname, MAXCOPYBUF, NULL)) { 2578*2df1fe9cSrandyf PMD(PMD_ERROR, ("ioctl: %s: 0x%p MAXCOPYBUF " 2579*2df1fe9cSrandyf "%d, " "EFAULT\n", cmdstr, 2580*2df1fe9cSrandyf (void *)(uintptr_t)psa32.pms_listname, 2581*2df1fe9cSrandyf MAXCOPYBUF)) 2582*2df1fe9cSrandyf ret = EFAULT; 2583*2df1fe9cSrandyf break; 2584*2df1fe9cSrandyf } 2585*2df1fe9cSrandyf if (copyinstr((void *)(uintptr_t)psa32.pms_manufacturer, 2586*2df1fe9cSrandyf manufacturer, MAXCOPYBUF, NULL)) { 2587*2df1fe9cSrandyf PMD(PMD_ERROR, ("ioctl: %s: 0x%p MAXCOPYBUF " 2588*2df1fe9cSrandyf "%d, " "EFAULT\n", cmdstr, 2589*2df1fe9cSrandyf (void *)(uintptr_t)psa32.pms_manufacturer, 2590*2df1fe9cSrandyf MAXCOPYBUF)) 2591*2df1fe9cSrandyf ret = EFAULT; 2592*2df1fe9cSrandyf break; 2593*2df1fe9cSrandyf } 2594*2df1fe9cSrandyf if (copyinstr((void *)(uintptr_t)psa32.pms_product, 2595*2df1fe9cSrandyf product, MAXCOPYBUF, NULL)) { 2596*2df1fe9cSrandyf PMD(PMD_ERROR, ("ioctl: %s: 0x%p MAXCOPYBUF " 2597*2df1fe9cSrandyf "%d, " "EFAULT\n", cmdstr, 2598*2df1fe9cSrandyf (void *)(uintptr_t)psa32.pms_product, 2599*2df1fe9cSrandyf MAXCOPYBUF)) 2600*2df1fe9cSrandyf ret = EFAULT; 2601*2df1fe9cSrandyf break; 2602*2df1fe9cSrandyf } 2603*2df1fe9cSrandyf } else 2604*2df1fe9cSrandyf #endif /* _MULTI_DATAMODEL */ 2605*2df1fe9cSrandyf { 2606*2df1fe9cSrandyf if (ddi_copyin((caddr_t)arg, &psa, 2607*2df1fe9cSrandyf sizeof (psa), mode) != 0) { 2608*2df1fe9cSrandyf PMD(PMD_ERROR, ("ioctl: %s: ddi_copyin " 2609*2df1fe9cSrandyf "EFAULT\n\n", cmdstr)) 2610*2df1fe9cSrandyf return (EFAULT); 2611*2df1fe9cSrandyf } 2612*2df1fe9cSrandyf if (copyinstr(psa.pms_listname, 2613*2df1fe9cSrandyf listname, MAXCOPYBUF, NULL)) { 2614*2df1fe9cSrandyf PMD(PMD_ERROR, ("ioctl: %s: 0x%p MAXCOPYBUF " 2615*2df1fe9cSrandyf "%d, " "EFAULT\n", cmdstr, 2616*2df1fe9cSrandyf (void *)psa.pms_listname, MAXCOPYBUF)) 2617*2df1fe9cSrandyf ret = EFAULT; 2618*2df1fe9cSrandyf break; 2619*2df1fe9cSrandyf } 2620*2df1fe9cSrandyf if (copyinstr(psa.pms_manufacturer, 2621*2df1fe9cSrandyf manufacturer, MAXCOPYBUF, NULL)) { 2622*2df1fe9cSrandyf PMD(PMD_ERROR, ("ioctl: %s: 0x%p MAXCOPYBUF " 2623*2df1fe9cSrandyf "%d, " "EFAULT\n", cmdstr, 2624*2df1fe9cSrandyf (void *)psa.pms_manufacturer, MAXCOPYBUF)) 2625*2df1fe9cSrandyf ret = EFAULT; 2626*2df1fe9cSrandyf break; 2627*2df1fe9cSrandyf } 2628*2df1fe9cSrandyf if (copyinstr(psa.pms_product, 2629*2df1fe9cSrandyf product, MAXCOPYBUF, NULL)) { 2630*2df1fe9cSrandyf PMD(PMD_ERROR, ("ioctl: %s: 0x%p MAXCOPYBUF " 2631*2df1fe9cSrandyf "%d, " "EFAULT\n", cmdstr, 2632*2df1fe9cSrandyf (void *)psa.pms_product, MAXCOPYBUF)) 2633*2df1fe9cSrandyf ret = EFAULT; 2634*2df1fe9cSrandyf break; 2635*2df1fe9cSrandyf } 2636*2df1fe9cSrandyf } 2637*2df1fe9cSrandyf psa.pms_listname = listname; 2638*2df1fe9cSrandyf psa.pms_manufacturer = manufacturer; 2639*2df1fe9cSrandyf psa.pms_product = product; 2640*2df1fe9cSrandyf switch (cmd) { 2641*2df1fe9cSrandyf case PM_SEARCH_LIST: 2642*2df1fe9cSrandyf ret = pm_ppm_searchlist(&psa); 2643*2df1fe9cSrandyf break; 2644*2df1fe9cSrandyf 2645*2df1fe9cSrandyf default: 2646*2df1fe9cSrandyf /* 2647*2df1fe9cSrandyf * Internal error, invalid ioctl description 2648*2df1fe9cSrandyf * force debug entry even if pm_debug not set 2649*2df1fe9cSrandyf */ 2650*2df1fe9cSrandyf #ifdef DEBUG 2651*2df1fe9cSrandyf pm_log("invalid diptype %d for cmd %d (%s)\n", 2652*2df1fe9cSrandyf pcip->diptype, cmd, pcip->name); 2653*2df1fe9cSrandyf #endif 2654*2df1fe9cSrandyf ASSERT(0); 2655*2df1fe9cSrandyf return (EIO); 2656*2df1fe9cSrandyf } 2657*2df1fe9cSrandyf break; 2658*2df1fe9cSrandyf } 26597c478bd9Sstevel@tonic-gate 26607c478bd9Sstevel@tonic-gate case NOSTRUCT: 2661*2df1fe9cSrandyf { 26627c478bd9Sstevel@tonic-gate switch (cmd) { 26637c478bd9Sstevel@tonic-gate case PM_START_PM: 2664c42872d4Smh27603 case PM_START_CPUPM: 2665*2df1fe9cSrandyf { 26667c478bd9Sstevel@tonic-gate mutex_enter(&pm_scan_lock); 2667c42872d4Smh27603 if ((cmd == PM_START_PM && autopm_enabled) || 2668c42872d4Smh27603 (cmd == PM_START_CPUPM && PM_CPUPM_ENABLED)) { 26697c478bd9Sstevel@tonic-gate mutex_exit(&pm_scan_lock); 26707c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: EBUSY\n", 26717c478bd9Sstevel@tonic-gate cmdstr)) 26727c478bd9Sstevel@tonic-gate ret = EBUSY; 26737c478bd9Sstevel@tonic-gate break; 26747c478bd9Sstevel@tonic-gate } 2675c42872d4Smh27603 if (cmd == PM_START_PM) 26767c478bd9Sstevel@tonic-gate autopm_enabled = 1; 2677c42872d4Smh27603 else 2678c42872d4Smh27603 cpupm = PM_CPUPM_ENABLE; 26797c478bd9Sstevel@tonic-gate mutex_exit(&pm_scan_lock); 26807c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), pm_start_pm_walk, &cmd); 26817c478bd9Sstevel@tonic-gate ret = 0; 26827c478bd9Sstevel@tonic-gate break; 2683*2df1fe9cSrandyf } 26847c478bd9Sstevel@tonic-gate 26857c478bd9Sstevel@tonic-gate case PM_RESET_PM: 26867c478bd9Sstevel@tonic-gate case PM_STOP_PM: 2687c42872d4Smh27603 case PM_STOP_CPUPM: 26887c478bd9Sstevel@tonic-gate { 26897c478bd9Sstevel@tonic-gate extern void pm_discard_thresholds(void); 26907c478bd9Sstevel@tonic-gate 26917c478bd9Sstevel@tonic-gate mutex_enter(&pm_scan_lock); 2692c42872d4Smh27603 if ((cmd == PM_STOP_PM && !autopm_enabled) || 2693c42872d4Smh27603 (cmd == PM_STOP_CPUPM && PM_CPUPM_DISABLED)) { 26947c478bd9Sstevel@tonic-gate mutex_exit(&pm_scan_lock); 26957c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: EINVAL\n", 26967c478bd9Sstevel@tonic-gate cmdstr)) 26977c478bd9Sstevel@tonic-gate ret = EINVAL; 26987c478bd9Sstevel@tonic-gate break; 26997c478bd9Sstevel@tonic-gate } 2700*2df1fe9cSrandyf if (cmd == PM_STOP_PM) { 27017c478bd9Sstevel@tonic-gate autopm_enabled = 0; 2702*2df1fe9cSrandyf pm_S3_enabled = 0; 2703*2df1fe9cSrandyf autoS3_enabled = 0; 2704*2df1fe9cSrandyf } else if (cmd == PM_STOP_CPUPM) { 2705c42872d4Smh27603 cpupm = PM_CPUPM_DISABLE; 2706*2df1fe9cSrandyf } else { 2707c42872d4Smh27603 autopm_enabled = 0; 2708*2df1fe9cSrandyf autoS3_enabled = 0; 2709c42872d4Smh27603 cpupm = PM_CPUPM_NOTSET; 2710c42872d4Smh27603 } 27117c478bd9Sstevel@tonic-gate mutex_exit(&pm_scan_lock); 2712c42872d4Smh27603 27137c478bd9Sstevel@tonic-gate /* 27147c478bd9Sstevel@tonic-gate * bring devices to full power level, stop scan 27157c478bd9Sstevel@tonic-gate */ 27167c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), pm_stop_pm_walk, &cmd); 27177c478bd9Sstevel@tonic-gate ret = 0; 2718c42872d4Smh27603 if (cmd == PM_STOP_PM || cmd == PM_STOP_CPUPM) 27197c478bd9Sstevel@tonic-gate break; 27207c478bd9Sstevel@tonic-gate /* 27217c478bd9Sstevel@tonic-gate * Now do only PM_RESET_PM stuff. 27227c478bd9Sstevel@tonic-gate */ 27237c478bd9Sstevel@tonic-gate pm_system_idle_threshold = pm_default_idle_threshold; 2724c42872d4Smh27603 pm_cpu_idle_threshold = 0; 27257c478bd9Sstevel@tonic-gate pm_discard_thresholds(); 27267c478bd9Sstevel@tonic-gate pm_all_to_default_thresholds(); 27277c478bd9Sstevel@tonic-gate pm_dispatch_to_dep_thread(PM_DEP_WK_REMOVE_DEP, 27287c478bd9Sstevel@tonic-gate NULL, NULL, PM_DEP_WAIT, NULL, 0); 27297c478bd9Sstevel@tonic-gate break; 27307c478bd9Sstevel@tonic-gate } 27317c478bd9Sstevel@tonic-gate 27327c478bd9Sstevel@tonic-gate case PM_GET_SYSTEM_THRESHOLD: 2733*2df1fe9cSrandyf { 27347c478bd9Sstevel@tonic-gate *rval_p = pm_system_idle_threshold; 27357c478bd9Sstevel@tonic-gate ret = 0; 27367c478bd9Sstevel@tonic-gate break; 2737*2df1fe9cSrandyf } 27387c478bd9Sstevel@tonic-gate 27397c478bd9Sstevel@tonic-gate case PM_GET_DEFAULT_SYSTEM_THRESHOLD: 2740*2df1fe9cSrandyf { 27417c478bd9Sstevel@tonic-gate *rval_p = pm_default_idle_threshold; 27427c478bd9Sstevel@tonic-gate ret = 0; 27437c478bd9Sstevel@tonic-gate break; 2744*2df1fe9cSrandyf } 27457c478bd9Sstevel@tonic-gate 2746c42872d4Smh27603 case PM_GET_CPU_THRESHOLD: 2747*2df1fe9cSrandyf { 2748c42872d4Smh27603 *rval_p = pm_cpu_idle_threshold; 2749c42872d4Smh27603 ret = 0; 2750c42872d4Smh27603 break; 2751*2df1fe9cSrandyf } 2752c42872d4Smh27603 27537c478bd9Sstevel@tonic-gate case PM_SET_SYSTEM_THRESHOLD: 2754c42872d4Smh27603 case PM_SET_CPU_THRESHOLD: 2755*2df1fe9cSrandyf { 27567c478bd9Sstevel@tonic-gate if ((int)arg < 0) { 27577c478bd9Sstevel@tonic-gate PMD(PMD_ERROR, ("ioctl: %s: arg 0x%x < 0" 27587c478bd9Sstevel@tonic-gate "--EINVAL\n", cmdstr, (int)arg)) 27597c478bd9Sstevel@tonic-gate ret = EINVAL; 27607c478bd9Sstevel@tonic-gate break; 27617c478bd9Sstevel@tonic-gate } 27627c478bd9Sstevel@tonic-gate PMD(PMD_IOCTL, ("ioctl: %s: 0x%x 0t%d\n", cmdstr, 27637c478bd9Sstevel@tonic-gate (int)arg, (int)arg)) 2764c42872d4Smh27603 if (cmd == PM_SET_SYSTEM_THRESHOLD) 27657c478bd9Sstevel@tonic-gate pm_system_idle_threshold = (int)arg; 2766c42872d4Smh27603 else { 2767c42872d4Smh27603 pm_cpu_idle_threshold = (int)arg; 2768c42872d4Smh27603 } 2769c42872d4Smh27603 ddi_walk_devs(ddi_root_node(), pm_set_idle_thresh_walk, 2770c42872d4Smh27603 (void *) &cmd); 2771c42872d4Smh27603 27727c478bd9Sstevel@tonic-gate ret = 0; 27737c478bd9Sstevel@tonic-gate break; 2774*2df1fe9cSrandyf } 27757c478bd9Sstevel@tonic-gate 27767c478bd9Sstevel@tonic-gate case PM_IDLE_DOWN: 2777*2df1fe9cSrandyf { 27787c478bd9Sstevel@tonic-gate if (pm_timeout_idledown() != 0) { 27797c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), 27807c478bd9Sstevel@tonic-gate pm_start_idledown, (void *)PMID_IOC); 27817c478bd9Sstevel@tonic-gate } 27827c478bd9Sstevel@tonic-gate ret = 0; 27837c478bd9Sstevel@tonic-gate break; 2784*2df1fe9cSrandyf } 27857c478bd9Sstevel@tonic-gate 27867c478bd9Sstevel@tonic-gate case PM_GET_PM_STATE: 2787*2df1fe9cSrandyf { 27887c478bd9Sstevel@tonic-gate if (autopm_enabled) { 27897c478bd9Sstevel@tonic-gate *rval_p = PM_SYSTEM_PM_ENABLED; 27907c478bd9Sstevel@tonic-gate } else { 27917c478bd9Sstevel@tonic-gate *rval_p = PM_SYSTEM_PM_DISABLED; 27927c478bd9Sstevel@tonic-gate } 27937c478bd9Sstevel@tonic-gate ret = 0; 27947c478bd9Sstevel@tonic-gate break; 2795*2df1fe9cSrandyf } 2796c42872d4Smh27603 2797c42872d4Smh27603 case PM_GET_CPUPM_STATE: 2798*2df1fe9cSrandyf { 2799c42872d4Smh27603 if (PM_CPUPM_ENABLED) 2800c42872d4Smh27603 *rval_p = PM_CPU_PM_ENABLED; 2801c42872d4Smh27603 else if (PM_CPUPM_DISABLED) 2802c42872d4Smh27603 *rval_p = PM_CPU_PM_DISABLED; 2803c42872d4Smh27603 else 2804c42872d4Smh27603 *rval_p = PM_CPU_PM_NOTSET; 2805c42872d4Smh27603 ret = 0; 2806c42872d4Smh27603 break; 28077c478bd9Sstevel@tonic-gate } 2808*2df1fe9cSrandyf 2809*2df1fe9cSrandyf case PM_GET_AUTOS3_STATE: 2810*2df1fe9cSrandyf { 2811*2df1fe9cSrandyf if (autoS3_enabled) { 2812*2df1fe9cSrandyf *rval_p = PM_AUTOS3_ENABLED; 2813*2df1fe9cSrandyf } else { 2814*2df1fe9cSrandyf *rval_p = PM_AUTOS3_DISABLED; 2815*2df1fe9cSrandyf } 2816*2df1fe9cSrandyf ret = 0; 28177c478bd9Sstevel@tonic-gate break; 2818*2df1fe9cSrandyf } 2819*2df1fe9cSrandyf 2820*2df1fe9cSrandyf case PM_GET_S3_SUPPORT_STATE: 2821*2df1fe9cSrandyf { 2822*2df1fe9cSrandyf if (pm_S3_enabled) { 2823*2df1fe9cSrandyf *rval_p = PM_S3_SUPPORT_ENABLED; 2824*2df1fe9cSrandyf } else { 2825*2df1fe9cSrandyf *rval_p = PM_S3_SUPPORT_DISABLED; 2826*2df1fe9cSrandyf } 2827*2df1fe9cSrandyf ret = 0; 2828*2df1fe9cSrandyf break; 2829*2df1fe9cSrandyf } 2830*2df1fe9cSrandyf 2831*2df1fe9cSrandyf /* 2832*2df1fe9cSrandyf * pmconfig tells us if the platform supports S3 2833*2df1fe9cSrandyf */ 2834*2df1fe9cSrandyf case PM_ENABLE_S3: 2835*2df1fe9cSrandyf { 2836*2df1fe9cSrandyf mutex_enter(&pm_scan_lock); 2837*2df1fe9cSrandyf if (pm_S3_enabled) { 2838*2df1fe9cSrandyf mutex_exit(&pm_scan_lock); 2839*2df1fe9cSrandyf PMD(PMD_ERROR, ("ioctl: %s: EBUSY\n", 2840*2df1fe9cSrandyf cmdstr)) 2841*2df1fe9cSrandyf ret = EBUSY; 2842*2df1fe9cSrandyf break; 2843*2df1fe9cSrandyf } 2844*2df1fe9cSrandyf pm_S3_enabled = 1; 2845*2df1fe9cSrandyf mutex_exit(&pm_scan_lock); 2846*2df1fe9cSrandyf ret = 0; 2847*2df1fe9cSrandyf break; 2848*2df1fe9cSrandyf } 2849*2df1fe9cSrandyf 2850*2df1fe9cSrandyf case PM_DISABLE_S3: 2851*2df1fe9cSrandyf { 2852*2df1fe9cSrandyf mutex_enter(&pm_scan_lock); 2853*2df1fe9cSrandyf pm_S3_enabled = 0; 2854*2df1fe9cSrandyf mutex_exit(&pm_scan_lock); 2855*2df1fe9cSrandyf ret = 0; 2856*2df1fe9cSrandyf break; 2857*2df1fe9cSrandyf } 2858*2df1fe9cSrandyf 2859*2df1fe9cSrandyf case PM_START_AUTOS3: 2860*2df1fe9cSrandyf { 2861*2df1fe9cSrandyf mutex_enter(&pm_scan_lock); 2862*2df1fe9cSrandyf if (autoS3_enabled) { 2863*2df1fe9cSrandyf mutex_exit(&pm_scan_lock); 2864*2df1fe9cSrandyf PMD(PMD_ERROR, ("ioctl: %s: EBUSY\n", 2865*2df1fe9cSrandyf cmdstr)) 2866*2df1fe9cSrandyf ret = EBUSY; 2867*2df1fe9cSrandyf break; 2868*2df1fe9cSrandyf } 2869*2df1fe9cSrandyf autoS3_enabled = 1; 2870*2df1fe9cSrandyf mutex_exit(&pm_scan_lock); 2871*2df1fe9cSrandyf ret = 0; 2872*2df1fe9cSrandyf break; 2873*2df1fe9cSrandyf } 2874*2df1fe9cSrandyf 2875*2df1fe9cSrandyf case PM_STOP_AUTOS3: 2876*2df1fe9cSrandyf { 2877*2df1fe9cSrandyf mutex_enter(&pm_scan_lock); 2878*2df1fe9cSrandyf autoS3_enabled = 0; 2879*2df1fe9cSrandyf mutex_exit(&pm_scan_lock); 2880*2df1fe9cSrandyf ret = 0; 2881*2df1fe9cSrandyf break; 2882*2df1fe9cSrandyf } 2883*2df1fe9cSrandyf 2884*2df1fe9cSrandyf default: 2885*2df1fe9cSrandyf /* 2886*2df1fe9cSrandyf * Internal error, invalid ioctl description 2887*2df1fe9cSrandyf * force debug entry even if pm_debug not set 2888*2df1fe9cSrandyf */ 2889*2df1fe9cSrandyf #ifdef DEBUG 2890*2df1fe9cSrandyf pm_log("invalid diptype %d for cmd %d (%s)\n", 2891*2df1fe9cSrandyf pcip->diptype, cmd, pcip->name); 2892*2df1fe9cSrandyf #endif 2893*2df1fe9cSrandyf ASSERT(0); 2894*2df1fe9cSrandyf return (EIO); 2895*2df1fe9cSrandyf } 2896*2df1fe9cSrandyf break; 2897*2df1fe9cSrandyf } 28987c478bd9Sstevel@tonic-gate 28997c478bd9Sstevel@tonic-gate default: 29007c478bd9Sstevel@tonic-gate /* 29017c478bd9Sstevel@tonic-gate * Internal error, invalid ioctl description 29027c478bd9Sstevel@tonic-gate * force debug entry even if pm_debug not set 29037c478bd9Sstevel@tonic-gate */ 29047c478bd9Sstevel@tonic-gate #ifdef DEBUG 29057c478bd9Sstevel@tonic-gate pm_log("ioctl: invalid str_type %d for cmd %d (%s)\n", 29067c478bd9Sstevel@tonic-gate pcip->str_type, cmd, pcip->name); 29077c478bd9Sstevel@tonic-gate #endif 29087c478bd9Sstevel@tonic-gate ASSERT(0); 29097c478bd9Sstevel@tonic-gate return (EIO); 29107c478bd9Sstevel@tonic-gate } 29117c478bd9Sstevel@tonic-gate ASSERT(ret != 0x0badcafe); /* some cmd in wrong case! */ 29127c478bd9Sstevel@tonic-gate if (dipheld) { 29137c478bd9Sstevel@tonic-gate ASSERT(dip); 29147c478bd9Sstevel@tonic-gate PMD(PMD_DHR, ("ioctl: %s: releasing %s@%s(%s#%d) for " 29157c478bd9Sstevel@tonic-gate "exiting pm_ioctl\n", cmdstr, PM_DEVICE(dip))) 29167c478bd9Sstevel@tonic-gate PM_RELE(dip); 29177c478bd9Sstevel@tonic-gate } 29187c478bd9Sstevel@tonic-gate PMD(PMD_IOCTL, ("ioctl: %s: end, ret=%d\n", cmdstr, ret)) 29197c478bd9Sstevel@tonic-gate return (ret); 29207c478bd9Sstevel@tonic-gate } 2921