xref: /illumos-gate/usr/src/uts/common/io/1394/s1394.c (revision 2570281c)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 /*
28  * s1394.c
29  *    1394 Services Layer Initialization and Cleanup Routines
30  *    The routines do all initialization and cleanup for the Sevices Layer
31  */
32 
33 #include <sys/conf.h>
34 #include <sys/ddi.h>
35 #include <sys/sunddi.h>
36 #include <sys/types.h>
37 #include <sys/kmem.h>
38 #include <sys/1394/t1394.h>
39 #include <sys/1394/s1394.h>
40 #include <sys/1394/h1394.h>
41 
42 /* Driver State Pointer */
43 s1394_state_t *s1394_statep;
44 
45 /* Module Driver Info */
46 static struct modlmisc s1394_modlmisc = {
47 	&mod_miscops,
48 	"IEEE 1394 Services Library 1.0"
49 };
50 
51 /* Module Linkage */
52 static struct modlinkage s1394_modlinkage = {
53 	MODREV_1,
54 	&s1394_modlmisc,
55 	NULL
56 };
57 
58 static int s1394_init();
59 static void s1394_fini();
60 
61 int
_init()62 _init()
63 {
64 	int status;
65 
66 	status = s1394_init();
67 	if (status != 0) {
68 		return (status);
69 	}
70 
71 	status = mod_install(&s1394_modlinkage);
72 	return (status);
73 }
74 
75 int
_info(struct modinfo * modinfop)76 _info(struct modinfo *modinfop)
77 {
78 	return (mod_info(&s1394_modlinkage, modinfop));
79 }
80 
81 int
_fini()82 _fini()
83 {
84 	int status;
85 
86 	status = mod_remove(&s1394_modlinkage);
87 	if (status != 0) {
88 		return (status);
89 	}
90 
91 	s1394_fini();
92 	return (status);
93 }
94 
95 /*
96  * s1394_init()
97  *    initializes the 1394 Software Framework's structures, i.e. the HAL list
98  *    and associated mutex.
99  */
100 static int
s1394_init()101 s1394_init()
102 {
103 	s1394_statep = kmem_zalloc(sizeof (s1394_state_t), KM_SLEEP);
104 
105 	s1394_statep->hal_head = NULL;
106 	s1394_statep->hal_tail = NULL;
107 	mutex_init(&s1394_statep->hal_list_mutex, NULL, MUTEX_DRIVER, NULL);
108 
109 	return (0);
110 }
111 
112 /*
113  * s1394_fini()
114  *    cleans up the 1394 Software Framework's structures that were allocated
115  *    in s1394_init().
116  */
117 static void
s1394_fini()118 s1394_fini()
119 {
120 	mutex_destroy(&s1394_statep->hal_list_mutex);
121 
122 	kmem_free(s1394_statep, sizeof (s1394_state_t));
123 }
124