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 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*6c9bfa0bSjan * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Schizo Power Management Driver 317c478bd9Sstevel@tonic-gate * 327c478bd9Sstevel@tonic-gate * This driver deals with Safari bus interface and it is used 337c478bd9Sstevel@tonic-gate * as part of the protocol to change the clock speed on Safari bus. 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * The routine on this driver is referenced by Platform Power 367c478bd9Sstevel@tonic-gate * Management driver of systems like Excalibur. Driver is 377c478bd9Sstevel@tonic-gate * loaded because of an explicit dependency defined in PPM driver. 387c478bd9Sstevel@tonic-gate * PPM driver also attaches the driver. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #include <sys/types.h> 427c478bd9Sstevel@tonic-gate #include <sys/conf.h> 437c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 447c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 457c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* 497c478bd9Sstevel@tonic-gate * Function prototypes 507c478bd9Sstevel@tonic-gate */ 517c478bd9Sstevel@tonic-gate static int spm_attach(dev_info_t *, ddi_attach_cmd_t); 527c478bd9Sstevel@tonic-gate static int spm_detach(dev_info_t *, ddi_detach_cmd_t); 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * Private data for schizo_pm driver 567c478bd9Sstevel@tonic-gate */ 57*6c9bfa0bSjan struct spm_soft_state { 587c478bd9Sstevel@tonic-gate dev_info_t *dip; 597c478bd9Sstevel@tonic-gate }; 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* 627c478bd9Sstevel@tonic-gate * Configuration data structures 637c478bd9Sstevel@tonic-gate */ 647c478bd9Sstevel@tonic-gate static struct dev_ops spm_ops = { 657c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 667c478bd9Sstevel@tonic-gate 0, /* refcnt */ 677c478bd9Sstevel@tonic-gate nodev, /* getinfo */ 687c478bd9Sstevel@tonic-gate nulldev, /* identify */ 697c478bd9Sstevel@tonic-gate nulldev, /* probe */ 707c478bd9Sstevel@tonic-gate spm_attach, /* attach */ 717c478bd9Sstevel@tonic-gate spm_detach, /* detach */ 727c478bd9Sstevel@tonic-gate nodev, /* reset */ 737c478bd9Sstevel@tonic-gate (struct cb_ops *)0, /* cb_ops */ 747c478bd9Sstevel@tonic-gate (struct bus_ops *)0, /* bus_ops */ 757c478bd9Sstevel@tonic-gate NULL /* power */ 767c478bd9Sstevel@tonic-gate }; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate /* 797c478bd9Sstevel@tonic-gate * Driver globals 807c478bd9Sstevel@tonic-gate */ 817c478bd9Sstevel@tonic-gate static void *spm_state; 827c478bd9Sstevel@tonic-gate static int spm_inst = -1; 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 857c478bd9Sstevel@tonic-gate &mod_driverops, /* Type of module = driver */ 867c478bd9Sstevel@tonic-gate "schizo pm driver v%I%", /* name of module */ 877c478bd9Sstevel@tonic-gate &spm_ops, /* driver ops */ 887c478bd9Sstevel@tonic-gate }; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 917c478bd9Sstevel@tonic-gate MODREV_1, 927c478bd9Sstevel@tonic-gate (void *)&modldrv, 937c478bd9Sstevel@tonic-gate NULL 947c478bd9Sstevel@tonic-gate }; 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* 977c478bd9Sstevel@tonic-gate * Schizo CSR E* bit masks 987c478bd9Sstevel@tonic-gate */ 997c478bd9Sstevel@tonic-gate #define SCHIZO_SAFARI_ECLK_32 0x20ULL 1007c478bd9Sstevel@tonic-gate #define SCHIZO_SAFARI_ECLK_2 0x2ULL 1017c478bd9Sstevel@tonic-gate #define SCHIZO_SAFARI_ECLK_1 0x1ULL 1027c478bd9Sstevel@tonic-gate #define SCHIZO_SAFARI_ECLK_MASK (SCHIZO_SAFARI_ECLK_32 | \ 1037c478bd9Sstevel@tonic-gate SCHIZO_SAFARI_ECLK_2 | SCHIZO_SAFARI_ECLK_1) 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* 1067c478bd9Sstevel@tonic-gate * bit masks to set schizo clock in parallel with setting cpu clock. 1077c478bd9Sstevel@tonic-gate * Used when changing cpu speeds. 1087c478bd9Sstevel@tonic-gate * 1097c478bd9Sstevel@tonic-gate * NOTE: The order of entries must be from slowest to fastest. 1107c478bd9Sstevel@tonic-gate */ 1117c478bd9Sstevel@tonic-gate static const uint64_t schizo_safari_masks[] = { 1127c478bd9Sstevel@tonic-gate SCHIZO_SAFARI_ECLK_32, 1137c478bd9Sstevel@tonic-gate SCHIZO_SAFARI_ECLK_2, 1147c478bd9Sstevel@tonic-gate SCHIZO_SAFARI_ECLK_1 1157c478bd9Sstevel@tonic-gate }; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * Normally, the address of the registers we use would be accessed from 1197c478bd9Sstevel@tonic-gate * our "official" private data. However, since the dip is not passed 1207c478bd9Sstevel@tonic-gate * in when spm_change_speed (see below) is called, and since there is 1217c478bd9Sstevel@tonic-gate * only one unit of the spm "device", we keep it here as a static. 1227c478bd9Sstevel@tonic-gate */ 1237c478bd9Sstevel@tonic-gate static volatile uint64_t *spm_schizo_csr; 1247c478bd9Sstevel@tonic-gate ddi_acc_handle_t spm_schizo_handle; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate int 1277c478bd9Sstevel@tonic-gate _init(void) 1287c478bd9Sstevel@tonic-gate { 1297c478bd9Sstevel@tonic-gate int error; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate if ((error = ddi_soft_state_init(&spm_state, 1327c478bd9Sstevel@tonic-gate sizeof (struct spm_soft_state), 0)) != 0) 1337c478bd9Sstevel@tonic-gate return (error); 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate if ((error = mod_install(&modlinkage)) != 0) 1367c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&spm_state); 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate return (error); 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate int 1427c478bd9Sstevel@tonic-gate _fini(void) 1437c478bd9Sstevel@tonic-gate { 1447c478bd9Sstevel@tonic-gate int error; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) == 0) 1477c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&spm_state); 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate return (error); 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate int 1537c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 1547c478bd9Sstevel@tonic-gate { 1557c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate static int 1597c478bd9Sstevel@tonic-gate spm_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 1607c478bd9Sstevel@tonic-gate { 1617c478bd9Sstevel@tonic-gate int rv; 1627c478bd9Sstevel@tonic-gate struct spm_soft_state *softsp; 1637c478bd9Sstevel@tonic-gate ddi_device_acc_attr_t attr; 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate switch (cmd) { 1667c478bd9Sstevel@tonic-gate case DDI_ATTACH: 1677c478bd9Sstevel@tonic-gate if (spm_inst != -1) { 1687c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "spm_attach: " 1697c478bd9Sstevel@tonic-gate "only one instance is allowed."); 1707c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate break; 1747c478bd9Sstevel@tonic-gate case DDI_RESUME: 1757c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 1767c478bd9Sstevel@tonic-gate default: 1777c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate spm_inst = ddi_get_instance(dip); 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(spm_state, spm_inst) != DDI_SUCCESS) { 1837c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "spm_attach: can't allocate state."); 1847c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate if ((softsp = ddi_get_soft_state(spm_state, spm_inst)) == NULL) { 1887c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "spm_attach: can't get state."); 1897c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate softsp->dip = dip; 1937c478bd9Sstevel@tonic-gate attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 1947c478bd9Sstevel@tonic-gate attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC; 1957c478bd9Sstevel@tonic-gate attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate /* 1987c478bd9Sstevel@tonic-gate * Map the Safari E* Control register. 1997c478bd9Sstevel@tonic-gate */ 2007c478bd9Sstevel@tonic-gate rv = ddi_regs_map_setup(dip, 0, 2017c478bd9Sstevel@tonic-gate (caddr_t *)&spm_schizo_csr, 0, 8, &attr, &spm_schizo_handle); 2027c478bd9Sstevel@tonic-gate if (rv != DDI_SUCCESS) { 2037c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "spm_attach: can't map the register."); 2047c478bd9Sstevel@tonic-gate ddi_soft_state_free(spm_state, spm_inst); 2057c478bd9Sstevel@tonic-gate return (rv); 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate ddi_report_dev(dip); 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2147c478bd9Sstevel@tonic-gate static int 2157c478bd9Sstevel@tonic-gate spm_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 2167c478bd9Sstevel@tonic-gate { 2177c478bd9Sstevel@tonic-gate switch (cmd) { 2187c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 2197c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate case DDI_DETACH: 2227c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate default: 2257c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2267c478bd9Sstevel@tonic-gate } 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate /* 2307c478bd9Sstevel@tonic-gate * This globally visible function is the main reason this driver exists. 2317c478bd9Sstevel@tonic-gate * It will be called by a platform power management driver to write to 2327c478bd9Sstevel@tonic-gate * the schizo ASIC csr which changes schizo's clock rate. This is a 2337c478bd9Sstevel@tonic-gate * required step when changing the clock of the cpus. 2347c478bd9Sstevel@tonic-gate * 2357c478bd9Sstevel@tonic-gate * NOTE - The caller should enter this routine sequentially. 2367c478bd9Sstevel@tonic-gate */ 2377c478bd9Sstevel@tonic-gate void 2387c478bd9Sstevel@tonic-gate spm_change_schizo_speed(int lvl_index) 2397c478bd9Sstevel@tonic-gate { 2407c478bd9Sstevel@tonic-gate uint64_t contents; 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate ASSERT(lvl_index >= 0 && lvl_index <= 2); 2437c478bd9Sstevel@tonic-gate contents = ddi_get64(spm_schizo_handle, (uint64_t *)spm_schizo_csr); 2447c478bd9Sstevel@tonic-gate contents &= ~SCHIZO_SAFARI_ECLK_MASK; 2457c478bd9Sstevel@tonic-gate contents |= schizo_safari_masks[ lvl_index ]; 2467c478bd9Sstevel@tonic-gate ddi_put64(spm_schizo_handle, (uint64_t *)spm_schizo_csr, contents); 2477c478bd9Sstevel@tonic-gate } 248