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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 
27 /*
28  * hci1394.c
29  *    1394 (firewire) OpenHCI 1.0 HBA driver. This file contains the driver's
30  *    _init(), _info(), and _fini().
31  */
32 
33 #include <sys/modctl.h>
34 #include <sys/conf.h>
35 #include <sys/ddi.h>
36 #include <sys/sunddi.h>
37 
38 #include <sys/1394/ieee1394.h>
39 #include <sys/1394/h1394.h>
40 
41 #include <sys/1394/adapters/hci1394.h>
42 
43 
44 /* HAL State Pointer */
45 void *hci1394_statep;
46 
47 /* Character/Block Operations */
48 static struct cb_ops hci1394_cb_ops = {
49 	hci1394_open,		/* open */
50 	hci1394_close,		/* close */
51 	nodev,			/* strategy (block) */
52 	nodev,			/* print (block) */
53 	nodev,			/* dump (block) */
54 	nodev,			/* read */
55 	nodev,			/* write */
56 	hci1394_ioctl,		/* ioctl */
57 	nodev,			/* devmap */
58 	nodev,			/* mmap */
59 	nodev,			/* segmap */
60 	nochpoll,		/* chpoll */
61 	ddi_prop_op,		/* prop_op */
62 	NULL,			/* streams */
63 	D_NEW | D_MP |
64 	D_64BIT | D_HOTPLUG,	/* flags */
65 	CB_REV			/* rev */
66 };
67 
68 /* Driver Operations */
69 static struct dev_ops hci1394_ops = {
70 	DEVO_REV,		/* struct rev */
71 	0,			/* refcnt */
72 	hci1394_getinfo,	/* getinfo */
73 	nulldev,		/* identify */
74 	nulldev,		/* probe */
75 	hci1394_attach,		/* attach */
76 	hci1394_detach,		/* detach */
77 	nodev,			/* reset */
78 	&hci1394_cb_ops,	/* cb_ops */
79 	NULL,			/* bus_ops */
80 	NULL,			/* power */
81 	hci1394_quiesce,	/* devo_quiesce */
82 };
83 
84 /* Module Driver Info */
85 static struct modldrv hci1394_modldrv = {
86 	&mod_driverops,
87 	"1394 OpenHCI HBA driver",
88 	&hci1394_ops
89 };
90 
91 /* Module Linkage */
92 static struct modlinkage hci1394_modlinkage = {
93 	MODREV_1,
94 	&hci1394_modldrv,
95 	NULL
96 };
97 
98 int
_init()99 _init()
100 {
101 	int status;
102 
103 	status = ddi_soft_state_init(&hci1394_statep, sizeof (hci1394_state_t),
104 	    (size_t)HCI1394_INITIAL_STATES);
105 	if (status != 0) {
106 		return (status);
107 	}
108 
109 	/* Call into services layer to init bus-ops */
110 	status = h1394_init(&hci1394_modlinkage);
111 	if (status != 0) {
112 		return (status);
113 	}
114 
115 	status = mod_install(&hci1394_modlinkage);
116 	if (status != 0) {
117 		ddi_soft_state_fini(&hci1394_statep);
118 		return (status);
119 	}
120 
121 	return (status);
122 }
123 
124 
125 int
_info(struct modinfo * modinfop)126 _info(struct modinfo *modinfop)
127 {
128 	int status;
129 
130 	status = mod_info(&hci1394_modlinkage, modinfop);
131 
132 	return (status);
133 }
134 
135 
136 int
_fini()137 _fini()
138 {
139 	int status;
140 
141 	status = mod_remove(&hci1394_modlinkage);
142 	if (status != 0) {
143 		return (status);
144 	}
145 
146 	/* Call into services layer notify about _fini */
147 	h1394_fini(&hci1394_modlinkage);
148 	ddi_soft_state_fini(&hci1394_statep);
149 
150 	return (status);
151 }
152