xref: /onnv-gate/usr/src/uts/common/io/1394/s1394.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma	ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate  * s1394.c
31*0Sstevel@tonic-gate  *    1394 Services Layer Initialization and Cleanup Routines
32*0Sstevel@tonic-gate  *    The routines do all initialization and cleanup for the Sevices Layer
33*0Sstevel@tonic-gate  */
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #include <sys/conf.h>
36*0Sstevel@tonic-gate #include <sys/ddi.h>
37*0Sstevel@tonic-gate #include <sys/sunddi.h>
38*0Sstevel@tonic-gate #include <sys/types.h>
39*0Sstevel@tonic-gate #include <sys/kmem.h>
40*0Sstevel@tonic-gate #include <sys/tnf_probe.h>
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate #include <sys/1394/t1394.h>
43*0Sstevel@tonic-gate #include <sys/1394/s1394.h>
44*0Sstevel@tonic-gate #include <sys/1394/h1394.h>
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate /* Driver State Pointer */
47*0Sstevel@tonic-gate s1394_state_t *s1394_statep;
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /* Module Driver Info */
50*0Sstevel@tonic-gate static struct modlmisc s1394_modlmisc = {
51*0Sstevel@tonic-gate 	&mod_miscops,
52*0Sstevel@tonic-gate 	"IEEE 1394 Services Library 1.0"
53*0Sstevel@tonic-gate };
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate /* Module Linkage */
56*0Sstevel@tonic-gate static struct modlinkage s1394_modlinkage = {
57*0Sstevel@tonic-gate 	MODREV_1,
58*0Sstevel@tonic-gate 	&s1394_modlmisc,
59*0Sstevel@tonic-gate 	NULL
60*0Sstevel@tonic-gate };
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate static int s1394_init();
63*0Sstevel@tonic-gate static void s1394_fini();
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate #ifndef NPROBE
66*0Sstevel@tonic-gate extern int tnf_mod_load(void);
67*0Sstevel@tonic-gate extern int tnf_mod_unload(struct modlinkage *mlp);
68*0Sstevel@tonic-gate #endif
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate int
_init()71*0Sstevel@tonic-gate _init()
72*0Sstevel@tonic-gate {
73*0Sstevel@tonic-gate 	int status;
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate #ifndef	NPROBE
76*0Sstevel@tonic-gate 	(void) tnf_mod_load();
77*0Sstevel@tonic-gate #endif
78*0Sstevel@tonic-gate 	status = s1394_init();
79*0Sstevel@tonic-gate 	if (status != 0) {
80*0Sstevel@tonic-gate 		TNF_PROBE_1(_init_error, S1394_TNF_SL_ERROR, "",
81*0Sstevel@tonic-gate 		    tnf_string, msg, "s1394: failed in s1394_init");
82*0Sstevel@tonic-gate #ifndef NPROBE
83*0Sstevel@tonic-gate 		(void) tnf_mod_unload(&s1394_modlinkage);
84*0Sstevel@tonic-gate #endif
85*0Sstevel@tonic-gate 		return (status);
86*0Sstevel@tonic-gate 	}
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate 	status = mod_install(&s1394_modlinkage);
89*0Sstevel@tonic-gate 	if (status != 0) {
90*0Sstevel@tonic-gate 		TNF_PROBE_1(_init_error, S1394_TNF_SL_ERROR, "",
91*0Sstevel@tonic-gate 		    tnf_string, msg, "s1394: failed in mod_install");
92*0Sstevel@tonic-gate #ifndef NPROBE
93*0Sstevel@tonic-gate 		(void) tnf_mod_unload(&s1394_modlinkage);
94*0Sstevel@tonic-gate #endif
95*0Sstevel@tonic-gate 	}
96*0Sstevel@tonic-gate 	return (status);
97*0Sstevel@tonic-gate }
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate int
_info(struct modinfo * modinfop)100*0Sstevel@tonic-gate _info(struct modinfo *modinfop)
101*0Sstevel@tonic-gate {
102*0Sstevel@tonic-gate 	return (mod_info(&s1394_modlinkage, modinfop));
103*0Sstevel@tonic-gate }
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate int
_fini()106*0Sstevel@tonic-gate _fini()
107*0Sstevel@tonic-gate {
108*0Sstevel@tonic-gate 	int status;
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate 	status = mod_remove(&s1394_modlinkage);
111*0Sstevel@tonic-gate 	if (status != 0) {
112*0Sstevel@tonic-gate 		TNF_PROBE_1(_fini_error, S1394_TNF_SL_ERROR, "",
113*0Sstevel@tonic-gate 		    tnf_string, msg, "s1394: failed in mod_remove");
114*0Sstevel@tonic-gate 		return (status);
115*0Sstevel@tonic-gate 	}
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate 	s1394_fini();
118*0Sstevel@tonic-gate #ifndef NPROBE
119*0Sstevel@tonic-gate 	(void) tnf_mod_unload(&s1394_modlinkage);
120*0Sstevel@tonic-gate #endif
121*0Sstevel@tonic-gate 	return (status);
122*0Sstevel@tonic-gate }
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate /*
125*0Sstevel@tonic-gate  * s1394_init()
126*0Sstevel@tonic-gate  *    initializes the 1394 Software Framework's structures, i.e. the HAL list
127*0Sstevel@tonic-gate  *    and associated mutex.
128*0Sstevel@tonic-gate  */
129*0Sstevel@tonic-gate static int
s1394_init()130*0Sstevel@tonic-gate s1394_init()
131*0Sstevel@tonic-gate {
132*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_init_enter, S1394_TNF_SL_STACK, "");
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate 	s1394_statep = kmem_zalloc(sizeof (s1394_state_t), KM_SLEEP);
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate 	s1394_statep->hal_head = NULL;
137*0Sstevel@tonic-gate 	s1394_statep->hal_tail = NULL;
138*0Sstevel@tonic-gate 	mutex_init(&s1394_statep->hal_list_mutex, NULL, MUTEX_DRIVER, NULL);
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_init_exit, S1394_TNF_SL_STACK, "");
141*0Sstevel@tonic-gate 	return (0);
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate /*
145*0Sstevel@tonic-gate  * s1394_fini()
146*0Sstevel@tonic-gate  *    cleans up the 1394 Software Framework's structures that were allocated
147*0Sstevel@tonic-gate  *    in s1394_init().
148*0Sstevel@tonic-gate  */
149*0Sstevel@tonic-gate static void
s1394_fini()150*0Sstevel@tonic-gate s1394_fini()
151*0Sstevel@tonic-gate {
152*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fini_enter, S1394_TNF_SL_STACK, "");
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate 	mutex_destroy(&s1394_statep->hal_list_mutex);
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate 	kmem_free(s1394_statep, sizeof (s1394_state_t));
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fini_exit, S1394_TNF_SL_STACK, "");
159*0Sstevel@tonic-gate }
160