1*e4b86885SCheng Sean Ye /* 2*e4b86885SCheng Sean Ye * CDDL HEADER START 3*e4b86885SCheng Sean Ye * 4*e4b86885SCheng Sean Ye * The contents of this file are subject to the terms of the 5*e4b86885SCheng Sean Ye * Common Development and Distribution License (the "License"). 6*e4b86885SCheng Sean Ye * You may not use this file except in compliance with the License. 7*e4b86885SCheng Sean Ye * 8*e4b86885SCheng Sean Ye * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*e4b86885SCheng Sean Ye * or http://www.opensolaris.org/os/licensing. 10*e4b86885SCheng Sean Ye * See the License for the specific language governing permissions 11*e4b86885SCheng Sean Ye * and limitations under the License. 12*e4b86885SCheng Sean Ye * 13*e4b86885SCheng Sean Ye * When distributing Covered Code, include this CDDL HEADER in each 14*e4b86885SCheng Sean Ye * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*e4b86885SCheng Sean Ye * If applicable, add the following below this CDDL HEADER, with the 16*e4b86885SCheng Sean Ye * fields enclosed by brackets "[]" replaced with your own identifying 17*e4b86885SCheng Sean Ye * information: Portions Copyright [yyyy] [name of copyright owner] 18*e4b86885SCheng Sean Ye * 19*e4b86885SCheng Sean Ye * CDDL HEADER END 20*e4b86885SCheng Sean Ye */ 21*e4b86885SCheng Sean Ye 22*e4b86885SCheng Sean Ye /* 23*e4b86885SCheng Sean Ye * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24*e4b86885SCheng Sean Ye * Use is subject to license terms. 25*e4b86885SCheng Sean Ye */ 26*e4b86885SCheng Sean Ye 27*e4b86885SCheng Sean Ye #include <sys/ddi.h> 28*e4b86885SCheng Sean Ye #include <sys/sunddi.h> 29*e4b86885SCheng Sean Ye 30*e4b86885SCheng Sean Ye #include <mcamd_pcicfg.h> 31*e4b86885SCheng Sean Ye #include <sys/pci_cfgspace.h> 32*e4b86885SCheng Sean Ye 33*e4b86885SCheng Sean Ye struct _mc_pcicfg_hdl { 34*e4b86885SCheng Sean Ye mc_t *cfh_mc; 35*e4b86885SCheng Sean Ye enum mc_funcnum cfh_func; 36*e4b86885SCheng Sean Ye ddi_acc_handle_t cfh_hdl; 37*e4b86885SCheng Sean Ye }; 38*e4b86885SCheng Sean Ye 39*e4b86885SCheng Sean Ye static int 40*e4b86885SCheng Sean Ye mccfgsetup(struct _mc_pcicfg_hdl *hdlp, mc_t *mc, enum mc_funcnum func) 41*e4b86885SCheng Sean Ye { 42*e4b86885SCheng Sean Ye hdlp->cfh_mc = mc; 43*e4b86885SCheng Sean Ye hdlp->cfh_func = func; 44*e4b86885SCheng Sean Ye 45*e4b86885SCheng Sean Ye if (mc->mc_funcs[func].mcf_devi == NULL) 46*e4b86885SCheng Sean Ye return (DDI_FAILURE); 47*e4b86885SCheng Sean Ye 48*e4b86885SCheng Sean Ye if (pci_config_setup(mc->mc_funcs[func].mcf_devi, &hdlp->cfh_hdl) != 49*e4b86885SCheng Sean Ye DDI_SUCCESS) 50*e4b86885SCheng Sean Ye return (DDI_FAILURE); 51*e4b86885SCheng Sean Ye 52*e4b86885SCheng Sean Ye return (DDI_SUCCESS); 53*e4b86885SCheng Sean Ye } 54*e4b86885SCheng Sean Ye 55*e4b86885SCheng Sean Ye int 56*e4b86885SCheng Sean Ye mc_pcicfg_setup(mc_t *mc, enum mc_funcnum func, mc_pcicfg_hdl_t *cookiep) 57*e4b86885SCheng Sean Ye { 58*e4b86885SCheng Sean Ye struct _mc_pcicfg_hdl *hdlp; 59*e4b86885SCheng Sean Ye 60*e4b86885SCheng Sean Ye *cookiep = hdlp = kmem_alloc(sizeof (struct _mc_pcicfg_hdl), KM_SLEEP); 61*e4b86885SCheng Sean Ye 62*e4b86885SCheng Sean Ye if (mccfgsetup(hdlp, mc, func) == DDI_FAILURE) { 63*e4b86885SCheng Sean Ye kmem_free(hdlp, sizeof (*hdlp)); 64*e4b86885SCheng Sean Ye return (DDI_FAILURE); 65*e4b86885SCheng Sean Ye } 66*e4b86885SCheng Sean Ye 67*e4b86885SCheng Sean Ye return (DDI_SUCCESS); 68*e4b86885SCheng Sean Ye } 69*e4b86885SCheng Sean Ye 70*e4b86885SCheng Sean Ye void 71*e4b86885SCheng Sean Ye mc_pcicfg_teardown(mc_pcicfg_hdl_t cookie) 72*e4b86885SCheng Sean Ye { 73*e4b86885SCheng Sean Ye struct _mc_pcicfg_hdl *hdlp = cookie; 74*e4b86885SCheng Sean Ye 75*e4b86885SCheng Sean Ye pci_config_teardown(&hdlp->cfh_hdl); 76*e4b86885SCheng Sean Ye kmem_free(hdlp, sizeof (*hdlp)); 77*e4b86885SCheng Sean Ye } 78*e4b86885SCheng Sean Ye 79*e4b86885SCheng Sean Ye uint32_t 80*e4b86885SCheng Sean Ye mc_pcicfg_get32(mc_pcicfg_hdl_t cookie, off_t offset) 81*e4b86885SCheng Sean Ye { 82*e4b86885SCheng Sean Ye struct _mc_pcicfg_hdl *hdlp = cookie; 83*e4b86885SCheng Sean Ye 84*e4b86885SCheng Sean Ye return (pci_config_get32(hdlp->cfh_hdl, offset)); 85*e4b86885SCheng Sean Ye } 86*e4b86885SCheng Sean Ye 87*e4b86885SCheng Sean Ye void 88*e4b86885SCheng Sean Ye mc_pcicfg_put32(mc_pcicfg_hdl_t cookie, off_t offset, uint32_t val) 89*e4b86885SCheng Sean Ye { 90*e4b86885SCheng Sean Ye struct _mc_pcicfg_hdl *hdlp = cookie; 91*e4b86885SCheng Sean Ye 92*e4b86885SCheng Sean Ye pci_config_put32(hdlp->cfh_hdl, offset, val); 93*e4b86885SCheng Sean Ye } 94*e4b86885SCheng Sean Ye 95*e4b86885SCheng Sean Ye uint32_t 96*e4b86885SCheng Sean Ye mc_pcicfg_get32_nohdl(mc_t *mc, enum mc_funcnum func, off_t offset) 97*e4b86885SCheng Sean Ye { 98*e4b86885SCheng Sean Ye return ((*pci_getl_func)(0, MC_AMD_DEV_OFFSET + mc->mc_props.mcp_num, 99*e4b86885SCheng Sean Ye func, offset)); 100*e4b86885SCheng Sean Ye } 101*e4b86885SCheng Sean Ye 102*e4b86885SCheng Sean Ye void 103*e4b86885SCheng Sean Ye mc_pcicfg_put32_nohdl(mc_t *mc, enum mc_funcnum func, off_t offset, 104*e4b86885SCheng Sean Ye uint32_t val) 105*e4b86885SCheng Sean Ye { 106*e4b86885SCheng Sean Ye (*pci_putl_func)(0, MC_AMD_DEV_OFFSET + mc->mc_props.mcp_num, 107*e4b86885SCheng Sean Ye func, offset, val); 108*e4b86885SCheng Sean Ye } 109