xref: /onnv-gate/usr/src/uts/sun4v/io/iospc/rfios_iospc.c (revision 11304:3092d1e303d6)
1*11304SJanie.Lu@Sun.COM /*
2*11304SJanie.Lu@Sun.COM  * CDDL HEADER START
3*11304SJanie.Lu@Sun.COM  *
4*11304SJanie.Lu@Sun.COM  * The contents of this file are subject to the terms of the
5*11304SJanie.Lu@Sun.COM  * Common Development and Distribution License (the "License").
6*11304SJanie.Lu@Sun.COM  * You may not use this file except in compliance with the License.
7*11304SJanie.Lu@Sun.COM  *
8*11304SJanie.Lu@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*11304SJanie.Lu@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*11304SJanie.Lu@Sun.COM  * See the License for the specific language governing permissions
11*11304SJanie.Lu@Sun.COM  * and limitations under the License.
12*11304SJanie.Lu@Sun.COM  *
13*11304SJanie.Lu@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*11304SJanie.Lu@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*11304SJanie.Lu@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*11304SJanie.Lu@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*11304SJanie.Lu@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*11304SJanie.Lu@Sun.COM  *
19*11304SJanie.Lu@Sun.COM  * CDDL HEADER END
20*11304SJanie.Lu@Sun.COM  */
21*11304SJanie.Lu@Sun.COM 
22*11304SJanie.Lu@Sun.COM /*
23*11304SJanie.Lu@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*11304SJanie.Lu@Sun.COM  * Use is subject to license terms.
25*11304SJanie.Lu@Sun.COM  */
26*11304SJanie.Lu@Sun.COM #include <sys/types.h>
27*11304SJanie.Lu@Sun.COM #include <sys/ddi.h>
28*11304SJanie.Lu@Sun.COM #include <sys/modctl.h>
29*11304SJanie.Lu@Sun.COM #include <sys/kmem.h>
30*11304SJanie.Lu@Sun.COM #include <sys/sunddi.h>
31*11304SJanie.Lu@Sun.COM #include <sys/sunndi.h>
32*11304SJanie.Lu@Sun.COM #include <sys/disp.h>
33*11304SJanie.Lu@Sun.COM #include <sys/stat.h>
34*11304SJanie.Lu@Sun.COM #include <sys/pci.h>
35*11304SJanie.Lu@Sun.COM #include <sys/hsvc.h>
36*11304SJanie.Lu@Sun.COM #include "iospc.h"
37*11304SJanie.Lu@Sun.COM #include "rfios_acc.h"
38*11304SJanie.Lu@Sun.COM #include "rfios_tables.h"
39*11304SJanie.Lu@Sun.COM 
40*11304SJanie.Lu@Sun.COM extern iospc_grp_t *rfios_leaf_grps[];
41*11304SJanie.Lu@Sun.COM 
42*11304SJanie.Lu@Sun.COM #define	RF_REQ_MAJOR_VER	1
43*11304SJanie.Lu@Sun.COM #define	RF_REQ_MINOR_VER	0
44*11304SJanie.Lu@Sun.COM 
45*11304SJanie.Lu@Sun.COM static hsvc_info_t rfios_hsvc = {
46*11304SJanie.Lu@Sun.COM 	HSVC_REV_1,
47*11304SJanie.Lu@Sun.COM 	NULL,
48*11304SJanie.Lu@Sun.COM 	RF_PERF_COUNTER_GROUP_ID,
49*11304SJanie.Lu@Sun.COM 	RF_REQ_MAJOR_VER,
50*11304SJanie.Lu@Sun.COM 	RF_REQ_MINOR_VER,
51*11304SJanie.Lu@Sun.COM 	MODULE_NAME	/* Passed in as a #define from Makefile */
52*11304SJanie.Lu@Sun.COM };
53*11304SJanie.Lu@Sun.COM 
54*11304SJanie.Lu@Sun.COM static uint64_t rfios_sup_minor;
55*11304SJanie.Lu@Sun.COM 
56*11304SJanie.Lu@Sun.COM iospc_grp_t **
rfios_bind_group(void)57*11304SJanie.Lu@Sun.COM rfios_bind_group(void)
58*11304SJanie.Lu@Sun.COM {
59*11304SJanie.Lu@Sun.COM 	int rval;
60*11304SJanie.Lu@Sun.COM 
61*11304SJanie.Lu@Sun.COM 	if ((rval = hsvc_register(&rfios_hsvc, &rfios_sup_minor)) !=
62*11304SJanie.Lu@Sun.COM 	    DDI_SUCCESS) {
63*11304SJanie.Lu@Sun.COM 		IOSPC_DBG1("%s: Could not hsvc_register: %d\n",
64*11304SJanie.Lu@Sun.COM 		    MODULE_NAME, rval);
65*11304SJanie.Lu@Sun.COM 
66*11304SJanie.Lu@Sun.COM 		return (NULL);
67*11304SJanie.Lu@Sun.COM 	}
68*11304SJanie.Lu@Sun.COM 
69*11304SJanie.Lu@Sun.COM 	return ((iospc_grp_t **)&rfios_leaf_grps);
70*11304SJanie.Lu@Sun.COM }
71*11304SJanie.Lu@Sun.COM 
72*11304SJanie.Lu@Sun.COM void
rfios_unbind_group(void)73*11304SJanie.Lu@Sun.COM rfios_unbind_group(void)
74*11304SJanie.Lu@Sun.COM {
75*11304SJanie.Lu@Sun.COM 	(void) hsvc_unregister(&rfios_hsvc);
76*11304SJanie.Lu@Sun.COM }
77*11304SJanie.Lu@Sun.COM 
78*11304SJanie.Lu@Sun.COM int
rfios_access_init(iospc_t * iospc_p,iospc_ksinfo_t * ksinfo_p)79*11304SJanie.Lu@Sun.COM rfios_access_init(iospc_t *iospc_p, iospc_ksinfo_t *ksinfo_p)
80*11304SJanie.Lu@Sun.COM {
81*11304SJanie.Lu@Sun.COM 	uint32_t regprop[4];
82*11304SJanie.Lu@Sun.COM 	int len;
83*11304SJanie.Lu@Sun.COM 	cntr_handle_t   iospc_handle;
84*11304SJanie.Lu@Sun.COM 
85*11304SJanie.Lu@Sun.COM 	IOSPC_DBG2("rfios_access_init: iospc_p=%p\n", (void *)iospc_p);
86*11304SJanie.Lu@Sun.COM 
87*11304SJanie.Lu@Sun.COM 	len = sizeof (regprop);
88*11304SJanie.Lu@Sun.COM 	if (ddi_getlongprop_buf(DDI_DEV_T_ANY, iospc_p->iospc_dip,
89*11304SJanie.Lu@Sun.COM 	    DDI_PROP_DONTPASS, "reg", (caddr_t)regprop, &len) !=
90*11304SJanie.Lu@Sun.COM 	    DDI_SUCCESS) {
91*11304SJanie.Lu@Sun.COM 		return (FAILURE);
92*11304SJanie.Lu@Sun.COM 	}
93*11304SJanie.Lu@Sun.COM 
94*11304SJanie.Lu@Sun.COM 	iospc_handle = (regprop[0] & 0xfffffff);
95*11304SJanie.Lu@Sun.COM 	ksinfo_p->arg = (void *)iospc_handle;
96*11304SJanie.Lu@Sun.COM 
97*11304SJanie.Lu@Sun.COM 	return (SUCCESS);
98*11304SJanie.Lu@Sun.COM 
99*11304SJanie.Lu@Sun.COM }
100*11304SJanie.Lu@Sun.COM 
101*11304SJanie.Lu@Sun.COM int
rfios_access_fini(iospc_t * iospc_p,iospc_ksinfo_t * ksinfo_p)102*11304SJanie.Lu@Sun.COM rfios_access_fini(iospc_t *iospc_p, iospc_ksinfo_t *ksinfo_p)
103*11304SJanie.Lu@Sun.COM {
104*11304SJanie.Lu@Sun.COM 	IOSPC_DBG2("rfios_access_fini: iospc_p=%p ksinfo_p=%p\n",
105*11304SJanie.Lu@Sun.COM 	    (void *)iospc_p, (void *)ksinfo_p);
106*11304SJanie.Lu@Sun.COM 	return (SUCCESS);
107*11304SJanie.Lu@Sun.COM }
108*11304SJanie.Lu@Sun.COM 
109*11304SJanie.Lu@Sun.COM int
rfios_access_hv(iospc_t * iospc_p,void * arg,int op,int regid,uint64_t * data)110*11304SJanie.Lu@Sun.COM rfios_access_hv(iospc_t *iospc_p, void *arg, int op, int regid, uint64_t *data)
111*11304SJanie.Lu@Sun.COM {
112*11304SJanie.Lu@Sun.COM 	cntr_handle_t   iospc_handle = (cntr_handle_t)arg;
113*11304SJanie.Lu@Sun.COM 
114*11304SJanie.Lu@Sun.COM 	if (op == IOSPC_REG_READ) {
115*11304SJanie.Lu@Sun.COM 		if (rfiospc_get_perfreg(iospc_handle, regid, data) != H_EOK) {
116*11304SJanie.Lu@Sun.COM 			IOSPC_DBG2("rfios_access_hv: READ handle=%p regid=%x "
117*11304SJanie.Lu@Sun.COM 			    "- Failed\n", (void *)iospc_p, regid);
118*11304SJanie.Lu@Sun.COM 			return (FAILURE);
119*11304SJanie.Lu@Sun.COM 		}
120*11304SJanie.Lu@Sun.COM 
121*11304SJanie.Lu@Sun.COM 		IOSPC_DBG2("rfios_access_hv: READ handle=%p regid=%x "
122*11304SJanie.Lu@Sun.COM 		    "data=%lx\n", (void *)iospc_p, regid, *data);
123*11304SJanie.Lu@Sun.COM 
124*11304SJanie.Lu@Sun.COM 	} else { /* IOSPC_REG_WRITE */
125*11304SJanie.Lu@Sun.COM 		if (rfiospc_set_perfreg(iospc_handle, regid, *data) != H_EOK) {
126*11304SJanie.Lu@Sun.COM 			IOSPC_DBG2("rfios_access_hv: READ handle=%p regid=%x "
127*11304SJanie.Lu@Sun.COM 			    "- Failed\n", (void *)iospc_p, regid);
128*11304SJanie.Lu@Sun.COM 			return (FAILURE);
129*11304SJanie.Lu@Sun.COM 		}
130*11304SJanie.Lu@Sun.COM 
131*11304SJanie.Lu@Sun.COM 		IOSPC_DBG2("rfios_access_hv: WRITE  handle=%p regid=%x "
132*11304SJanie.Lu@Sun.COM 		    "data=%lx\n", (void *)iospc_p, regid, *data);
133*11304SJanie.Lu@Sun.COM 	}
134*11304SJanie.Lu@Sun.COM 
135*11304SJanie.Lu@Sun.COM 	return (SUCCESS);
136*11304SJanie.Lu@Sun.COM }
137