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
519397407SSherry Moore * Common Development and Distribution License (the "License").
619397407SSherry Moore * 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 /*
22*07d06da5SSurya Prakki * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * Platform Power Management driver for SUNW,Sun-Blade-1000
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
307c478bd9Sstevel@tonic-gate #include <sys/conf.h>
317c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
327c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
337c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
347c478bd9Sstevel@tonic-gate #include <sys/ppmvar.h>
357c478bd9Sstevel@tonic-gate #include <sys/ppmio.h>
367c478bd9Sstevel@tonic-gate #include <sys/xcalppm_reg.h>
377c478bd9Sstevel@tonic-gate #include <sys/xcalppm_var.h>
387c478bd9Sstevel@tonic-gate #include <sys/stat.h>
397c478bd9Sstevel@tonic-gate #include <sys/epm.h>
407c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
417c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
427c478bd9Sstevel@tonic-gate #include <sys/cheetahregs.h>
437c478bd9Sstevel@tonic-gate #include <sys/us3_module.h>
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate * Locking Considerations
477c478bd9Sstevel@tonic-gate *
487c478bd9Sstevel@tonic-gate * To look at and/or modify xcppm_domain fields or elements of its list of
497c478bd9Sstevel@tonic-gate * xcppm_dev structures the domain_lock for the affected domain must be held.
507c478bd9Sstevel@tonic-gate *
517c478bd9Sstevel@tonic-gate * When the autopm framework needs to change the power of a component of a
527c478bd9Sstevel@tonic-gate * device, it needs to hold the associated power lock (see discussion at
537c478bd9Sstevel@tonic-gate * top of uts/common/os/sunpm.c).
547c478bd9Sstevel@tonic-gate *
557c478bd9Sstevel@tonic-gate * If the framework needs to lock a dev/cmpt for a device which this ppm
567c478bd9Sstevel@tonic-gate * has claimed, xcppm_ctlops will be called with PMR_PPM_LOCK_POWER. Ppm
577c478bd9Sstevel@tonic-gate * needs to be involved because, due to platform constraints, changing the
587c478bd9Sstevel@tonic-gate * power of one device may require that other devices be changed in the same
597c478bd9Sstevel@tonic-gate * operation.
607c478bd9Sstevel@tonic-gate *
617c478bd9Sstevel@tonic-gate * In some domains (e.g., cpus) the power lock must be acquired for all the
627c478bd9Sstevel@tonic-gate * affected devices to avoid possible corruption of the power states. The
637c478bd9Sstevel@tonic-gate * joint change must be an atomic operation. Ppm handles this by acquiring
647c478bd9Sstevel@tonic-gate * the domain lock, then walking the list of affected devices and acquiring
657c478bd9Sstevel@tonic-gate * the power lock for each of them. To unlock, the list is traversed and
667c478bd9Sstevel@tonic-gate * each of the power locks is freed, followed by freeing the domain lock.
677c478bd9Sstevel@tonic-gate *
687c478bd9Sstevel@tonic-gate * For other domains ppm will only be changing the power of a single device
697c478bd9Sstevel@tonic-gate * that is known to the framework. In these cases, the locking is done by
707c478bd9Sstevel@tonic-gate * acquiring the domain lock and directly calling the framework routine for
717c478bd9Sstevel@tonic-gate * getting a single power lock.
727c478bd9Sstevel@tonic-gate */
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate static int xcppm_attach(dev_info_t *, ddi_attach_cmd_t);
757c478bd9Sstevel@tonic-gate static int xcppm_detach(dev_info_t *, ddi_detach_cmd_t);
767c478bd9Sstevel@tonic-gate static int xcppm_ctlops(dev_info_t *, dev_info_t *,
777c478bd9Sstevel@tonic-gate ddi_ctl_enum_t, void *, void *);
787c478bd9Sstevel@tonic-gate static void xcppm_dev_init(ppm_dev_t *);
797c478bd9Sstevel@tonic-gate static void xcppm_dev_fini(ppm_dev_t *);
807c478bd9Sstevel@tonic-gate static void xcppm_iocset(uint8_t);
817c478bd9Sstevel@tonic-gate static uint8_t xcppm_iocget(void);
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate * Note: 1394 and pciupa were originally required to be LOCK_ALL domains.
857c478bd9Sstevel@tonic-gate * However, the underlying nexus drivers aren't able to do power mgmt
867c478bd9Sstevel@tonic-gate * (because of hw implementation issues). The locking protocol for these
877c478bd9Sstevel@tonic-gate * domains is changed to LOCK_ONE to simplify other code. The domain
887c478bd9Sstevel@tonic-gate * code itself will be removed in the future.
897c478bd9Sstevel@tonic-gate */
907c478bd9Sstevel@tonic-gate static ppm_domain_t xcppm_1394 = { "domain_1394", PPMD_LOCK_ONE };
917c478bd9Sstevel@tonic-gate static ppm_domain_t xcppm_cpu = { "domain_cpu", PPMD_LOCK_ALL };
927c478bd9Sstevel@tonic-gate static ppm_domain_t xcppm_fet = { "domain_powerfet", PPMD_LOCK_ONE };
937c478bd9Sstevel@tonic-gate static ppm_domain_t xcppm_upa = { "domain_pciupa", PPMD_LOCK_ONE };
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate ppm_domain_t *ppm_domains[] = {
967c478bd9Sstevel@tonic-gate &xcppm_1394,
977c478bd9Sstevel@tonic-gate &xcppm_cpu,
987c478bd9Sstevel@tonic-gate &xcppm_fet,
997c478bd9Sstevel@tonic-gate &xcppm_upa,
1007c478bd9Sstevel@tonic-gate NULL
1017c478bd9Sstevel@tonic-gate };
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate struct ppm_funcs ppmf = {
1057c478bd9Sstevel@tonic-gate xcppm_dev_init, /* dev_init */
1067c478bd9Sstevel@tonic-gate xcppm_dev_fini, /* dev_fini */
1077c478bd9Sstevel@tonic-gate xcppm_iocset, /* iocset */
1087c478bd9Sstevel@tonic-gate xcppm_iocget, /* iocget */
1097c478bd9Sstevel@tonic-gate };
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate * The order of entries must be from slowest to fastest and in
1147c478bd9Sstevel@tonic-gate * one-to-one correspondence with the cpu_level array.
1157c478bd9Sstevel@tonic-gate */
1167c478bd9Sstevel@tonic-gate static const uint16_t bbc_estar_control_masks[] = {
1177c478bd9Sstevel@tonic-gate BBC_ESTAR_SLOW, BBC_ESTAR_MEDIUM, BBC_ESTAR_FAST
1187c478bd9Sstevel@tonic-gate };
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate int bbc_delay = 10; /* microsec */
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * Configuration data structures
1257c478bd9Sstevel@tonic-gate */
1267c478bd9Sstevel@tonic-gate static struct cb_ops xcppm_cb_ops = {
1277c478bd9Sstevel@tonic-gate ppm_open, /* open */
1287c478bd9Sstevel@tonic-gate ppm_close, /* close */
1297c478bd9Sstevel@tonic-gate nodev, /* strategy */
1307c478bd9Sstevel@tonic-gate nodev, /* print */
1317c478bd9Sstevel@tonic-gate nodev, /* dump */
1327c478bd9Sstevel@tonic-gate nodev, /* read */
1337c478bd9Sstevel@tonic-gate nodev, /* write */
1347c478bd9Sstevel@tonic-gate ppm_ioctl, /* ioctl */
1357c478bd9Sstevel@tonic-gate nodev, /* devmap */
1367c478bd9Sstevel@tonic-gate nodev, /* mmap */
1377c478bd9Sstevel@tonic-gate nodev, /* segmap */
1387c478bd9Sstevel@tonic-gate nochpoll, /* poll */
1397c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */
1407c478bd9Sstevel@tonic-gate NULL, /* streamtab */
1417c478bd9Sstevel@tonic-gate D_MP | D_NEW, /* driver compatibility flag */
1427c478bd9Sstevel@tonic-gate CB_REV, /* cb_ops revision */
1437c478bd9Sstevel@tonic-gate nodev, /* async read */
1447c478bd9Sstevel@tonic-gate nodev /* async write */
1457c478bd9Sstevel@tonic-gate };
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate static struct bus_ops xcppm_bus_ops = {
1487c478bd9Sstevel@tonic-gate BUSO_REV,
1497c478bd9Sstevel@tonic-gate 0,
1507c478bd9Sstevel@tonic-gate 0,
1517c478bd9Sstevel@tonic-gate 0,
1527c478bd9Sstevel@tonic-gate 0,
1537c478bd9Sstevel@tonic-gate 0,
1547c478bd9Sstevel@tonic-gate ddi_no_dma_map,
1557c478bd9Sstevel@tonic-gate ddi_no_dma_allochdl,
1567c478bd9Sstevel@tonic-gate ddi_no_dma_freehdl,
1577c478bd9Sstevel@tonic-gate ddi_no_dma_bindhdl,
1587c478bd9Sstevel@tonic-gate ddi_no_dma_unbindhdl,
1597c478bd9Sstevel@tonic-gate ddi_no_dma_flush,
1607c478bd9Sstevel@tonic-gate ddi_no_dma_win,
1617c478bd9Sstevel@tonic-gate ddi_no_dma_mctl,
1627c478bd9Sstevel@tonic-gate xcppm_ctlops,
1637c478bd9Sstevel@tonic-gate 0,
1647c478bd9Sstevel@tonic-gate 0, /* (*bus_get_eventcookie)(); */
1657c478bd9Sstevel@tonic-gate 0, /* (*bus_add_eventcall)(); */
1667c478bd9Sstevel@tonic-gate 0, /* (*bus_remove_eventcall)(); */
1677c478bd9Sstevel@tonic-gate 0 /* (*bus_post_event)(); */
1687c478bd9Sstevel@tonic-gate };
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate static struct dev_ops xcppm_ops = {
1717c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev */
1727c478bd9Sstevel@tonic-gate 0, /* refcnt */
1737c478bd9Sstevel@tonic-gate ppm_getinfo, /* info */
1747c478bd9Sstevel@tonic-gate nulldev, /* identify */
1757c478bd9Sstevel@tonic-gate nulldev, /* probe */
1767c478bd9Sstevel@tonic-gate xcppm_attach, /* attach */
1777c478bd9Sstevel@tonic-gate xcppm_detach, /* detach */
1787c478bd9Sstevel@tonic-gate nodev, /* reset */
1797c478bd9Sstevel@tonic-gate &xcppm_cb_ops, /* driver operations */
1807c478bd9Sstevel@tonic-gate &xcppm_bus_ops, /* bus operations */
1817c478bd9Sstevel@tonic-gate NULL, /* power */
18219397407SSherry Moore ddi_quiesce_not_supported, /* devo_quiesce */
1837c478bd9Sstevel@tonic-gate };
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate extern struct mod_ops mod_driverops;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
1887c478bd9Sstevel@tonic-gate &mod_driverops, /* type of module - pseudo */
18919397407SSherry Moore "platform pm driver",
1907c478bd9Sstevel@tonic-gate &xcppm_ops
1917c478bd9Sstevel@tonic-gate };
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1947c478bd9Sstevel@tonic-gate MODREV_1,
1957c478bd9Sstevel@tonic-gate &modldrv,
1967c478bd9Sstevel@tonic-gate NULL
1977c478bd9Sstevel@tonic-gate };
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate int
_init(void)2017c478bd9Sstevel@tonic-gate _init(void)
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate return (ppm_init(&modlinkage, sizeof (xcppm_unit_t), "xc"));
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate int
_fini(void)2087c478bd9Sstevel@tonic-gate _fini(void)
2097c478bd9Sstevel@tonic-gate {
2107c478bd9Sstevel@tonic-gate return (EBUSY);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)2157c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
2167c478bd9Sstevel@tonic-gate {
2177c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate static int
xcppm_map_all_regs(dev_info_t * dip)2227c478bd9Sstevel@tonic-gate xcppm_map_all_regs(dev_info_t *dip)
2237c478bd9Sstevel@tonic-gate {
2247c478bd9Sstevel@tonic-gate ddi_device_acc_attr_t attr_be, attr_le;
2257c478bd9Sstevel@tonic-gate int rv0, rv1, rv2, rv3;
2267c478bd9Sstevel@tonic-gate xcppm_unit_t *unitp;
2277c478bd9Sstevel@tonic-gate caddr_t base_addr;
2287c478bd9Sstevel@tonic-gate uint8_t data8;
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ppm_statep, ppm_inst);
2317c478bd9Sstevel@tonic-gate attr_be.devacc_attr_version = DDI_DEVICE_ATTR_V0;
2327c478bd9Sstevel@tonic-gate attr_be.devacc_attr_endian_flags = DDI_STRUCTURE_BE_ACC;
2337c478bd9Sstevel@tonic-gate attr_be.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate attr_le.devacc_attr_version = DDI_DEVICE_ATTR_V0;
2367c478bd9Sstevel@tonic-gate attr_le.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
2377c478bd9Sstevel@tonic-gate attr_le.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate rv0 = ddi_regs_map_setup(dip, 0, &base_addr, 0, 0, &attr_be,
2407c478bd9Sstevel@tonic-gate &unitp->hndls.bbc_estar_ctrl);
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate unitp->regs.bbc_estar_ctrl = (uint16_t *)(base_addr +
2437c478bd9Sstevel@tonic-gate BBC_ESTAR_CTRL_OFFSET);
2447c478bd9Sstevel@tonic-gate unitp->regs.bbc_assert_change = (uint32_t *)(base_addr +
2457c478bd9Sstevel@tonic-gate BBC_ASSERT_CHANGE_OFFSET);
2467c478bd9Sstevel@tonic-gate unitp->regs.bbc_pll_settle = (uint32_t *)(base_addr +
2477c478bd9Sstevel@tonic-gate BBC_PLL_SETTLE_OFFSET);
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate rv1 = ddi_regs_map_setup(dip, 1,
2507c478bd9Sstevel@tonic-gate (caddr_t *)&unitp->regs.rio_mode_auxio,
2517c478bd9Sstevel@tonic-gate 0, 0, &attr_le, &unitp->hndls.rio_mode_auxio);
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate rv2 = ddi_regs_map_setup(dip, 2, &base_addr,
2547c478bd9Sstevel@tonic-gate 0, 0, &attr_le, &unitp->hndls.gpio_bank_select);
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate unitp->regs.gpio_bank_sel_index = (uint8_t *)(base_addr +
2577c478bd9Sstevel@tonic-gate GPIO_BANK_SEL_INDEX_OFFSET);
2587c478bd9Sstevel@tonic-gate unitp->regs.gpio_bank_sel_data = (uint8_t *)(base_addr +
2597c478bd9Sstevel@tonic-gate GPIO_BANK_SEL_DATA_OFFSET);
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate rv3 = ddi_regs_map_setup(dip, 3, &base_addr, 0, 0, &attr_le,
2627c478bd9Sstevel@tonic-gate &unitp->hndls.gpio_data_ports);
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate unitp->regs.gpio_port1_data = (uint8_t *)(base_addr +
2657c478bd9Sstevel@tonic-gate GPIO_PORT1_DATA_OFFSET);
2667c478bd9Sstevel@tonic-gate unitp->regs.gpio_port2_data = (uint8_t *)(base_addr +
2677c478bd9Sstevel@tonic-gate GPIO_PORT2_DATA_OFFSET);
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate if (rv0 != DDI_SUCCESS || rv1 != DDI_SUCCESS ||
2707c478bd9Sstevel@tonic-gate rv2 != DDI_SUCCESS || rv3 != DDI_SUCCESS) {
2717c478bd9Sstevel@tonic-gate if (rv0 == DDI_SUCCESS)
2727c478bd9Sstevel@tonic-gate ddi_regs_map_free(&unitp->hndls.bbc_estar_ctrl);
2737c478bd9Sstevel@tonic-gate if (rv1 == DDI_SUCCESS)
2747c478bd9Sstevel@tonic-gate ddi_regs_map_free(&unitp->hndls.rio_mode_auxio);
2757c478bd9Sstevel@tonic-gate if (rv2 == DDI_SUCCESS)
2767c478bd9Sstevel@tonic-gate ddi_regs_map_free(&unitp->hndls.gpio_bank_select);
2777c478bd9Sstevel@tonic-gate if (rv3 == DDI_SUCCESS)
2787c478bd9Sstevel@tonic-gate ddi_regs_map_free(&unitp->hndls.gpio_data_ports);
2797c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate /*
2837c478bd9Sstevel@tonic-gate * Ppm uses GPIO bits in Bank 0. Make sure Bank 0 is selected.
2847c478bd9Sstevel@tonic-gate */
2857c478bd9Sstevel@tonic-gate data8 = SIO_CONFIG2_INDEX;
2867c478bd9Sstevel@tonic-gate XCPPM_SETGET8(unitp->hndls.gpio_bank_select,
2877c478bd9Sstevel@tonic-gate unitp->regs.gpio_bank_sel_index, data8);
2887c478bd9Sstevel@tonic-gate data8 = XCPPM_GET8(unitp->hndls.gpio_bank_select,
2897c478bd9Sstevel@tonic-gate unitp->regs.gpio_bank_sel_data);
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate data8 &= 0x7f; /* Set Bit7 to zero */
2927c478bd9Sstevel@tonic-gate XCPPM_SETGET8(unitp->hndls.gpio_bank_select,
2937c478bd9Sstevel@tonic-gate unitp->regs.gpio_bank_sel_data, data8);
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
2967c478bd9Sstevel@tonic-gate }
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate static int
xcppm_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)3007c478bd9Sstevel@tonic-gate xcppm_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
3017c478bd9Sstevel@tonic-gate {
3027c478bd9Sstevel@tonic-gate #ifdef DEBUG
3037c478bd9Sstevel@tonic-gate char *str = "xcppm_attach";
3047c478bd9Sstevel@tonic-gate #endif
3057c478bd9Sstevel@tonic-gate xcppm_unit_t *unitp;
3067c478bd9Sstevel@tonic-gate ppm_domain_t **dompp;
3077c478bd9Sstevel@tonic-gate int retval;
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate DPRINTF(D_ATTACH, ("%s: attach cmd %d\n", str, cmd));
3107c478bd9Sstevel@tonic-gate retval = DDI_SUCCESS;
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate switch (cmd) {
3137c478bd9Sstevel@tonic-gate case DDI_ATTACH:
3147c478bd9Sstevel@tonic-gate if (ppm_inst != -1) {
3157c478bd9Sstevel@tonic-gate DPRINTF(D_ERROR,
3167c478bd9Sstevel@tonic-gate ("%s: instance already attached\n", str));
3177c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate ppm_inst = ddi_get_instance(dip);
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate /*
3227c478bd9Sstevel@tonic-gate * Allocate and initialize soft state structure
3237c478bd9Sstevel@tonic-gate */
3247c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(ppm_statep, ppm_inst) != 0)
3257c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
3267c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ppm_statep, ppm_inst);
3277c478bd9Sstevel@tonic-gate mutex_init(&unitp->unit_lock, NULL, MUTEX_DRIVER, NULL);
3287c478bd9Sstevel@tonic-gate mutex_init(&unitp->creator_lock, NULL, MUTEX_DRIVER, NULL);
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, "ppm", S_IFCHR,
3317c478bd9Sstevel@tonic-gate ppm_inst, "ddi_ppm", 0) == DDI_FAILURE) {
3327c478bd9Sstevel@tonic-gate ddi_soft_state_free(ppm_statep, ppm_inst);
3337c478bd9Sstevel@tonic-gate DPRINTF(D_ERROR,
334*07d06da5SSurya Prakki ("%s: Can't create minor for 0x%p\n", str,
335*07d06da5SSurya Prakki (void *)dip));
3367c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
3377c478bd9Sstevel@tonic-gate }
3387c478bd9Sstevel@tonic-gate ddi_report_dev(dip);
3397c478bd9Sstevel@tonic-gate unitp->dip = dip;
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate if (retval = ppm_create_db(dip))
3427c478bd9Sstevel@tonic-gate return (retval);
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate /*
3457c478bd9Sstevel@tonic-gate * Map all of the registers under the ppm node.
3467c478bd9Sstevel@tonic-gate */
3477c478bd9Sstevel@tonic-gate if (xcppm_map_all_regs(dip) != DDI_SUCCESS)
3487c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate if ((retval =
3517c478bd9Sstevel@tonic-gate pm_register_ppm(ppm_claim_dev, dip)) != DDI_SUCCESS) {
3527c478bd9Sstevel@tonic-gate DPRINTF(D_ERROR,
3537c478bd9Sstevel@tonic-gate ("%s: can't register ppm handler\n", str));
3547c478bd9Sstevel@tonic-gate return (retval);
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate for (dompp = ppm_domains; *dompp; dompp++)
3587c478bd9Sstevel@tonic-gate mutex_init(&(*dompp)->lock, NULL, MUTEX_DRIVER, NULL);
3597c478bd9Sstevel@tonic-gate
3607c478bd9Sstevel@tonic-gate break;
3617c478bd9Sstevel@tonic-gate
3627c478bd9Sstevel@tonic-gate case DDI_RESUME:
3637c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ppm_statep, ppm_inst);
3647c478bd9Sstevel@tonic-gate mutex_enter(&unitp->unit_lock);
3657c478bd9Sstevel@tonic-gate unitp->state &= ~XCPPM_ST_SUSPENDED;
3667c478bd9Sstevel@tonic-gate mutex_exit(&unitp->unit_lock);
3677c478bd9Sstevel@tonic-gate break;
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate default:
3707c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "xcppm_attach: unknown "
371*07d06da5SSurya Prakki "attach command %d, dip 0x%p\n", cmd, (void *)dip);
3727c478bd9Sstevel@tonic-gate retval = DDI_FAILURE;
3737c478bd9Sstevel@tonic-gate }
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate return (retval);
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate /*
3807c478bd9Sstevel@tonic-gate * set the front panel LED:
3817c478bd9Sstevel@tonic-gate * PPM_LEDON turns it on, PPM_LEDOFF turns it off.
3827c478bd9Sstevel@tonic-gate * for GPIO register: 0x0 means led-on, 0x2 means led-off.
3837c478bd9Sstevel@tonic-gate */
3847c478bd9Sstevel@tonic-gate static void
xcppm_set_led(int action)3857c478bd9Sstevel@tonic-gate xcppm_set_led(int action)
3867c478bd9Sstevel@tonic-gate {
3877c478bd9Sstevel@tonic-gate xcppm_unit_t *unitp;
3887c478bd9Sstevel@tonic-gate uint8_t reg;
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate ASSERT(action == PPM_LEDON || action == PPM_LEDOFF);
3917c478bd9Sstevel@tonic-gate DPRINTF(D_LED, ("xcppm_set_led: Turn LED %s\n",
3927c478bd9Sstevel@tonic-gate (action == PPM_LEDON) ? "on" : "off"));
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ppm_statep, ppm_inst);
3957c478bd9Sstevel@tonic-gate reg = XCPPM_GET8(unitp->hndls.gpio_data_ports,
3967c478bd9Sstevel@tonic-gate unitp->regs.gpio_port1_data);
3977c478bd9Sstevel@tonic-gate if (action == PPM_LEDON)
3987c478bd9Sstevel@tonic-gate reg &= ~LED;
3997c478bd9Sstevel@tonic-gate else
4007c478bd9Sstevel@tonic-gate reg |= LED;
4017c478bd9Sstevel@tonic-gate XCPPM_SETGET8(unitp->hndls.gpio_data_ports,
4027c478bd9Sstevel@tonic-gate unitp->regs.gpio_port1_data, reg);
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate static void
xcppm_blink_led(void * action)4077c478bd9Sstevel@tonic-gate xcppm_blink_led(void *action)
4087c478bd9Sstevel@tonic-gate {
4097c478bd9Sstevel@tonic-gate xcppm_unit_t *unitp;
4107c478bd9Sstevel@tonic-gate int new_action;
4117c478bd9Sstevel@tonic-gate clock_t intvl;
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ppm_statep, ppm_inst);
4147c478bd9Sstevel@tonic-gate mutex_enter(&unitp->unit_lock);
4157c478bd9Sstevel@tonic-gate if (unitp->led_tid == 0) {
4167c478bd9Sstevel@tonic-gate mutex_exit(&unitp->unit_lock);
4177c478bd9Sstevel@tonic-gate return;
4187c478bd9Sstevel@tonic-gate }
4197c478bd9Sstevel@tonic-gate
420360e6f5eSmathue if ((int)(uintptr_t)action == PPM_LEDON) {
4217c478bd9Sstevel@tonic-gate new_action = PPM_LEDOFF;
4227c478bd9Sstevel@tonic-gate intvl = PPM_LEDOFF_INTERVAL;
4237c478bd9Sstevel@tonic-gate } else {
424360e6f5eSmathue ASSERT((int)(uintptr_t)action == PPM_LEDOFF);
4257c478bd9Sstevel@tonic-gate new_action = PPM_LEDON;
4267c478bd9Sstevel@tonic-gate intvl = PPM_LEDON_INTERVAL;
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate
4297c478bd9Sstevel@tonic-gate xcppm_set_led(new_action);
430360e6f5eSmathue unitp->led_tid = timeout(xcppm_blink_led, (void *)(uintptr_t)new_action,
431360e6f5eSmathue intvl);
4327c478bd9Sstevel@tonic-gate mutex_exit(&unitp->unit_lock);
4337c478bd9Sstevel@tonic-gate }
4347c478bd9Sstevel@tonic-gate
4357c478bd9Sstevel@tonic-gate
4367c478bd9Sstevel@tonic-gate static void
xcppm_freeze_led(void * action)4377c478bd9Sstevel@tonic-gate xcppm_freeze_led(void *action)
4387c478bd9Sstevel@tonic-gate {
4397c478bd9Sstevel@tonic-gate xcppm_unit_t *unitp;
4407c478bd9Sstevel@tonic-gate timeout_id_t tid;
4417c478bd9Sstevel@tonic-gate
442360e6f5eSmathue DPRINTF(D_LOWEST, ("xcppm_freeze_led: action %d\n",
443360e6f5eSmathue (int)(uintptr_t)action));
4447c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ppm_statep, ppm_inst);
4457c478bd9Sstevel@tonic-gate mutex_enter(&unitp->unit_lock);
4467c478bd9Sstevel@tonic-gate tid = unitp->led_tid;
4477c478bd9Sstevel@tonic-gate unitp->led_tid = 0;
4487c478bd9Sstevel@tonic-gate mutex_exit(&unitp->unit_lock);
449*07d06da5SSurya Prakki (void) untimeout(tid);
4507c478bd9Sstevel@tonic-gate mutex_enter(&unitp->unit_lock);
451360e6f5eSmathue xcppm_set_led((int)(uintptr_t)action);
4527c478bd9Sstevel@tonic-gate mutex_exit(&unitp->unit_lock);
4537c478bd9Sstevel@tonic-gate }
4547c478bd9Sstevel@tonic-gate
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate /* ARGSUSED */
4577c478bd9Sstevel@tonic-gate static int
xcppm_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)4587c478bd9Sstevel@tonic-gate xcppm_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
4597c478bd9Sstevel@tonic-gate {
4607c478bd9Sstevel@tonic-gate xcppm_unit_t *unitp;
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ppm_statep, ppm_inst);
4637c478bd9Sstevel@tonic-gate DPRINTF(D_DETACH, ("xcppm_detach: cmd %d\n", cmd));
4647c478bd9Sstevel@tonic-gate
4657c478bd9Sstevel@tonic-gate switch (cmd) {
4667c478bd9Sstevel@tonic-gate case DDI_DETACH:
4677c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate case DDI_SUSPEND:
4707c478bd9Sstevel@tonic-gate mutex_enter(&unitp->unit_lock);
4717c478bd9Sstevel@tonic-gate unitp->state |= XCPPM_ST_SUSPENDED;
4727c478bd9Sstevel@tonic-gate mutex_exit(&unitp->unit_lock);
4737c478bd9Sstevel@tonic-gate
4747c478bd9Sstevel@tonic-gate /*
4757c478bd9Sstevel@tonic-gate * Suspend requires that timeout callouts to be canceled.
4767c478bd9Sstevel@tonic-gate * Turning off the LED blinking will cancel the timeout.
4777c478bd9Sstevel@tonic-gate */
4787c478bd9Sstevel@tonic-gate xcppm_freeze_led((void *)PPM_LEDON);
4797c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate default:
4827c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate }
4857c478bd9Sstevel@tonic-gate
4867c478bd9Sstevel@tonic-gate
4877c478bd9Sstevel@tonic-gate /*
4887c478bd9Sstevel@tonic-gate * Device we claimed has detached. We must get rid of
4897c478bd9Sstevel@tonic-gate * our state which was used to track this device.
4907c478bd9Sstevel@tonic-gate */
4917c478bd9Sstevel@tonic-gate static void
xcppm_detach_ctlop(dev_info_t * dip,power_req_t * reqp)4927c478bd9Sstevel@tonic-gate xcppm_detach_ctlop(dev_info_t *dip, power_req_t *reqp)
4937c478bd9Sstevel@tonic-gate {
4947c478bd9Sstevel@tonic-gate ppm_dev_t *ppmd;
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate ppmd = PPM_GET_PRIVATE(dip);
4977c478bd9Sstevel@tonic-gate if (ppmd == NULL || reqp->req.ppm_config_req.result != DDI_SUCCESS)
4987c478bd9Sstevel@tonic-gate return;
4997c478bd9Sstevel@tonic-gate
5007c478bd9Sstevel@tonic-gate ppm_rem_dev(dip);
5017c478bd9Sstevel@tonic-gate }
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate
5047c478bd9Sstevel@tonic-gate /*
5057c478bd9Sstevel@tonic-gate * The system is being resumed from a cpr suspend operation and this
5067c478bd9Sstevel@tonic-gate * device's attach entry will be called shortly. The driver will set
5077c478bd9Sstevel@tonic-gate * the device's power to a conventional starting value, and we need to
5087c478bd9Sstevel@tonic-gate * stay in sync and set our private copy to the same value.
5097c478bd9Sstevel@tonic-gate */
5107c478bd9Sstevel@tonic-gate /* ARGSUSED */
5117c478bd9Sstevel@tonic-gate static void
xcppm_resume_ctlop(dev_info_t * dip,power_req_t * reqp)5127c478bd9Sstevel@tonic-gate xcppm_resume_ctlop(dev_info_t *dip, power_req_t *reqp)
5137c478bd9Sstevel@tonic-gate {
5147c478bd9Sstevel@tonic-gate ppm_domain_t *domp;
5157c478bd9Sstevel@tonic-gate ppm_dev_t *ppmd;
5167c478bd9Sstevel@tonic-gate int powered;
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate ppmd = PPM_GET_PRIVATE(dip);
5197c478bd9Sstevel@tonic-gate if (ppmd == NULL)
5207c478bd9Sstevel@tonic-gate return;
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate /*
5237c478bd9Sstevel@tonic-gate * Maintain correct powered count for domain which cares
5247c478bd9Sstevel@tonic-gate */
5257c478bd9Sstevel@tonic-gate powered = 0;
5267c478bd9Sstevel@tonic-gate domp = ppmd->domp;
5277c478bd9Sstevel@tonic-gate mutex_enter(&domp->lock);
5287c478bd9Sstevel@tonic-gate if (domp == &xcppm_fet) {
5297c478bd9Sstevel@tonic-gate for (ppmd = domp->devlist; ppmd; ppmd = ppmd->next) {
5307c478bd9Sstevel@tonic-gate if (ppmd->dip == dip && ppmd->level)
5317c478bd9Sstevel@tonic-gate powered++;
5327c478bd9Sstevel@tonic-gate }
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate /*
5357c478bd9Sstevel@tonic-gate * If this device was powered off when the system was
5367c478bd9Sstevel@tonic-gate * suspended, this resume acts like a power-on transition,
5377c478bd9Sstevel@tonic-gate * so we adjust the count.
5387c478bd9Sstevel@tonic-gate */
5397c478bd9Sstevel@tonic-gate if (powered == 0)
5407c478bd9Sstevel@tonic-gate domp->pwr_cnt++;
5417c478bd9Sstevel@tonic-gate }
5427c478bd9Sstevel@tonic-gate
5437c478bd9Sstevel@tonic-gate for (ppmd = domp->devlist; ppmd; ppmd = ppmd->next) {
5447c478bd9Sstevel@tonic-gate if (ppmd->dip == dip)
5457c478bd9Sstevel@tonic-gate ppmd->level = ppmd->rplvl = PM_LEVEL_UNKNOWN;
5467c478bd9Sstevel@tonic-gate }
5477c478bd9Sstevel@tonic-gate mutex_exit(&domp->lock);
5487c478bd9Sstevel@tonic-gate }
5497c478bd9Sstevel@tonic-gate
5507c478bd9Sstevel@tonic-gate
5517c478bd9Sstevel@tonic-gate /*
5527c478bd9Sstevel@tonic-gate * Change the power level for a component of a device. If the change
5537c478bd9Sstevel@tonic-gate * arg is true, we call the framework to actually change the device's
5547c478bd9Sstevel@tonic-gate * power; otherwise, we just update our own copy of the power level.
5557c478bd9Sstevel@tonic-gate */
5567c478bd9Sstevel@tonic-gate static int
xcppm_set_level(ppm_dev_t * ppmd,int cmpt,int level,boolean_t change)5577c478bd9Sstevel@tonic-gate xcppm_set_level(ppm_dev_t *ppmd, int cmpt, int level, boolean_t change)
5587c478bd9Sstevel@tonic-gate {
5597c478bd9Sstevel@tonic-gate #ifdef DEBUG
5607c478bd9Sstevel@tonic-gate char *str = "xcppm_set_level";
5617c478bd9Sstevel@tonic-gate #endif
5627c478bd9Sstevel@tonic-gate int ret;
5637c478bd9Sstevel@tonic-gate
5647c478bd9Sstevel@tonic-gate ret = DDI_SUCCESS;
5657c478bd9Sstevel@tonic-gate if (change)
5667c478bd9Sstevel@tonic-gate ret = pm_power(ppmd->dip, cmpt, level);
5677c478bd9Sstevel@tonic-gate
5687c478bd9Sstevel@tonic-gate DPRINTF(D_SETLVL, ("%s: \"%s\" change=%d, old %d, new %d, ret %d\n",
5697c478bd9Sstevel@tonic-gate str, ppmd->path, change, ppmd->level, level, ret));
5707c478bd9Sstevel@tonic-gate
5717c478bd9Sstevel@tonic-gate if (ret == DDI_SUCCESS) {
5727c478bd9Sstevel@tonic-gate ppmd->level = level;
5737c478bd9Sstevel@tonic-gate ppmd->rplvl = PM_LEVEL_UNKNOWN;
5747c478bd9Sstevel@tonic-gate }
5757c478bd9Sstevel@tonic-gate
5767c478bd9Sstevel@tonic-gate return (ret);
5777c478bd9Sstevel@tonic-gate }
5787c478bd9Sstevel@tonic-gate
5797c478bd9Sstevel@tonic-gate
5807c478bd9Sstevel@tonic-gate static int
xcppm_change_power_level(ppm_dev_t * ppmd,int cmpt,int level)5817c478bd9Sstevel@tonic-gate xcppm_change_power_level(ppm_dev_t *ppmd, int cmpt, int level)
5827c478bd9Sstevel@tonic-gate {
5837c478bd9Sstevel@tonic-gate return (xcppm_set_level(ppmd, cmpt, level, B_TRUE));
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate
5867c478bd9Sstevel@tonic-gate
5877c478bd9Sstevel@tonic-gate static int
xcppm_record_level_change(ppm_dev_t * ppmd,int cmpt,int level)5887c478bd9Sstevel@tonic-gate xcppm_record_level_change(ppm_dev_t *ppmd, int cmpt, int level)
5897c478bd9Sstevel@tonic-gate {
5907c478bd9Sstevel@tonic-gate return (xcppm_set_level(ppmd, cmpt, level, B_FALSE));
5917c478bd9Sstevel@tonic-gate }
5927c478bd9Sstevel@tonic-gate
5937c478bd9Sstevel@tonic-gate
5947c478bd9Sstevel@tonic-gate static uint8_t
xcppm_gpio_port2(int action,uint8_t pos)5957c478bd9Sstevel@tonic-gate xcppm_gpio_port2(int action, uint8_t pos)
5967c478bd9Sstevel@tonic-gate {
5977c478bd9Sstevel@tonic-gate #ifdef DEBUG
5987c478bd9Sstevel@tonic-gate char *str = "xcppm_gpio_port2";
5997c478bd9Sstevel@tonic-gate #endif
6007c478bd9Sstevel@tonic-gate xcppm_unit_t *unitp;
6017c478bd9Sstevel@tonic-gate uint8_t data8, buf8;
6027c478bd9Sstevel@tonic-gate uint8_t ret;
6037c478bd9Sstevel@tonic-gate
6047c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ppm_statep, ppm_inst);
6057c478bd9Sstevel@tonic-gate mutex_enter(&unitp->gpio_lock);
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate data8 = buf8 = XCPPM_GET8(unitp->hndls.gpio_data_ports,
6087c478bd9Sstevel@tonic-gate unitp->regs.gpio_port2_data);
6097c478bd9Sstevel@tonic-gate
6107c478bd9Sstevel@tonic-gate switch (action) {
6117c478bd9Sstevel@tonic-gate case XCPPM_GETBIT:
6127c478bd9Sstevel@tonic-gate ret = data8 & pos;
6137c478bd9Sstevel@tonic-gate DPRINTF(D_GPIO, ("%s: READ: GPIO Bank2 value 0x%x\n",
6147c478bd9Sstevel@tonic-gate str, buf8));
6157c478bd9Sstevel@tonic-gate break;
6167c478bd9Sstevel@tonic-gate
6177c478bd9Sstevel@tonic-gate case XCPPM_SETBIT:
6187c478bd9Sstevel@tonic-gate case XCPPM_CLRBIT:
6197c478bd9Sstevel@tonic-gate if (action == XCPPM_SETBIT)
6207c478bd9Sstevel@tonic-gate data8 |= pos;
6217c478bd9Sstevel@tonic-gate else
6227c478bd9Sstevel@tonic-gate data8 &= ~pos;
6237c478bd9Sstevel@tonic-gate XCPPM_SETGET8(unitp->hndls.gpio_data_ports,
6247c478bd9Sstevel@tonic-gate unitp->regs.gpio_port2_data, data8);
6257c478bd9Sstevel@tonic-gate ret = data8 & pos;
6267c478bd9Sstevel@tonic-gate DPRINTF(D_GPIO, ("%s: %s: GPIO Bank2 "
6277c478bd9Sstevel@tonic-gate "bit 0x%x changed from 0x%x to 0x%x\n",
6287c478bd9Sstevel@tonic-gate str, (action == XCPPM_SETBIT) ? "UP" : "DOWN",
6297c478bd9Sstevel@tonic-gate pos, buf8, data8));
6307c478bd9Sstevel@tonic-gate break;
6317c478bd9Sstevel@tonic-gate
6327c478bd9Sstevel@tonic-gate default:
6337c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "xcalppm: unrecognized register "
6347c478bd9Sstevel@tonic-gate "IO command %d\n", action);
6357c478bd9Sstevel@tonic-gate break;
6367c478bd9Sstevel@tonic-gate }
6377c478bd9Sstevel@tonic-gate mutex_exit(&unitp->gpio_lock);
6387c478bd9Sstevel@tonic-gate
6397c478bd9Sstevel@tonic-gate return (ret);
6407c478bd9Sstevel@tonic-gate }
6417c478bd9Sstevel@tonic-gate
6427c478bd9Sstevel@tonic-gate
6437c478bd9Sstevel@tonic-gate /*
6447c478bd9Sstevel@tonic-gate * Raise the power level of a subrange of cpus. Used when cpu driver
6457c478bd9Sstevel@tonic-gate * failed an attempt to lower the power of a cpu (probably because
6467c478bd9Sstevel@tonic-gate * it got busy). Need to revert the ones we already changed.
6477c478bd9Sstevel@tonic-gate *
6487c478bd9Sstevel@tonic-gate * ecpup = the ppm_dev_t for the cpu which failed to lower power
6497c478bd9Sstevel@tonic-gate * level = power level to reset prior cpus to
6507c478bd9Sstevel@tonic-gate */
6517c478bd9Sstevel@tonic-gate static void
xcppm_revert_cpu_power(ppm_dev_t * ecpup,int level)6527c478bd9Sstevel@tonic-gate xcppm_revert_cpu_power(ppm_dev_t *ecpup, int level)
6537c478bd9Sstevel@tonic-gate {
6547c478bd9Sstevel@tonic-gate ppm_dev_t *cpup;
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate for (cpup = xcppm_cpu.devlist; cpup != ecpup; cpup = cpup->next) {
6577c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("xrcp: \"%s\", revert to level %d\n",
6587c478bd9Sstevel@tonic-gate cpup->path, level));
6597c478bd9Sstevel@tonic-gate (void) xcppm_change_power_level(cpup, 0, level);
6607c478bd9Sstevel@tonic-gate }
6617c478bd9Sstevel@tonic-gate }
6627c478bd9Sstevel@tonic-gate
6637c478bd9Sstevel@tonic-gate /*
6647c478bd9Sstevel@tonic-gate * Switch the DC/DC converter. Clearing the GPIO bit in SuperI/O puts
6657c478bd9Sstevel@tonic-gate * the converter in low power mode and setting the bit puts it back in
6667c478bd9Sstevel@tonic-gate * normal mode.
6677c478bd9Sstevel@tonic-gate */
6687c478bd9Sstevel@tonic-gate static void
xcppm_switch_dcdc_converter(int action)6697c478bd9Sstevel@tonic-gate xcppm_switch_dcdc_converter(int action)
6707c478bd9Sstevel@tonic-gate {
6717c478bd9Sstevel@tonic-gate int tries = XCPPM_VCL_TRIES;
6727c478bd9Sstevel@tonic-gate uint_t spl;
6737c478bd9Sstevel@tonic-gate uint64_t stick_begin, stick_end;
6747c478bd9Sstevel@tonic-gate uint64_t tick_begin, tick_end;
6757c478bd9Sstevel@tonic-gate uint64_t cur_speed_ratio, full_speed_ratio;
6767c478bd9Sstevel@tonic-gate static int xcppm_dcdc_lpm;
6777c478bd9Sstevel@tonic-gate
6787c478bd9Sstevel@tonic-gate switch (action) {
6797c478bd9Sstevel@tonic-gate case XCPPM_SETBIT:
6807c478bd9Sstevel@tonic-gate if (xcppm_dcdc_lpm) {
6817c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("xcppm_switch_dcdc_converter: "
6827c478bd9Sstevel@tonic-gate "switch to normal power mode.\n"));
6837c478bd9Sstevel@tonic-gate (void) xcppm_gpio_port2(action, HIGHPWR);
6847c478bd9Sstevel@tonic-gate xcppm_dcdc_lpm = 0;
6857c478bd9Sstevel@tonic-gate }
6867c478bd9Sstevel@tonic-gate break;
6877c478bd9Sstevel@tonic-gate case XCPPM_CLRBIT:
6887c478bd9Sstevel@tonic-gate /*
6897c478bd9Sstevel@tonic-gate * In some fast CPU configurations, DC/DC converter was
6907c478bd9Sstevel@tonic-gate * put in low power mode before CPUs made the transition
6917c478bd9Sstevel@tonic-gate * to 1/32 of clock speed. In those cases, system was
6927c478bd9Sstevel@tonic-gate * shut down by hardware for protection. To resolve that
6937c478bd9Sstevel@tonic-gate * problem, we make sure CPUs have made the clock transition
6947c478bd9Sstevel@tonic-gate * before the DC/DC converter has been put to low power mode.
6957c478bd9Sstevel@tonic-gate */
6967c478bd9Sstevel@tonic-gate ASSERT(xcppm_dcdc_lpm == 0);
6977c478bd9Sstevel@tonic-gate kpreempt_disable();
6987c478bd9Sstevel@tonic-gate full_speed_ratio = cpunodes[CPU->cpu_id].clock_freq /
6997c478bd9Sstevel@tonic-gate sys_tick_freq;
7007c478bd9Sstevel@tonic-gate while (tries) {
7017c478bd9Sstevel@tonic-gate spl = ddi_enter_critical();
7027c478bd9Sstevel@tonic-gate tick_begin = gettick_counter();
7037c478bd9Sstevel@tonic-gate stick_timestamp((int64_t *)&stick_begin);
7047c478bd9Sstevel@tonic-gate ddi_exit_critical(spl);
7057c478bd9Sstevel@tonic-gate drv_usecwait(XCPPM_VCL_DELAY);
7067c478bd9Sstevel@tonic-gate spl = ddi_enter_critical();
7077c478bd9Sstevel@tonic-gate tick_end = gettick_counter();
7087c478bd9Sstevel@tonic-gate stick_timestamp((int64_t *)&stick_end);
7097c478bd9Sstevel@tonic-gate ddi_exit_critical(spl);
7107c478bd9Sstevel@tonic-gate cur_speed_ratio = (tick_end - tick_begin) /
7117c478bd9Sstevel@tonic-gate (stick_end - stick_begin);
7127c478bd9Sstevel@tonic-gate
7137c478bd9Sstevel@tonic-gate /*
7147c478bd9Sstevel@tonic-gate * tick/stick at current speed should at most be
7157c478bd9Sstevel@tonic-gate * equal to full-speed tick/stick, adjusted with
7167c478bd9Sstevel@tonic-gate * full/lowest clock speed ratio. If not, speed
7177c478bd9Sstevel@tonic-gate * transition has not happened yet.
7187c478bd9Sstevel@tonic-gate */
7197c478bd9Sstevel@tonic-gate if (cur_speed_ratio <= ((full_speed_ratio /
7207c478bd9Sstevel@tonic-gate XCPPM_VCL_DIVISOR) + 1)) {
7217c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("xcppm_switch_dcdc_converter: "
7227c478bd9Sstevel@tonic-gate "switch to low power mode.\n"));
7237c478bd9Sstevel@tonic-gate (void) xcppm_gpio_port2(action, HIGHPWR);
7247c478bd9Sstevel@tonic-gate xcppm_dcdc_lpm = 1;
7257c478bd9Sstevel@tonic-gate break;
7267c478bd9Sstevel@tonic-gate }
7277c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("xcppm_switch_dcdc_converter: CPU "
7287c478bd9Sstevel@tonic-gate "has not made transition to lowest speed yet "
7297c478bd9Sstevel@tonic-gate "(%d)\n", tries));
7307c478bd9Sstevel@tonic-gate tries--;
7317c478bd9Sstevel@tonic-gate }
7327c478bd9Sstevel@tonic-gate kpreempt_enable();
7337c478bd9Sstevel@tonic-gate break;
7347c478bd9Sstevel@tonic-gate }
7357c478bd9Sstevel@tonic-gate }
7367c478bd9Sstevel@tonic-gate
7377c478bd9Sstevel@tonic-gate static void
xcppm_rio_mode(xcppm_unit_t * unitp,int mode)7387c478bd9Sstevel@tonic-gate xcppm_rio_mode(xcppm_unit_t *unitp, int mode)
7397c478bd9Sstevel@tonic-gate {
7407c478bd9Sstevel@tonic-gate uint32_t data32, buf32;
7417c478bd9Sstevel@tonic-gate
7427c478bd9Sstevel@tonic-gate mutex_enter(&unitp->gpio_lock);
7437c478bd9Sstevel@tonic-gate data32 = buf32 = XCPPM_GET32(unitp->hndls.rio_mode_auxio,
7447c478bd9Sstevel@tonic-gate unitp->regs.rio_mode_auxio);
7457c478bd9Sstevel@tonic-gate if (mode == XCPPM_SETBIT)
7467c478bd9Sstevel@tonic-gate data32 |= RIO_BBC_ESTAR_MODE;
7477c478bd9Sstevel@tonic-gate else
7487c478bd9Sstevel@tonic-gate data32 &= ~RIO_BBC_ESTAR_MODE;
7497c478bd9Sstevel@tonic-gate XCPPM_SETGET32(unitp->hndls.rio_mode_auxio,
7507c478bd9Sstevel@tonic-gate unitp->regs.rio_mode_auxio, data32);
7517c478bd9Sstevel@tonic-gate mutex_exit(&unitp->gpio_lock);
7527c478bd9Sstevel@tonic-gate
7537c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("xcppm_rio_mode: %s: change from 0x%x to 0x%x\n",
7547c478bd9Sstevel@tonic-gate (mode == XCPPM_SETBIT) ? "DOWN" : "UP", buf32, data32));
7557c478bd9Sstevel@tonic-gate }
7567c478bd9Sstevel@tonic-gate
7577c478bd9Sstevel@tonic-gate
7587c478bd9Sstevel@tonic-gate /*
7597c478bd9Sstevel@tonic-gate * change the power level of all cpus to the arg value;
7607c478bd9Sstevel@tonic-gate * the caller needs to ensure that a legal transition is requested.
7617c478bd9Sstevel@tonic-gate */
7627c478bd9Sstevel@tonic-gate static int
xcppm_change_cpu_power(int newlevel)7637c478bd9Sstevel@tonic-gate xcppm_change_cpu_power(int newlevel)
7647c478bd9Sstevel@tonic-gate {
7657c478bd9Sstevel@tonic-gate #ifdef DEBUG
7667c478bd9Sstevel@tonic-gate char *str = "xcppm_ccp";
7677c478bd9Sstevel@tonic-gate #endif
7687c478bd9Sstevel@tonic-gate int index, level, oldlevel;
7697c478bd9Sstevel@tonic-gate int lowest, highest;
7707c478bd9Sstevel@tonic-gate int undo_flag, ret;
7717c478bd9Sstevel@tonic-gate int speedup, incr;
7727c478bd9Sstevel@tonic-gate uint32_t data32;
7737c478bd9Sstevel@tonic-gate uint16_t data16;
7747c478bd9Sstevel@tonic-gate xcppm_unit_t *unitp;
7757c478bd9Sstevel@tonic-gate ppm_dev_t *cpup;
7767c478bd9Sstevel@tonic-gate dev_info_t *dip;
7777c478bd9Sstevel@tonic-gate char *chstr;
7787c478bd9Sstevel@tonic-gate
7797c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ppm_statep, ppm_inst);
7807c478bd9Sstevel@tonic-gate ASSERT(unitp);
7817c478bd9Sstevel@tonic-gate cpup = xcppm_cpu.devlist;
7827c478bd9Sstevel@tonic-gate lowest = cpup->lowest;
7837c478bd9Sstevel@tonic-gate highest = cpup->highest;
7847c478bd9Sstevel@tonic-gate
7857c478bd9Sstevel@tonic-gate /*
7867c478bd9Sstevel@tonic-gate * not all cpus may have transitioned to a known level by this time
7877c478bd9Sstevel@tonic-gate */
7887c478bd9Sstevel@tonic-gate oldlevel = (cpup->level == PM_LEVEL_UNKNOWN) ? highest : cpup->level;
7897c478bd9Sstevel@tonic-gate dip = cpup->dip;
7907c478bd9Sstevel@tonic-gate ASSERT(dip);
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("%s: old %d, new %d, highest %d, lowest %d\n",
7937c478bd9Sstevel@tonic-gate str, oldlevel, newlevel, highest, lowest));
7947c478bd9Sstevel@tonic-gate
7957c478bd9Sstevel@tonic-gate if (newlevel > oldlevel) {
7967c478bd9Sstevel@tonic-gate chstr = "UP";
7977c478bd9Sstevel@tonic-gate speedup = 1;
7987c478bd9Sstevel@tonic-gate incr = 1;
7997c478bd9Sstevel@tonic-gate } else if (newlevel < oldlevel) {
8007c478bd9Sstevel@tonic-gate chstr = "DOWN";
8017c478bd9Sstevel@tonic-gate speedup = 0;
8027c478bd9Sstevel@tonic-gate incr = -1;
8037c478bd9Sstevel@tonic-gate } else
8047c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
8057c478bd9Sstevel@tonic-gate
8067c478bd9Sstevel@tonic-gate undo_flag = 0;
8077c478bd9Sstevel@tonic-gate if (speedup) {
8087c478bd9Sstevel@tonic-gate /*
8097c478bd9Sstevel@tonic-gate * If coming up from lowest power level, set the E*
8107c478bd9Sstevel@tonic-gate * mode bit in GPIO to make power supply efficient
8117c478bd9Sstevel@tonic-gate * at normal power.
8127c478bd9Sstevel@tonic-gate */
8137c478bd9Sstevel@tonic-gate if (oldlevel == cpup->lowest) {
8147c478bd9Sstevel@tonic-gate xcppm_switch_dcdc_converter(XCPPM_SETBIT);
8157c478bd9Sstevel@tonic-gate undo_flag = 1;
8167c478bd9Sstevel@tonic-gate }
8177c478bd9Sstevel@tonic-gate } else {
8187c478bd9Sstevel@tonic-gate /*
8197c478bd9Sstevel@tonic-gate * set BBC Estar mode bit in RIO AUXIO register
8207c478bd9Sstevel@tonic-gate */
8217c478bd9Sstevel@tonic-gate if (oldlevel == highest) {
8227c478bd9Sstevel@tonic-gate xcppm_rio_mode(unitp, XCPPM_SETBIT);
8237c478bd9Sstevel@tonic-gate undo_flag = 1;
8247c478bd9Sstevel@tonic-gate }
8257c478bd9Sstevel@tonic-gate }
8267c478bd9Sstevel@tonic-gate
8277c478bd9Sstevel@tonic-gate /*
8287c478bd9Sstevel@tonic-gate * this loop will execute 1x or 2x depending on
8297c478bd9Sstevel@tonic-gate * number of times we need to change clock rates
8307c478bd9Sstevel@tonic-gate */
8317c478bd9Sstevel@tonic-gate for (level = oldlevel+incr; level != newlevel+incr; level += incr) {
8327c478bd9Sstevel@tonic-gate for (cpup = xcppm_cpu.devlist; cpup; cpup = cpup->next) {
8337c478bd9Sstevel@tonic-gate if (cpup->level == level)
8347c478bd9Sstevel@tonic-gate continue;
8357c478bd9Sstevel@tonic-gate ret = xcppm_change_power_level(cpup, 0, level);
8367c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("%s: \"%s\", %s to level %d, ret %d\n",
8377c478bd9Sstevel@tonic-gate str, cpup->path, chstr, cpup->level, ret));
8387c478bd9Sstevel@tonic-gate if (ret == DDI_SUCCESS)
8397c478bd9Sstevel@tonic-gate continue;
8407c478bd9Sstevel@tonic-gate
8417c478bd9Sstevel@tonic-gate /*
8427c478bd9Sstevel@tonic-gate * if the driver was unable to lower cpu speed,
8437c478bd9Sstevel@tonic-gate * the cpu probably got busy; set the previous
8447c478bd9Sstevel@tonic-gate * cpus back to the original level
8457c478bd9Sstevel@tonic-gate */
8467c478bd9Sstevel@tonic-gate if (speedup == 0)
8477c478bd9Sstevel@tonic-gate xcppm_revert_cpu_power(cpup, level + 1);
8487c478bd9Sstevel@tonic-gate
8497c478bd9Sstevel@tonic-gate if (undo_flag) {
8507c478bd9Sstevel@tonic-gate if (speedup)
8517c478bd9Sstevel@tonic-gate xcppm_switch_dcdc_converter(
8527c478bd9Sstevel@tonic-gate XCPPM_CLRBIT);
8537c478bd9Sstevel@tonic-gate else
8547c478bd9Sstevel@tonic-gate xcppm_rio_mode(unitp, XCPPM_CLRBIT);
8557c478bd9Sstevel@tonic-gate }
8567c478bd9Sstevel@tonic-gate return (ret);
8577c478bd9Sstevel@tonic-gate }
8587c478bd9Sstevel@tonic-gate
8597c478bd9Sstevel@tonic-gate index = level - 1;
8607c478bd9Sstevel@tonic-gate spm_change_schizo_speed(index);
8617c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("%s: safari config reg changed\n", str));
8627c478bd9Sstevel@tonic-gate
8637c478bd9Sstevel@tonic-gate /*
8647c478bd9Sstevel@tonic-gate * set the delay times for changing to this rate
8657c478bd9Sstevel@tonic-gate */
8667c478bd9Sstevel@tonic-gate data32 = XCPPM_BBC_DELAY(index);
8677c478bd9Sstevel@tonic-gate XCPPM_SETGET32(unitp->hndls.bbc_estar_ctrl,
8687c478bd9Sstevel@tonic-gate (caddr_t)unitp->regs.bbc_assert_change, data32);
8697c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("%s: %s: Wrote E* Assert Change Time "
8707c478bd9Sstevel@tonic-gate "(t1) = 0x%x\n", str, chstr, data32));
8717c478bd9Sstevel@tonic-gate
8727c478bd9Sstevel@tonic-gate data32 = XCPPM_BBC_DELAY(index);
8737c478bd9Sstevel@tonic-gate XCPPM_SETGET32(unitp->hndls.bbc_estar_ctrl,
8747c478bd9Sstevel@tonic-gate (caddr_t)unitp->regs.bbc_pll_settle, data32);
8757c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("%s: %s: Wrote E* PLL Settle Time "
8767c478bd9Sstevel@tonic-gate "(t4) = 0x%x\n", str, chstr, data32));
8777c478bd9Sstevel@tonic-gate
8787c478bd9Sstevel@tonic-gate data16 = bbc_estar_control_masks[index];
8797c478bd9Sstevel@tonic-gate XCPPM_SETGET16(unitp->hndls.bbc_estar_ctrl,
8807c478bd9Sstevel@tonic-gate (caddr_t)unitp->regs.bbc_estar_ctrl, data16);
8817c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("%s: %s: Wrote BCC E* Control = 0x%x\n",
8827c478bd9Sstevel@tonic-gate str, chstr, data16));
8837c478bd9Sstevel@tonic-gate }
8847c478bd9Sstevel@tonic-gate
8857c478bd9Sstevel@tonic-gate /*
8867c478bd9Sstevel@tonic-gate * clear CPU Estar Mode bit in the gpio register
8877c478bd9Sstevel@tonic-gate */
8887c478bd9Sstevel@tonic-gate if (speedup) {
8897c478bd9Sstevel@tonic-gate if (newlevel == highest)
8907c478bd9Sstevel@tonic-gate xcppm_rio_mode(unitp, XCPPM_CLRBIT);
8917c478bd9Sstevel@tonic-gate } else {
8927c478bd9Sstevel@tonic-gate if (newlevel == lowest)
8937c478bd9Sstevel@tonic-gate xcppm_switch_dcdc_converter(XCPPM_CLRBIT);
8947c478bd9Sstevel@tonic-gate }
8957c478bd9Sstevel@tonic-gate
8967c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
8977c478bd9Sstevel@tonic-gate }
8987c478bd9Sstevel@tonic-gate
8997c478bd9Sstevel@tonic-gate
9007c478bd9Sstevel@tonic-gate /*
9017c478bd9Sstevel@tonic-gate * Process a request to change the power level of a cpu. If all cpus
9027c478bd9Sstevel@tonic-gate * don't want to be at the same power yet, or if we are currently
9037c478bd9Sstevel@tonic-gate * refusing slowdown requests due to thermal stress, just cache the
9047c478bd9Sstevel@tonic-gate * request. Otherwise, make the change for all cpus.
9057c478bd9Sstevel@tonic-gate */
9067c478bd9Sstevel@tonic-gate /* ARGSUSED */
9077c478bd9Sstevel@tonic-gate static int
xcppm_manage_cpus(dev_info_t * dip,power_req_t * reqp,int * result)9087c478bd9Sstevel@tonic-gate xcppm_manage_cpus(dev_info_t *dip, power_req_t *reqp, int *result)
9097c478bd9Sstevel@tonic-gate {
9107c478bd9Sstevel@tonic-gate #ifdef DEBUG
9117c478bd9Sstevel@tonic-gate char *str = "xcppm_manage_cpus";
9127c478bd9Sstevel@tonic-gate #endif
9137c478bd9Sstevel@tonic-gate int old, new, ret, kmflag;
9147c478bd9Sstevel@tonic-gate ppm_dev_t *ppmd;
9157c478bd9Sstevel@tonic-gate pm_ppm_devlist_t *devlist = NULL, *p;
9167c478bd9Sstevel@tonic-gate int do_rescan = 0;
9177c478bd9Sstevel@tonic-gate dev_info_t *rescan_dip;
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate *result = DDI_SUCCESS;
9207c478bd9Sstevel@tonic-gate switch (reqp->request_type) {
9217c478bd9Sstevel@tonic-gate case PMR_PPM_SET_POWER:
9227c478bd9Sstevel@tonic-gate break;
9237c478bd9Sstevel@tonic-gate case PMR_PPM_POWER_CHANGE_NOTIFY:
9247c478bd9Sstevel@tonic-gate /* cpu driver can`t change cpu power level by itself */
9257c478bd9Sstevel@tonic-gate default:
9267c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
9277c478bd9Sstevel@tonic-gate }
9287c478bd9Sstevel@tonic-gate
9297c478bd9Sstevel@tonic-gate ppmd = PPM_GET_PRIVATE(dip);
9307c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ppmd->domp->lock));
9317c478bd9Sstevel@tonic-gate old = reqp->req.ppm_set_power_req.old_level;
9327c478bd9Sstevel@tonic-gate new = reqp->req.ppm_set_power_req.new_level;
9337c478bd9Sstevel@tonic-gate
9347c478bd9Sstevel@tonic-gate /*
9357c478bd9Sstevel@tonic-gate * At power on, the cpus are at full speed. There is no hardware
9367c478bd9Sstevel@tonic-gate * transition needed for going from unknown to full. However, the
9377c478bd9Sstevel@tonic-gate * state of the pm framework and cpu driver needs to be adjusted.
9387c478bd9Sstevel@tonic-gate */
9397c478bd9Sstevel@tonic-gate if (ppmd->level == PM_LEVEL_UNKNOWN && new == ppmd->highest) {
9407c478bd9Sstevel@tonic-gate *result = ret = xcppm_change_power_level(ppmd, 0, new);
9417c478bd9Sstevel@tonic-gate if (ret != DDI_SUCCESS) {
9427c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("%s: Failed to change "
9437c478bd9Sstevel@tonic-gate "power level to %d\n", str, new));
9447c478bd9Sstevel@tonic-gate }
9457c478bd9Sstevel@tonic-gate return (ret);
9467c478bd9Sstevel@tonic-gate }
9477c478bd9Sstevel@tonic-gate
9487c478bd9Sstevel@tonic-gate if (new == ppmd->level) {
9497c478bd9Sstevel@tonic-gate DPRINTF(D_CPU, ("%s: already at power level %d\n", str, new));
9507c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
9517c478bd9Sstevel@tonic-gate }
9527c478bd9Sstevel@tonic-gate
9537c478bd9Sstevel@tonic-gate ppmd->rplvl = new;
9547c478bd9Sstevel@tonic-gate
9557c478bd9Sstevel@tonic-gate /*
9567c478bd9Sstevel@tonic-gate * A request from lower to higher level transition is granted and
9577c478bd9Sstevel@tonic-gate * made effective on both cpus. For more than two cpu platform model,
9587c478bd9Sstevel@tonic-gate * the following code needs to be modified to remember the rest of
9597c478bd9Sstevel@tonic-gate * the unsoliciting cpus to be rescan'ed.
9607c478bd9Sstevel@tonic-gate * A request from higher to lower must be agreed by all cpus.
9617c478bd9Sstevel@tonic-gate */
9627c478bd9Sstevel@tonic-gate for (ppmd = xcppm_cpu.devlist; ppmd; ppmd = ppmd->next) {
9637c478bd9Sstevel@tonic-gate if (ppmd->rplvl == new)
9647c478bd9Sstevel@tonic-gate continue;
9657c478bd9Sstevel@tonic-gate
9667c478bd9Sstevel@tonic-gate if (new < old) {
9677c478bd9Sstevel@tonic-gate DPRINTF(D_SOME, ("%s: not all cpus want to go down to "
9687c478bd9Sstevel@tonic-gate "level %d yet\n", str, new));
9697c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
9707c478bd9Sstevel@tonic-gate }
9717c478bd9Sstevel@tonic-gate
9727c478bd9Sstevel@tonic-gate /*
9737c478bd9Sstevel@tonic-gate * If a single cpu requests power up, honor the request
9747c478bd9Sstevel@tonic-gate * by powering up both cpus.
9757c478bd9Sstevel@tonic-gate */
9767c478bd9Sstevel@tonic-gate if (new > old) {
9777c478bd9Sstevel@tonic-gate DPRINTF(D_SOME, ("%s: powering up device(%s@%s, %p) "
9787c478bd9Sstevel@tonic-gate "because of request from dip(%s@%s, %p), "
9797c478bd9Sstevel@tonic-gate "need pm_rescan\n", str, PM_NAME(ppmd->dip),
9807c478bd9Sstevel@tonic-gate PM_ADDR(ppmd->dip), (void *)ppmd->dip,
9817c478bd9Sstevel@tonic-gate PM_NAME(dip), PM_ADDR(dip), (void *)dip))
9827c478bd9Sstevel@tonic-gate do_rescan++;
9837c478bd9Sstevel@tonic-gate rescan_dip = ppmd->dip;
9847c478bd9Sstevel@tonic-gate break;
9857c478bd9Sstevel@tonic-gate }
9867c478bd9Sstevel@tonic-gate }
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate ret = xcppm_change_cpu_power(new);
9897c478bd9Sstevel@tonic-gate *result = ret;
9907c478bd9Sstevel@tonic-gate
9917c478bd9Sstevel@tonic-gate if (ret == DDI_SUCCESS) {
9927c478bd9Sstevel@tonic-gate if (reqp->req.ppm_set_power_req.canblock == PM_CANBLOCK_BLOCK)
9937c478bd9Sstevel@tonic-gate kmflag = KM_SLEEP;
9947c478bd9Sstevel@tonic-gate else
9957c478bd9Sstevel@tonic-gate kmflag = KM_NOSLEEP;
9967c478bd9Sstevel@tonic-gate
9977c478bd9Sstevel@tonic-gate for (ppmd = xcppm_cpu.devlist; ppmd; ppmd = ppmd->next) {
9987c478bd9Sstevel@tonic-gate if (ppmd->dip == dip)
9997c478bd9Sstevel@tonic-gate continue;
10007c478bd9Sstevel@tonic-gate
10017c478bd9Sstevel@tonic-gate if ((p = kmem_zalloc(sizeof (pm_ppm_devlist_t),
10027c478bd9Sstevel@tonic-gate kmflag)) == NULL) {
10037c478bd9Sstevel@tonic-gate break;
10047c478bd9Sstevel@tonic-gate }
10057c478bd9Sstevel@tonic-gate p->ppd_who = ppmd->dip;
10067c478bd9Sstevel@tonic-gate p->ppd_cmpt = ppmd->cmpt;
10077c478bd9Sstevel@tonic-gate p->ppd_old_level = old;
10087c478bd9Sstevel@tonic-gate p->ppd_new_level = new;
10097c478bd9Sstevel@tonic-gate p->ppd_next = devlist;
10107c478bd9Sstevel@tonic-gate
10117c478bd9Sstevel@tonic-gate devlist = p;
10127c478bd9Sstevel@tonic-gate }
10137c478bd9Sstevel@tonic-gate reqp->req.ppm_set_power_req.cookie = (void *) devlist;
10147c478bd9Sstevel@tonic-gate
10157c478bd9Sstevel@tonic-gate if (do_rescan > 0)
10167c478bd9Sstevel@tonic-gate pm_rescan(rescan_dip);
10177c478bd9Sstevel@tonic-gate }
10187c478bd9Sstevel@tonic-gate
10197c478bd9Sstevel@tonic-gate return (ret);
10207c478bd9Sstevel@tonic-gate }
10217c478bd9Sstevel@tonic-gate
10227c478bd9Sstevel@tonic-gate
10237c478bd9Sstevel@tonic-gate /*
10247c478bd9Sstevel@tonic-gate * If powering off and all devices in this domain will now be off,
10257c478bd9Sstevel@tonic-gate * shut off common power. If powering up and no devices up yet,
10267c478bd9Sstevel@tonic-gate * turn on common power. Always make the requested power level
10277c478bd9Sstevel@tonic-gate * change for the target device.
10287c478bd9Sstevel@tonic-gate */
10297c478bd9Sstevel@tonic-gate static int
xcppm_manage_fet(dev_info_t * dip,power_req_t * reqp,int * result)10307c478bd9Sstevel@tonic-gate xcppm_manage_fet(dev_info_t *dip, power_req_t *reqp, int *result)
10317c478bd9Sstevel@tonic-gate {
10327c478bd9Sstevel@tonic-gate #ifdef DEBUG
10337c478bd9Sstevel@tonic-gate char *str = "xcppm_manage_fet";
10347c478bd9Sstevel@tonic-gate #endif
10357c478bd9Sstevel@tonic-gate int (*pwr_func)(ppm_dev_t *, int, int);
10367c478bd9Sstevel@tonic-gate int new, old, cmpt, incr = 0;
10377c478bd9Sstevel@tonic-gate ppm_dev_t *ppmd;
10387c478bd9Sstevel@tonic-gate
10397c478bd9Sstevel@tonic-gate ppmd = PPM_GET_PRIVATE(dip);
10407c478bd9Sstevel@tonic-gate DPRINTF(D_FET, ("%s: \"%s\", req %s\n", str,
10417c478bd9Sstevel@tonic-gate ppmd->path, ppm_get_ctlstr(reqp->request_type, ~0)));
10427c478bd9Sstevel@tonic-gate
10437c478bd9Sstevel@tonic-gate *result = DDI_SUCCESS; /* change later for failures */
10447c478bd9Sstevel@tonic-gate switch (reqp->request_type) {
10457c478bd9Sstevel@tonic-gate case PMR_PPM_SET_POWER:
10467c478bd9Sstevel@tonic-gate pwr_func = xcppm_change_power_level;
10477c478bd9Sstevel@tonic-gate old = reqp->req.ppm_set_power_req.old_level;
10487c478bd9Sstevel@tonic-gate new = reqp->req.ppm_set_power_req.new_level;
10497c478bd9Sstevel@tonic-gate cmpt = reqp->req.ppm_set_power_req.cmpt;
10507c478bd9Sstevel@tonic-gate break;
10517c478bd9Sstevel@tonic-gate case PMR_PPM_POWER_CHANGE_NOTIFY:
10527c478bd9Sstevel@tonic-gate pwr_func = xcppm_record_level_change;
10537c478bd9Sstevel@tonic-gate old = reqp->req.ppm_notify_level_req.old_level;
10547c478bd9Sstevel@tonic-gate new = reqp->req.ppm_notify_level_req.new_level;
10557c478bd9Sstevel@tonic-gate cmpt = reqp->req.ppm_notify_level_req.cmpt;
10567c478bd9Sstevel@tonic-gate break;
10577c478bd9Sstevel@tonic-gate default:
10587c478bd9Sstevel@tonic-gate return (*result = DDI_FAILURE);
10597c478bd9Sstevel@tonic-gate
10607c478bd9Sstevel@tonic-gate }
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gate /* This is common code for SET_POWER and POWER_CHANGE_NOTIFY cases */
10637c478bd9Sstevel@tonic-gate DPRINTF(D_FET, ("%s: \"%s\", old %d, new %d\n",
10647c478bd9Sstevel@tonic-gate str, ppmd->path, old, new));
10657c478bd9Sstevel@tonic-gate
10667c478bd9Sstevel@tonic-gate ASSERT(old == ppmd->level);
10677c478bd9Sstevel@tonic-gate if (new == ppmd->level)
10687c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
10697c478bd9Sstevel@tonic-gate
10707c478bd9Sstevel@tonic-gate PPM_LOCK_DOMAIN(ppmd->domp);
10717c478bd9Sstevel@tonic-gate /*
10727c478bd9Sstevel@tonic-gate * Devices in this domain are known to have 0 (off) as their
10737c478bd9Sstevel@tonic-gate * lowest power level. We use this fact to simplify the logic.
10747c478bd9Sstevel@tonic-gate */
10757c478bd9Sstevel@tonic-gate if (new > 0) {
10767c478bd9Sstevel@tonic-gate if (ppmd->domp->pwr_cnt == 0)
10777c478bd9Sstevel@tonic-gate (void) xcppm_gpio_port2(XCPPM_SETBIT, DRVON);
10787c478bd9Sstevel@tonic-gate if (old == 0) {
10797c478bd9Sstevel@tonic-gate ppmd->domp->pwr_cnt++;
10807c478bd9Sstevel@tonic-gate incr = 1;
10817c478bd9Sstevel@tonic-gate DPRINTF(D_FET, ("%s: UP cnt = %d\n",
10827c478bd9Sstevel@tonic-gate str, ppmd->domp->pwr_cnt));
10837c478bd9Sstevel@tonic-gate }
10847c478bd9Sstevel@tonic-gate }
10857c478bd9Sstevel@tonic-gate
10867c478bd9Sstevel@tonic-gate PPM_UNLOCK_DOMAIN(ppmd->domp);
10877c478bd9Sstevel@tonic-gate
10887c478bd9Sstevel@tonic-gate ASSERT(ppmd->domp->pwr_cnt > 0);
10897c478bd9Sstevel@tonic-gate
10907c478bd9Sstevel@tonic-gate if ((*result = (*pwr_func)(ppmd, cmpt, new)) != DDI_SUCCESS) {
10917c478bd9Sstevel@tonic-gate DPRINTF(D_FET, ("%s: \"%s\" power change failed \n",
10927c478bd9Sstevel@tonic-gate str, ppmd->path));
10937c478bd9Sstevel@tonic-gate }
10947c478bd9Sstevel@tonic-gate
10957c478bd9Sstevel@tonic-gate PPM_LOCK_DOMAIN(ppmd->domp);
10967c478bd9Sstevel@tonic-gate
10977c478bd9Sstevel@tonic-gate /*
10987c478bd9Sstevel@tonic-gate * Decr the power count in two cases:
10997c478bd9Sstevel@tonic-gate *
11007c478bd9Sstevel@tonic-gate * 1) request was to power device down and was successful
11017c478bd9Sstevel@tonic-gate * 2) request was to power up (we pre-incremented count), but failed.
11027c478bd9Sstevel@tonic-gate */
11037c478bd9Sstevel@tonic-gate if ((*result == DDI_SUCCESS && ppmd->level == 0) ||
11047c478bd9Sstevel@tonic-gate (*result != DDI_SUCCESS && incr)) {
11057c478bd9Sstevel@tonic-gate ASSERT(ppmd->domp->pwr_cnt > 0);
11067c478bd9Sstevel@tonic-gate ppmd->domp->pwr_cnt--;
11077c478bd9Sstevel@tonic-gate DPRINTF(D_FET, ("%s: DN cnt = %d\n", str, ppmd->domp->pwr_cnt));
11087c478bd9Sstevel@tonic-gate if (ppmd->domp->pwr_cnt == 0)
11097c478bd9Sstevel@tonic-gate (void) xcppm_gpio_port2(XCPPM_CLRBIT, DRVON);
11107c478bd9Sstevel@tonic-gate }
11117c478bd9Sstevel@tonic-gate
11127c478bd9Sstevel@tonic-gate PPM_UNLOCK_DOMAIN(ppmd->domp);
11137c478bd9Sstevel@tonic-gate ASSERT(ppmd->domp->pwr_cnt >= 0);
11147c478bd9Sstevel@tonic-gate return (*result == DDI_SUCCESS ? DDI_SUCCESS : DDI_FAILURE);
11157c478bd9Sstevel@tonic-gate }
11167c478bd9Sstevel@tonic-gate
11177c478bd9Sstevel@tonic-gate
11187c478bd9Sstevel@tonic-gate /*
11197c478bd9Sstevel@tonic-gate * Since UPA64S relies on PCI B staying at nominal 33MHz in order to
11207c478bd9Sstevel@tonic-gate * have its interrupt pulse function properly, we ensure
11217c478bd9Sstevel@tonic-gate * - Lowering PCI B only if UPA64S is at low power, otherwise defer
11227c478bd9Sstevel@tonic-gate * the action until UPA64S goes down; hence right after UPA64S goes
11237c478bd9Sstevel@tonic-gate * down, perform the deferred action for PCI B;
11247c478bd9Sstevel@tonic-gate * - Always raise PCI B power prior to raising UPA64S power.
11257c478bd9Sstevel@tonic-gate *
11267c478bd9Sstevel@tonic-gate * Both UPA64S and PCI B devices are considered each other's dependency
11277c478bd9Sstevel@tonic-gate * device whenever actual power transition is handled (PMR_PPM_SET_POWER).
11287c478bd9Sstevel@tonic-gate */
11297c478bd9Sstevel@tonic-gate static int
xcppm_manage_pciupa(dev_info_t * dip,power_req_t * reqp,int * result)11307c478bd9Sstevel@tonic-gate xcppm_manage_pciupa(dev_info_t *dip, power_req_t *reqp, int *result)
11317c478bd9Sstevel@tonic-gate {
11327c478bd9Sstevel@tonic-gate #ifdef DEBUG
11337c478bd9Sstevel@tonic-gate char *str = "xcppm_manage_pciupa";
11347c478bd9Sstevel@tonic-gate #endif
11357c478bd9Sstevel@tonic-gate int (*pwr_func)(ppm_dev_t *, int, int);
11367c478bd9Sstevel@tonic-gate uint_t flags = 0, co_flags = 0;
11377c478bd9Sstevel@tonic-gate ppm_dev_t *ppmd, *codev;
11387c478bd9Sstevel@tonic-gate int new, cmpt, retval;
11397c478bd9Sstevel@tonic-gate
11407c478bd9Sstevel@tonic-gate ppmd = PPM_GET_PRIVATE(dip);
11417c478bd9Sstevel@tonic-gate DPRINTF(D_PCIUPA, ("%s: \"%s\", req %s\n", str,
11427c478bd9Sstevel@tonic-gate ppmd->path, ppm_get_ctlstr(reqp->request_type, ~0)));
11437c478bd9Sstevel@tonic-gate
11447c478bd9Sstevel@tonic-gate *result = DDI_SUCCESS;
11457c478bd9Sstevel@tonic-gate
11467c478bd9Sstevel@tonic-gate switch (reqp->request_type) {
11477c478bd9Sstevel@tonic-gate case PMR_PPM_SET_POWER:
11487c478bd9Sstevel@tonic-gate pwr_func = xcppm_change_power_level;
11497c478bd9Sstevel@tonic-gate new = reqp->req.ppm_set_power_req.new_level;
11507c478bd9Sstevel@tonic-gate cmpt = reqp->req.ppm_set_power_req.cmpt;
11517c478bd9Sstevel@tonic-gate break;
11527c478bd9Sstevel@tonic-gate case PMR_PPM_POWER_CHANGE_NOTIFY:
11537c478bd9Sstevel@tonic-gate pwr_func = xcppm_record_level_change;
11547c478bd9Sstevel@tonic-gate new = reqp->req.ppm_notify_level_req.new_level;
11557c478bd9Sstevel@tonic-gate cmpt = reqp->req.ppm_notify_level_req.cmpt;
11567c478bd9Sstevel@tonic-gate break;
11577c478bd9Sstevel@tonic-gate default:
11587c478bd9Sstevel@tonic-gate *result = DDI_FAILURE;
11597c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
11607c478bd9Sstevel@tonic-gate }
11617c478bd9Sstevel@tonic-gate
11627c478bd9Sstevel@tonic-gate /* Common code for SET_POWER and POWER_CHANGE_NOTIFY cases */
11637c478bd9Sstevel@tonic-gate ASSERT(ppmd); /* since it should be locked already */
11647c478bd9Sstevel@tonic-gate
11657c478bd9Sstevel@tonic-gate if (new == ppmd->level)
11667c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
11677c478bd9Sstevel@tonic-gate
11687c478bd9Sstevel@tonic-gate DPRINTF(D_PCIUPA, ("%s: \"%s\", levels: current %d, new %d\n",
11697c478bd9Sstevel@tonic-gate str, ppmd->path, ppmd->level, new));
11707c478bd9Sstevel@tonic-gate
11717c478bd9Sstevel@tonic-gate /*
11727c478bd9Sstevel@tonic-gate * find power-wise co-related device
11737c478bd9Sstevel@tonic-gate */
11747c478bd9Sstevel@tonic-gate flags = ppmd->flags;
11757c478bd9Sstevel@tonic-gate
11767c478bd9Sstevel@tonic-gate #ifdef DEBUG
11777c478bd9Sstevel@tonic-gate if (flags & ~(XCPPMF_PCIB|XCPPMF_UPA))
1178360e6f5eSmathue DPRINTF(D_ERROR, ("%s: invalid ppmd->flags value 0x%x\n", str,
11797c478bd9Sstevel@tonic-gate ppmd->flags));
11807c478bd9Sstevel@tonic-gate #endif
11817c478bd9Sstevel@tonic-gate
11827c478bd9Sstevel@tonic-gate if (flags == XCPPMF_UPA)
11837c478bd9Sstevel@tonic-gate co_flags = XCPPMF_PCIB;
11847c478bd9Sstevel@tonic-gate else if (flags == XCPPMF_PCIB)
11857c478bd9Sstevel@tonic-gate co_flags = XCPPMF_UPA;
11867c478bd9Sstevel@tonic-gate
11877c478bd9Sstevel@tonic-gate for (codev = ppmd->domp->devlist; codev; codev = codev->next)
11887c478bd9Sstevel@tonic-gate if ((codev->cmpt == 0) && (codev->flags == co_flags))
11897c478bd9Sstevel@tonic-gate break;
11907c478bd9Sstevel@tonic-gate
11917c478bd9Sstevel@tonic-gate if (new > ppmd->level) {
11927c478bd9Sstevel@tonic-gate /*
11937c478bd9Sstevel@tonic-gate * Raise power level -
11947c478bd9Sstevel@tonic-gate * pre-raising: upa ensure pci is powered up.
11957c478bd9Sstevel@tonic-gate */
11967c478bd9Sstevel@tonic-gate if ((flags == XCPPMF_UPA) && codev &&
11977c478bd9Sstevel@tonic-gate (codev->level != codev->highest)) {
11987c478bd9Sstevel@tonic-gate if ((retval = xcppm_change_power_level(codev,
11997c478bd9Sstevel@tonic-gate 0, codev->highest)) != DDI_SUCCESS &&
12007c478bd9Sstevel@tonic-gate codev->level != codev->highest) {
12017c478bd9Sstevel@tonic-gate *result = retval;
12027c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
12037c478bd9Sstevel@tonic-gate }
12047c478bd9Sstevel@tonic-gate }
12057c478bd9Sstevel@tonic-gate if ((retval = (*pwr_func)(ppmd, 0, new)) != DDI_SUCCESS) {
12067c478bd9Sstevel@tonic-gate *result = retval;
12077c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
12087c478bd9Sstevel@tonic-gate }
12097c478bd9Sstevel@tonic-gate } else if (new < ppmd->level) {
12107c478bd9Sstevel@tonic-gate /*
12117c478bd9Sstevel@tonic-gate * Lower power level
12127c478bd9Sstevel@tonic-gate *
12137c478bd9Sstevel@tonic-gate * once upa is attached, pci checks upa level:
12147c478bd9Sstevel@tonic-gate * if upa is at high level, defer the request and return.
12157c478bd9Sstevel@tonic-gate * otherwise, set power level then check and lower pci level.
12167c478bd9Sstevel@tonic-gate */
12177c478bd9Sstevel@tonic-gate if ((flags == XCPPMF_PCIB) && codev &&
12187c478bd9Sstevel@tonic-gate (codev->level != codev->lowest)) {
12197c478bd9Sstevel@tonic-gate ppmd->rplvl = new;
12207c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
12217c478bd9Sstevel@tonic-gate }
12227c478bd9Sstevel@tonic-gate if ((retval = (*pwr_func)(ppmd, cmpt, new)) != DDI_SUCCESS &&
12237c478bd9Sstevel@tonic-gate ppmd->level != new) {
12247c478bd9Sstevel@tonic-gate *result = retval;
12257c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
12267c478bd9Sstevel@tonic-gate }
12277c478bd9Sstevel@tonic-gate
12287c478bd9Sstevel@tonic-gate if (flags == XCPPMF_UPA) {
12297c478bd9Sstevel@tonic-gate if (codev && (codev->rplvl != PM_LEVEL_UNKNOWN) &&
12307c478bd9Sstevel@tonic-gate (codev->rplvl < codev->level)) {
12317c478bd9Sstevel@tonic-gate DPRINTF(D_PCIUPA, ("%s: codev \"%s\" "
12327c478bd9Sstevel@tonic-gate "rplvl %d level %d\n", str, codev->path,
12337c478bd9Sstevel@tonic-gate codev->rplvl, codev->level));
12347c478bd9Sstevel@tonic-gate if ((retval = xcppm_change_power_level(
12357c478bd9Sstevel@tonic-gate codev, 0, codev->rplvl)) != DDI_SUCCESS) {
12367c478bd9Sstevel@tonic-gate *result = retval;
12377c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
12387c478bd9Sstevel@tonic-gate }
12397c478bd9Sstevel@tonic-gate }
12407c478bd9Sstevel@tonic-gate }
12417c478bd9Sstevel@tonic-gate }
12427c478bd9Sstevel@tonic-gate
12437c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
12447c478bd9Sstevel@tonic-gate }
12457c478bd9Sstevel@tonic-gate
12467c478bd9Sstevel@tonic-gate
12477c478bd9Sstevel@tonic-gate /*
12487c478bd9Sstevel@tonic-gate * When all of the children of the 1394 nexus are idle, a call will be
12497c478bd9Sstevel@tonic-gate * made to the nexus driver's own power entry point to lower power. Ppm
12507c478bd9Sstevel@tonic-gate * intercepts this and kills 1394 cable power (since the driver doesn't
12517c478bd9Sstevel@tonic-gate * have access to the required register). Similar logic applies when
12527c478bd9Sstevel@tonic-gate * coming up from the state where all the children were off.
12537c478bd9Sstevel@tonic-gate */
12547c478bd9Sstevel@tonic-gate static int
xcppm_manage_1394(dev_info_t * dip,power_req_t * reqp,int * result)12557c478bd9Sstevel@tonic-gate xcppm_manage_1394(dev_info_t *dip, power_req_t *reqp, int *result)
12567c478bd9Sstevel@tonic-gate {
12577c478bd9Sstevel@tonic-gate #ifdef DEBUG
12587c478bd9Sstevel@tonic-gate char *str = "xcppm_manage_1394";
12597c478bd9Sstevel@tonic-gate #endif
12607c478bd9Sstevel@tonic-gate int (*pwr_func)(ppm_dev_t *, int, int);
12617c478bd9Sstevel@tonic-gate int new, old, cmpt;
12627c478bd9Sstevel@tonic-gate ppm_dev_t *ppmd;
12637c478bd9Sstevel@tonic-gate
12647c478bd9Sstevel@tonic-gate ppmd = PPM_GET_PRIVATE(dip);
12657c478bd9Sstevel@tonic-gate DPRINTF(D_1394, ("%s: \"%s\", req %s\n", str,
12667c478bd9Sstevel@tonic-gate ppmd->path, ppm_get_ctlstr(reqp->request_type, ~0)));
12677c478bd9Sstevel@tonic-gate
12687c478bd9Sstevel@tonic-gate switch (reqp->request_type) {
12697c478bd9Sstevel@tonic-gate case PMR_PPM_SET_POWER:
12707c478bd9Sstevel@tonic-gate pwr_func = xcppm_change_power_level;
12717c478bd9Sstevel@tonic-gate old = reqp->req.ppm_set_power_req.old_level;
12727c478bd9Sstevel@tonic-gate new = reqp->req.ppm_set_power_req.new_level;
12737c478bd9Sstevel@tonic-gate cmpt = reqp->req.ppm_set_power_req.cmpt;
12747c478bd9Sstevel@tonic-gate break;
12757c478bd9Sstevel@tonic-gate case PMR_PPM_POWER_CHANGE_NOTIFY:
12767c478bd9Sstevel@tonic-gate pwr_func = xcppm_record_level_change;
12777c478bd9Sstevel@tonic-gate old = reqp->req.ppm_notify_level_req.old_level;
12787c478bd9Sstevel@tonic-gate new = reqp->req.ppm_notify_level_req.new_level;
12797c478bd9Sstevel@tonic-gate cmpt = reqp->req.ppm_notify_level_req.cmpt;
12807c478bd9Sstevel@tonic-gate break;
12817c478bd9Sstevel@tonic-gate default:
12827c478bd9Sstevel@tonic-gate return (*result = DDI_FAILURE);
12837c478bd9Sstevel@tonic-gate }
12847c478bd9Sstevel@tonic-gate
12857c478bd9Sstevel@tonic-gate
12867c478bd9Sstevel@tonic-gate /* Common code for SET_POWER and POWER_CHANGE_NOTIFY cases */
12877c478bd9Sstevel@tonic-gate DPRINTF(D_1394, ("%s: dev %s@%s, old %d new %d\n", str,
12887c478bd9Sstevel@tonic-gate ddi_binding_name(dip), ddi_get_name_addr(dip), old, new));
12897c478bd9Sstevel@tonic-gate
12907c478bd9Sstevel@tonic-gate ASSERT(ppmd); /* since it must already be locked */
12917c478bd9Sstevel@tonic-gate ASSERT(old == ppmd->level);
12927c478bd9Sstevel@tonic-gate
12937c478bd9Sstevel@tonic-gate if (new == ppmd->level)
12947c478bd9Sstevel@tonic-gate return (*result = DDI_SUCCESS);
12957c478bd9Sstevel@tonic-gate
12967c478bd9Sstevel@tonic-gate /* the reduce power case */
12977c478bd9Sstevel@tonic-gate if (cmpt == 0 && new < ppmd->level) {
12987c478bd9Sstevel@tonic-gate if ((*result =
12997c478bd9Sstevel@tonic-gate (*pwr_func)(ppmd, cmpt, new)) != DDI_SUCCESS) {
13007c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
13017c478bd9Sstevel@tonic-gate }
13027c478bd9Sstevel@tonic-gate if (new == ppmd->lowest)
13037c478bd9Sstevel@tonic-gate (void) xcppm_gpio_port2(XCPPM_CLRBIT, CPEN);
13047c478bd9Sstevel@tonic-gate ppmd->level = new;
13057c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
13067c478bd9Sstevel@tonic-gate }
13077c478bd9Sstevel@tonic-gate
13087c478bd9Sstevel@tonic-gate /* the increase power case */
13097c478bd9Sstevel@tonic-gate if (cmpt == 0 && new > ppmd->level) {
13107c478bd9Sstevel@tonic-gate if (ppmd->level == ppmd->lowest) {
13117c478bd9Sstevel@tonic-gate (void) xcppm_gpio_port2(XCPPM_SETBIT, CPEN);
13127c478bd9Sstevel@tonic-gate delay(1);
13137c478bd9Sstevel@tonic-gate }
13147c478bd9Sstevel@tonic-gate /*
13157c478bd9Sstevel@tonic-gate * Even if pwr_func fails we need to check current level again
13167c478bd9Sstevel@tonic-gate * because it could have been changed by an intervening
13177c478bd9Sstevel@tonic-gate * POWER_CHANGE_NOTIFY operation.
13187c478bd9Sstevel@tonic-gate */
13197c478bd9Sstevel@tonic-gate if ((*result =
13207c478bd9Sstevel@tonic-gate (*pwr_func)(ppmd, cmpt, new)) != DDI_SUCCESS &&
13217c478bd9Sstevel@tonic-gate ppmd->level == ppmd->lowest) {
13227c478bd9Sstevel@tonic-gate (void) xcppm_gpio_port2(XCPPM_CLRBIT, CPEN);
13237c478bd9Sstevel@tonic-gate } else {
13247c478bd9Sstevel@tonic-gate ppmd->level = new;
13257c478bd9Sstevel@tonic-gate }
13267c478bd9Sstevel@tonic-gate
13277c478bd9Sstevel@tonic-gate return (*result == DDI_SUCCESS ? DDI_SUCCESS : DDI_FAILURE);
13287c478bd9Sstevel@tonic-gate }
13297c478bd9Sstevel@tonic-gate
13307c478bd9Sstevel@tonic-gate /*
13317c478bd9Sstevel@tonic-gate * We get here if component was non-zero. This is not what we
13327c478bd9Sstevel@tonic-gate * expect. Let the device deal with it and just pass back the
13337c478bd9Sstevel@tonic-gate * result.
13347c478bd9Sstevel@tonic-gate */
13357c478bd9Sstevel@tonic-gate *result = xcppm_change_power_level(ppmd, cmpt, new);
13367c478bd9Sstevel@tonic-gate return (*result == DDI_SUCCESS ? DDI_SUCCESS : DDI_FAILURE);
13377c478bd9Sstevel@tonic-gate }
13387c478bd9Sstevel@tonic-gate
13397c478bd9Sstevel@tonic-gate
13407c478bd9Sstevel@tonic-gate /*
13417c478bd9Sstevel@tonic-gate * lock, unlock, or trylock for one power mutex
13427c478bd9Sstevel@tonic-gate */
13437c478bd9Sstevel@tonic-gate static void
xcppm_lock_one(ppm_dev_t * ppmd,power_req_t * reqp,int * iresp)13447c478bd9Sstevel@tonic-gate xcppm_lock_one(ppm_dev_t *ppmd, power_req_t *reqp, int *iresp)
13457c478bd9Sstevel@tonic-gate {
13467c478bd9Sstevel@tonic-gate switch (reqp->request_type) {
13477c478bd9Sstevel@tonic-gate case PMR_PPM_LOCK_POWER:
13487c478bd9Sstevel@tonic-gate pm_lock_power_single(ppmd->dip,
13497c478bd9Sstevel@tonic-gate reqp->req.ppm_lock_power_req.circp);
13507c478bd9Sstevel@tonic-gate break;
13517c478bd9Sstevel@tonic-gate
13527c478bd9Sstevel@tonic-gate case PMR_PPM_UNLOCK_POWER:
13537c478bd9Sstevel@tonic-gate pm_unlock_power_single(ppmd->dip,
13547c478bd9Sstevel@tonic-gate reqp->req.ppm_unlock_power_req.circ);
13557c478bd9Sstevel@tonic-gate break;
13567c478bd9Sstevel@tonic-gate
13577c478bd9Sstevel@tonic-gate case PMR_PPM_TRY_LOCK_POWER:
13587c478bd9Sstevel@tonic-gate *iresp = pm_try_locking_power_single(ppmd->dip,
13597c478bd9Sstevel@tonic-gate reqp->req.ppm_lock_power_req.circp);
13607c478bd9Sstevel@tonic-gate break;
13617c478bd9Sstevel@tonic-gate }
13627c478bd9Sstevel@tonic-gate }
13637c478bd9Sstevel@tonic-gate
13647c478bd9Sstevel@tonic-gate
13657c478bd9Sstevel@tonic-gate /*
13667c478bd9Sstevel@tonic-gate * lock, unlock, or trylock all devices within a domain.
13677c478bd9Sstevel@tonic-gate */
13687c478bd9Sstevel@tonic-gate static void
xcppm_lock_all(ppm_domain_t * domp,power_req_t * reqp,int * iresp)13697c478bd9Sstevel@tonic-gate xcppm_lock_all(ppm_domain_t *domp, power_req_t *reqp, int *iresp)
13707c478bd9Sstevel@tonic-gate {
13717c478bd9Sstevel@tonic-gate /*
13727c478bd9Sstevel@tonic-gate * To simplify the implementation we let all the devices
13737c478bd9Sstevel@tonic-gate * in the domain be represented by a single device (dip).
13747c478bd9Sstevel@tonic-gate * We use the first device in the domain's devlist. This
13757c478bd9Sstevel@tonic-gate * is safe because we return with the domain lock held
13767c478bd9Sstevel@tonic-gate * which prevents the list from changing.
13777c478bd9Sstevel@tonic-gate */
13787c478bd9Sstevel@tonic-gate if (reqp->request_type == PMR_PPM_LOCK_POWER) {
13797c478bd9Sstevel@tonic-gate if (!MUTEX_HELD(&domp->lock))
13807c478bd9Sstevel@tonic-gate mutex_enter(&domp->lock);
13817c478bd9Sstevel@tonic-gate domp->refcnt++;
13827c478bd9Sstevel@tonic-gate ASSERT(domp->devlist != NULL);
13837c478bd9Sstevel@tonic-gate pm_lock_power_single(domp->devlist->dip,
13847c478bd9Sstevel@tonic-gate reqp->req.ppm_lock_power_req.circp);
13857c478bd9Sstevel@tonic-gate /* domain lock remains held */
13867c478bd9Sstevel@tonic-gate return;
13877c478bd9Sstevel@tonic-gate } else if (reqp->request_type == PMR_PPM_UNLOCK_POWER) {
13887c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&domp->lock));
13897c478bd9Sstevel@tonic-gate ASSERT(domp->devlist != NULL);
13907c478bd9Sstevel@tonic-gate pm_unlock_power_single(domp->devlist->dip,
13917c478bd9Sstevel@tonic-gate reqp->req.ppm_unlock_power_req.circ);
13927c478bd9Sstevel@tonic-gate if (--domp->refcnt == 0)
13937c478bd9Sstevel@tonic-gate mutex_exit(&domp->lock);
13947c478bd9Sstevel@tonic-gate return;
13957c478bd9Sstevel@tonic-gate }
13967c478bd9Sstevel@tonic-gate
13977c478bd9Sstevel@tonic-gate ASSERT(reqp->request_type == PMR_PPM_TRY_LOCK_POWER);
13987c478bd9Sstevel@tonic-gate if (!MUTEX_HELD(&domp->lock))
13997c478bd9Sstevel@tonic-gate if (!mutex_tryenter(&domp->lock)) {
14007c478bd9Sstevel@tonic-gate *iresp = 0;
14017c478bd9Sstevel@tonic-gate return;
14027c478bd9Sstevel@tonic-gate }
14037c478bd9Sstevel@tonic-gate *iresp = pm_try_locking_power_single(domp->devlist->dip,
14047c478bd9Sstevel@tonic-gate reqp->req.ppm_lock_power_req.circp);
14057c478bd9Sstevel@tonic-gate if (*iresp)
14067c478bd9Sstevel@tonic-gate domp->refcnt++;
14077c478bd9Sstevel@tonic-gate else
14087c478bd9Sstevel@tonic-gate mutex_exit(&domp->lock);
14097c478bd9Sstevel@tonic-gate }
14107c478bd9Sstevel@tonic-gate
14117c478bd9Sstevel@tonic-gate
14127c478bd9Sstevel@tonic-gate /*
14137c478bd9Sstevel@tonic-gate * The pm framework calls us here to manage power for a device.
14147c478bd9Sstevel@tonic-gate * We maintain state which tells us whether we need to turn off/on
14157c478bd9Sstevel@tonic-gate * system board power components based on the status of all the devices
14167c478bd9Sstevel@tonic-gate * sharing a component.
14177c478bd9Sstevel@tonic-gate *
14187c478bd9Sstevel@tonic-gate */
14197c478bd9Sstevel@tonic-gate /* ARGSUSED */
14207c478bd9Sstevel@tonic-gate static int
xcppm_ctlops(dev_info_t * dip,dev_info_t * rdip,ddi_ctl_enum_t ctlop,void * arg,void * result)14217c478bd9Sstevel@tonic-gate xcppm_ctlops(dev_info_t *dip, dev_info_t *rdip,
14227c478bd9Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result)
14237c478bd9Sstevel@tonic-gate {
14247c478bd9Sstevel@tonic-gate power_req_t *reqp = arg;
14257c478bd9Sstevel@tonic-gate xcppm_unit_t *unitp;
14267c478bd9Sstevel@tonic-gate ppm_domain_t *domp;
14277c478bd9Sstevel@tonic-gate ppm_dev_t *ppmd;
14287c478bd9Sstevel@tonic-gate
14297c478bd9Sstevel@tonic-gate #ifdef DEBUG
14307c478bd9Sstevel@tonic-gate char path[MAXPATHLEN], *ctlstr, *str = "xcppm_ctlops";
14317c478bd9Sstevel@tonic-gate uint_t mask = ppm_debug & (D_CTLOPS1 | D_CTLOPS2);
14327c478bd9Sstevel@tonic-gate if (mask && (ctlstr = ppm_get_ctlstr(reqp->request_type, mask))) {
14337c478bd9Sstevel@tonic-gate prom_printf("%s: \"%s\", %s\n", str,
14347c478bd9Sstevel@tonic-gate ddi_pathname(rdip, path), ctlstr);
14357c478bd9Sstevel@tonic-gate }
14367c478bd9Sstevel@tonic-gate #endif
14377c478bd9Sstevel@tonic-gate
14387c478bd9Sstevel@tonic-gate if (ctlop != DDI_CTLOPS_POWER)
14397c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
14407c478bd9Sstevel@tonic-gate
14417c478bd9Sstevel@tonic-gate switch (reqp->request_type) {
14427c478bd9Sstevel@tonic-gate case PMR_PPM_UNMANAGE:
14437c478bd9Sstevel@tonic-gate case PMR_PPM_PRE_PROBE:
14447c478bd9Sstevel@tonic-gate case PMR_PPM_POST_PROBE:
14457c478bd9Sstevel@tonic-gate case PMR_PPM_PRE_ATTACH:
14467c478bd9Sstevel@tonic-gate case PMR_PPM_PRE_DETACH:
14477c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
14487c478bd9Sstevel@tonic-gate
14497c478bd9Sstevel@tonic-gate /*
14507c478bd9Sstevel@tonic-gate * There is no hardware configuration required to be done on this
14517c478bd9Sstevel@tonic-gate * platform prior to installing drivers.
14527c478bd9Sstevel@tonic-gate */
14537c478bd9Sstevel@tonic-gate case PMR_PPM_INIT_CHILD:
14547c478bd9Sstevel@tonic-gate case PMR_PPM_UNINIT_CHILD:
14557c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
14567c478bd9Sstevel@tonic-gate
14577c478bd9Sstevel@tonic-gate case PMR_PPM_ALL_LOWEST:
14587c478bd9Sstevel@tonic-gate DPRINTF(D_LOWEST, ("%s: all devices at lowest power = %d\n",
14597c478bd9Sstevel@tonic-gate str, reqp->req.ppm_all_lowest_req.mode));
14607c478bd9Sstevel@tonic-gate if (reqp->req.ppm_all_lowest_req.mode == PM_ALL_LOWEST) {
14617c478bd9Sstevel@tonic-gate unitp = ddi_get_soft_state(ppm_statep, ppm_inst);
14627c478bd9Sstevel@tonic-gate mutex_enter(&unitp->unit_lock);
14637c478bd9Sstevel@tonic-gate if (unitp->state & XCPPM_ST_SUSPENDED) {
14647c478bd9Sstevel@tonic-gate mutex_exit(&unitp->unit_lock);
14657c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
14667c478bd9Sstevel@tonic-gate }
14677c478bd9Sstevel@tonic-gate
14687c478bd9Sstevel@tonic-gate xcppm_set_led(PPM_LEDON);
14697c478bd9Sstevel@tonic-gate unitp->led_tid = timeout(xcppm_blink_led,
14707c478bd9Sstevel@tonic-gate (void *)PPM_LEDON, PPM_LEDON_INTERVAL);
14717c478bd9Sstevel@tonic-gate mutex_exit(&unitp->unit_lock);
14727c478bd9Sstevel@tonic-gate DPRINTF(D_LOWEST, ("%s: LED blink started\n", str));
14737c478bd9Sstevel@tonic-gate } else {
14747c478bd9Sstevel@tonic-gate xcppm_freeze_led((void *)PPM_LEDON);
14757c478bd9Sstevel@tonic-gate DPRINTF(D_LOWEST, ("%s: LED freeze ON\n", str));
14767c478bd9Sstevel@tonic-gate }
14777c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
14787c478bd9Sstevel@tonic-gate
14797c478bd9Sstevel@tonic-gate case PMR_PPM_POST_ATTACH:
14807c478bd9Sstevel@tonic-gate /*
14817c478bd9Sstevel@tonic-gate * After a successful attach, if we haven't already created
14827c478bd9Sstevel@tonic-gate * our private data structure for this device, ppm_get_dev()
14837c478bd9Sstevel@tonic-gate * will force it to be created.
14847c478bd9Sstevel@tonic-gate */
14857c478bd9Sstevel@tonic-gate ppmd = PPM_GET_PRIVATE(rdip);
14867c478bd9Sstevel@tonic-gate if (reqp->req.ppm_config_req.result != DDI_SUCCESS) {
14877c478bd9Sstevel@tonic-gate if (ppmd)
14887c478bd9Sstevel@tonic-gate ppm_rem_dev(rdip);
14897c478bd9Sstevel@tonic-gate } else if (!ppmd) {
14907c478bd9Sstevel@tonic-gate domp = ppm_lookup_dev(rdip);
14917c478bd9Sstevel@tonic-gate ASSERT(domp);
14927c478bd9Sstevel@tonic-gate (void) ppm_get_dev(rdip, domp);
14937c478bd9Sstevel@tonic-gate }
14947c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
14957c478bd9Sstevel@tonic-gate
14967c478bd9Sstevel@tonic-gate case PMR_PPM_POST_DETACH:
14977c478bd9Sstevel@tonic-gate xcppm_detach_ctlop(rdip, reqp);
14987c478bd9Sstevel@tonic-gate *(int *)result = DDI_SUCCESS;
14997c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
15007c478bd9Sstevel@tonic-gate
15017c478bd9Sstevel@tonic-gate case PMR_PPM_PRE_RESUME:
15027c478bd9Sstevel@tonic-gate xcppm_resume_ctlop(rdip, reqp);
15037c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
15047c478bd9Sstevel@tonic-gate
15057c478bd9Sstevel@tonic-gate case PMR_PPM_UNLOCK_POWER:
15067c478bd9Sstevel@tonic-gate case PMR_PPM_TRY_LOCK_POWER:
15077c478bd9Sstevel@tonic-gate case PMR_PPM_LOCK_POWER:
15087c478bd9Sstevel@tonic-gate ppmd = PPM_GET_PRIVATE(rdip);
15097c478bd9Sstevel@tonic-gate if (ppmd)
15107c478bd9Sstevel@tonic-gate domp = ppmd->domp;
15117c478bd9Sstevel@tonic-gate else if (reqp->request_type != PMR_PPM_UNLOCK_POWER) {
15127c478bd9Sstevel@tonic-gate domp = ppm_lookup_dev(rdip);
15137c478bd9Sstevel@tonic-gate ASSERT(domp);
15147c478bd9Sstevel@tonic-gate ppmd = ppm_get_dev(rdip, domp);
15157c478bd9Sstevel@tonic-gate }
15167c478bd9Sstevel@tonic-gate
15177c478bd9Sstevel@tonic-gate ASSERT(domp->dflags == PPMD_LOCK_ALL ||
15187c478bd9Sstevel@tonic-gate domp->dflags == PPMD_LOCK_ONE);
15197c478bd9Sstevel@tonic-gate DPRINTF(D_LOCKS, ("xcppm_lock_%s: \"%s\", %s\n",
15207c478bd9Sstevel@tonic-gate (domp->dflags == PPMD_LOCK_ALL) ? "all" : "one",
15217c478bd9Sstevel@tonic-gate ppmd->path, ppm_get_ctlstr(reqp->request_type, D_LOCKS)));
15227c478bd9Sstevel@tonic-gate
15237c478bd9Sstevel@tonic-gate if (domp->dflags == PPMD_LOCK_ALL)
15247c478bd9Sstevel@tonic-gate xcppm_lock_all(domp, reqp, result);
15257c478bd9Sstevel@tonic-gate else
15267c478bd9Sstevel@tonic-gate xcppm_lock_one(ppmd, reqp, result);
15277c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
15287c478bd9Sstevel@tonic-gate
15297c478bd9Sstevel@tonic-gate case PMR_PPM_POWER_LOCK_OWNER:
15307c478bd9Sstevel@tonic-gate ASSERT(reqp->req.ppm_power_lock_owner_req.who == rdip);
15317c478bd9Sstevel@tonic-gate ppmd = PPM_GET_PRIVATE(rdip);
15327c478bd9Sstevel@tonic-gate if (ppmd)
15337c478bd9Sstevel@tonic-gate domp = ppmd->domp;
15347c478bd9Sstevel@tonic-gate else {
15357c478bd9Sstevel@tonic-gate domp = ppm_lookup_dev(rdip);
15367c478bd9Sstevel@tonic-gate ASSERT(domp);
15377c478bd9Sstevel@tonic-gate ppmd = ppm_get_dev(rdip, domp);
15387c478bd9Sstevel@tonic-gate }
15397c478bd9Sstevel@tonic-gate
15407c478bd9Sstevel@tonic-gate /*
15417c478bd9Sstevel@tonic-gate * In case of LOCK_ALL, effective owner of the power lock
15427c478bd9Sstevel@tonic-gate * is the owner of the domain lock. otherwise, it is the owner
15437c478bd9Sstevel@tonic-gate * of the power lock.
15447c478bd9Sstevel@tonic-gate */
15457c478bd9Sstevel@tonic-gate if (domp->dflags & PPMD_LOCK_ALL)
15467c478bd9Sstevel@tonic-gate reqp->req.ppm_power_lock_owner_req.owner =
15477c478bd9Sstevel@tonic-gate mutex_owner(&domp->lock);
15487c478bd9Sstevel@tonic-gate else {
15497c478bd9Sstevel@tonic-gate reqp->req.ppm_power_lock_owner_req.owner =
15507c478bd9Sstevel@tonic-gate DEVI(rdip)->devi_busy_thread;
15517c478bd9Sstevel@tonic-gate }
15527c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
15537c478bd9Sstevel@tonic-gate
15547c478bd9Sstevel@tonic-gate default:
15557c478bd9Sstevel@tonic-gate ppmd = PPM_GET_PRIVATE(rdip);
15567c478bd9Sstevel@tonic-gate if (ppmd == NULL) {
15577c478bd9Sstevel@tonic-gate domp = ppm_lookup_dev(rdip);
15587c478bd9Sstevel@tonic-gate ASSERT(domp);
15597c478bd9Sstevel@tonic-gate ppmd = ppm_get_dev(rdip, domp);
15607c478bd9Sstevel@tonic-gate }
15617c478bd9Sstevel@tonic-gate
15627c478bd9Sstevel@tonic-gate #ifdef DEBUG
15637c478bd9Sstevel@tonic-gate if ((reqp->request_type == PMR_PPM_SET_POWER) &&
15647c478bd9Sstevel@tonic-gate (ppm_debug & D_SETPWR)) {
15657c478bd9Sstevel@tonic-gate prom_printf("%s: \"%s\", PMR_PPM_SET_POWER\n",
15667c478bd9Sstevel@tonic-gate str, ppmd->path);
15677c478bd9Sstevel@tonic-gate }
15687c478bd9Sstevel@tonic-gate #endif
15697c478bd9Sstevel@tonic-gate
15707c478bd9Sstevel@tonic-gate if (ppmd->domp == &xcppm_cpu)
15717c478bd9Sstevel@tonic-gate return (xcppm_manage_cpus(rdip, reqp, result));
15727c478bd9Sstevel@tonic-gate else if (ppmd->domp == &xcppm_fet)
15737c478bd9Sstevel@tonic-gate return (xcppm_manage_fet(rdip, reqp, result));
15747c478bd9Sstevel@tonic-gate else if (ppmd->domp == &xcppm_upa)
15757c478bd9Sstevel@tonic-gate return (xcppm_manage_pciupa(rdip, reqp, result));
15767c478bd9Sstevel@tonic-gate else {
15777c478bd9Sstevel@tonic-gate ASSERT(ppmd->domp == &xcppm_1394);
15787c478bd9Sstevel@tonic-gate return (xcppm_manage_1394(rdip, reqp, result));
15797c478bd9Sstevel@tonic-gate }
15807c478bd9Sstevel@tonic-gate }
15817c478bd9Sstevel@tonic-gate }
15827c478bd9Sstevel@tonic-gate
15837c478bd9Sstevel@tonic-gate
15847c478bd9Sstevel@tonic-gate /*
15857c478bd9Sstevel@tonic-gate * Initialize our private version of real power level
15867c478bd9Sstevel@tonic-gate * as well as lowest and highest levels the device supports;
15877c478bd9Sstevel@tonic-gate * see ppmf and ppm_add_dev
15887c478bd9Sstevel@tonic-gate */
15897c478bd9Sstevel@tonic-gate static void
xcppm_dev_init(ppm_dev_t * ppmd)15907c478bd9Sstevel@tonic-gate xcppm_dev_init(ppm_dev_t *ppmd)
15917c478bd9Sstevel@tonic-gate {
15927c478bd9Sstevel@tonic-gate struct pm_component *dcomps;
15937c478bd9Sstevel@tonic-gate struct pm_comp *pm_comp;
15947c478bd9Sstevel@tonic-gate dev_info_t *dip;
15957c478bd9Sstevel@tonic-gate int maxi;
15967c478bd9Sstevel@tonic-gate
15977c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ppmd->domp->lock));
15987c478bd9Sstevel@tonic-gate ppmd->level = PM_LEVEL_UNKNOWN;
15997c478bd9Sstevel@tonic-gate ppmd->rplvl = PM_LEVEL_UNKNOWN;
16007c478bd9Sstevel@tonic-gate
16017c478bd9Sstevel@tonic-gate dip = ppmd->dip;
16027c478bd9Sstevel@tonic-gate /*
16037c478bd9Sstevel@tonic-gate * ppm exists to handle power-manageable devices which require
16047c478bd9Sstevel@tonic-gate * special handling on the current platform. However, a
16057c478bd9Sstevel@tonic-gate * driver for such a device may choose not to support power
16067c478bd9Sstevel@tonic-gate * management on a particular load/attach. In this case we
16077c478bd9Sstevel@tonic-gate * we create a structure to represent a single-component device
16087c478bd9Sstevel@tonic-gate * for which "level" = PM_LEVEL_UNKNOWN and "lowest" = 0
16097c478bd9Sstevel@tonic-gate * are effectively constant.
16107c478bd9Sstevel@tonic-gate */
16117c478bd9Sstevel@tonic-gate if (PM_GET_PM_INFO(dip)) {
16127c478bd9Sstevel@tonic-gate dcomps = DEVI(dip)->devi_pm_components;
16137c478bd9Sstevel@tonic-gate pm_comp = &dcomps[ppmd->cmpt].pmc_comp;
16147c478bd9Sstevel@tonic-gate
16157c478bd9Sstevel@tonic-gate ppmd->lowest = pm_comp->pmc_lvals[0];
16167c478bd9Sstevel@tonic-gate ASSERT(ppmd->lowest >= 0);
16177c478bd9Sstevel@tonic-gate maxi = pm_comp->pmc_numlevels - 1;
16187c478bd9Sstevel@tonic-gate ppmd->highest = pm_comp->pmc_lvals[maxi];
16197c478bd9Sstevel@tonic-gate }
16207c478bd9Sstevel@tonic-gate
16217c478bd9Sstevel@tonic-gate /*
16227c478bd9Sstevel@tonic-gate * add any domain-specific initialization here
16237c478bd9Sstevel@tonic-gate */
16247c478bd9Sstevel@tonic-gate if (ppmd->domp == &xcppm_fet) {
16257c478bd9Sstevel@tonic-gate /*
16267c478bd9Sstevel@tonic-gate * when a new device is added to domain_powefet
16277c478bd9Sstevel@tonic-gate * it is counted here as being powered up.
16287c478bd9Sstevel@tonic-gate */
16297c478bd9Sstevel@tonic-gate ppmd->domp->pwr_cnt++;
16307c478bd9Sstevel@tonic-gate DPRINTF(D_FET, ("xcppm_dev_init: UP cnt = %d\n",
16317c478bd9Sstevel@tonic-gate ppmd->domp->pwr_cnt));
16327c478bd9Sstevel@tonic-gate } else if (ppmd->domp == &xcppm_upa) {
16337c478bd9Sstevel@tonic-gate /*
16347c478bd9Sstevel@tonic-gate * There may be a better way to determine the device type
16357c478bd9Sstevel@tonic-gate * instead of comparing to hard coded string names.
16367c478bd9Sstevel@tonic-gate */
16377c478bd9Sstevel@tonic-gate if (strstr(ppmd->path, "pci@8,700000"))
16387c478bd9Sstevel@tonic-gate ppmd->flags = XCPPMF_PCIB;
16397c478bd9Sstevel@tonic-gate else if (strstr(ppmd->path, "upa@8,480000"))
16407c478bd9Sstevel@tonic-gate ppmd->flags = XCPPMF_UPA;
16417c478bd9Sstevel@tonic-gate }
16427c478bd9Sstevel@tonic-gate }
16437c478bd9Sstevel@tonic-gate
16447c478bd9Sstevel@tonic-gate
16457c478bd9Sstevel@tonic-gate /*
16467c478bd9Sstevel@tonic-gate * see ppmf and ppm_rem_dev
16477c478bd9Sstevel@tonic-gate */
16487c478bd9Sstevel@tonic-gate static void
xcppm_dev_fini(ppm_dev_t * ppmd)16497c478bd9Sstevel@tonic-gate xcppm_dev_fini(ppm_dev_t *ppmd)
16507c478bd9Sstevel@tonic-gate {
16517c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ppmd->domp->lock));
16527c478bd9Sstevel@tonic-gate if (ppmd->domp == &xcppm_fet) {
16537c478bd9Sstevel@tonic-gate if (ppmd->level != ppmd->lowest) {
16547c478bd9Sstevel@tonic-gate ppmd->domp->pwr_cnt--;
16557c478bd9Sstevel@tonic-gate DPRINTF(D_FET, ("xcppm_dev_fini: DN cnt = %d\n",
16567c478bd9Sstevel@tonic-gate ppmd->domp->pwr_cnt));
16577c478bd9Sstevel@tonic-gate };
16587c478bd9Sstevel@tonic-gate }
16597c478bd9Sstevel@tonic-gate }
16607c478bd9Sstevel@tonic-gate
16617c478bd9Sstevel@tonic-gate
16627c478bd9Sstevel@tonic-gate /*
16637c478bd9Sstevel@tonic-gate * see ppmf and ppm_ioctl, PPMIOCSET
16647c478bd9Sstevel@tonic-gate */
16657c478bd9Sstevel@tonic-gate static void
xcppm_iocset(uint8_t value)16667c478bd9Sstevel@tonic-gate xcppm_iocset(uint8_t value)
16677c478bd9Sstevel@tonic-gate {
16687c478bd9Sstevel@tonic-gate int action;
16697c478bd9Sstevel@tonic-gate
16707c478bd9Sstevel@tonic-gate if (value == PPM_IDEV_POWER_ON)
16717c478bd9Sstevel@tonic-gate action = XCPPM_SETBIT;
16727c478bd9Sstevel@tonic-gate else if (value == PPM_IDEV_POWER_OFF)
16737c478bd9Sstevel@tonic-gate action = XCPPM_CLRBIT;
16747c478bd9Sstevel@tonic-gate (void) xcppm_gpio_port2(action, DRVON);
16757c478bd9Sstevel@tonic-gate }
16767c478bd9Sstevel@tonic-gate
16777c478bd9Sstevel@tonic-gate
16787c478bd9Sstevel@tonic-gate /*
16797c478bd9Sstevel@tonic-gate * see ppmf and ppm_ioctl, PPMIOCGET
16807c478bd9Sstevel@tonic-gate */
16817c478bd9Sstevel@tonic-gate static uint8_t
xcppm_iocget(void)16827c478bd9Sstevel@tonic-gate xcppm_iocget(void)
16837c478bd9Sstevel@tonic-gate {
16847c478bd9Sstevel@tonic-gate uint8_t bit;
16857c478bd9Sstevel@tonic-gate
16867c478bd9Sstevel@tonic-gate bit = xcppm_gpio_port2(XCPPM_GETBIT, DRVON);
16877c478bd9Sstevel@tonic-gate return ((bit == DRVON) ? PPM_IDEV_POWER_ON : PPM_IDEV_POWER_OFF);
16887c478bd9Sstevel@tonic-gate }
1689