xref: /illumos-gate/usr/src/uts/sun4/io/fpc/fpc.c (revision 2aeafac3612e19716bf8164f89c3c9196342979c)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 
28 #include <sys/types.h>
29 #include <sys/sunddi.h>
30 #include <sys/sunndi.h>
31 #include <sys/conf.h>
32 #include <sys/modctl.h>
33 #include <sys/stat.h>
34 #include <fpc.h>
35 
36 static int fpc_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
37 static int fpc_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
38 
39 static struct dev_ops fpc_ops = {
40 	DEVO_REV,
41 	0,
42 	nulldev,
43 	nulldev,
44 	nulldev,
45 	fpc_attach,
46 	fpc_detach,
47 	nodev,
48 	NULL,
49 	NULL,
50 	nodev,
51 	ddi_quiesce_not_needed,		/* quiesce */
52 };
53 
54 extern struct mod_ops mod_driverops;
55 
56 static struct modldrv md = {
57 	&mod_driverops,
58 	"IO Chip Perf Counter",
59 	&fpc_ops,
60 };
61 
62 static struct modlinkage ml = {
63 	MODREV_1,
64 	(void *)&md,
65 	NULL
66 };
67 
68 int
69 _init(void)
70 {
71 	if (fpc_init_platform_check() != SUCCESS)
72 		return (ENODEV);
73 	return (mod_install(&ml));
74 }
75 
76 int
77 _info(struct modinfo *modinfop)
78 {
79 	return (mod_info(&ml, modinfop));
80 }
81 
82 int
83 _fini(void)
84 {
85 	return (mod_remove(&ml));
86 }
87 
88 static int
89 fpc_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
90 {
91 	switch (cmd) {
92 	/*
93 	 * Since the driver saves no state between calls, we can fully detach
94 	 * on suspend and fully attach on resume.
95 	 *
96 	 * An RFE might be to save event register states for restore.
97 	 * The result of not doing this is that the kstat reader (busstat)
98 	 * may quit upon resume, seeing that the events have changed out from
99 	 * underneath it (since the registers were powered off upon suspend).
100 	 */
101 	case DDI_RESUME:
102 	case DDI_ATTACH:
103 		if (fpc_kstat_init(dip) != DDI_SUCCESS) {
104 			(void) fpc_detach(dip, DDI_DETACH);
105 			return (DDI_FAILURE);
106 		}
107 		return (DDI_SUCCESS);
108 	default:
109 		return (DDI_FAILURE);
110 	}
111 }
112 
113 static int
114 fpc_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
115 {
116 	switch (cmd) {
117 	case DDI_SUSPEND:
118 	case DDI_DETACH:
119 		fpc_kstat_fini(dip);
120 		return (DDI_SUCCESS);
121 	default:
122 		return (DDI_FAILURE);
123 	}
124 }
125