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