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