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