Deleted Added
full compact
tmc18c30_isa.c (103693) tmc18c30_isa.c (113205)
1/* $FreeBSD: head/sys/dev/stg/tmc18c30_isa.c 103693 2002-09-20 16:53:19Z phk $ */
1/* $FreeBSD: head/sys/dev/stg/tmc18c30_isa.c 113205 2003-04-07 10:13:25Z mdodd $ */
2/* $NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $ */
3/* $NetBSD$ */
4
5/*
6 * [Ported for FreeBSD]
7 * Copyright (c) 2000
8 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
9 * All rights reserved.

--- 37 unchanged lines hidden (view full) ---

47#include <sys/malloc.h>
48#include <sys/errno.h>
49
50#include <machine/bus_pio.h>
51#include <machine/bus.h>
52#include <machine/resource.h>
53#include <sys/rman.h>
54
2/* $NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $ */
3/* $NetBSD$ */
4
5/*
6 * [Ported for FreeBSD]
7 * Copyright (c) 2000
8 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
9 * All rights reserved.

--- 37 unchanged lines hidden (view full) ---

47#include <sys/malloc.h>
48#include <sys/errno.h>
49
50#include <machine/bus_pio.h>
51#include <machine/bus.h>
52#include <machine/resource.h>
53#include <sys/rman.h>
54
55#include <isa/isavar.h>
56
57#include <machine/dvcfg.h>
58
59#include <sys/device_port.h>
60
61#include <cam/scsi/scsi_low.h>
55#include <cam/scsi/scsi_low.h>
62#include <isa/isa_common.h>
63#include <cam/scsi/scsi_low_pisa.h>
64
65#include <dev/stg/tmc18c30reg.h>
66#include <dev/stg/tmc18c30var.h>
56#include <cam/scsi/scsi_low_pisa.h>
57
58#include <dev/stg/tmc18c30reg.h>
59#include <dev/stg/tmc18c30var.h>
60#include <dev/stg/tmc18c30.h>
67
61
68#define STG_HOSTID 7
69
70#include <sys/kernel.h>
71#include <sys/module.h>
72
73static int stgprobe(device_t devi);
74static int stgattach(device_t devi);
75
76static void stg_isa_unload (device_t);
77
78static void
79stg_isa_intr(void * arg)
80{
81 stgintr(arg);
82}
83
84static void
85stg_release_resource(device_t dev)
86{
87 struct stg_softc *sc = device_get_softc(dev);
88
89 if (sc->stg_intrhand) {
90 bus_teardown_intr(dev, sc->irq_res, sc->stg_intrhand);
91 }
92
93 if (sc->port_res) {
94 bus_release_resource(dev, SYS_RES_IOPORT,
95 sc->port_rid, sc->port_res);
96 }
97
98 if (sc->irq_res) {
99 bus_release_resource(dev, SYS_RES_IRQ,
100 sc->irq_rid, sc->irq_res);
101 }
102
103 if (sc->mem_res) {
104 bus_release_resource(dev, SYS_RES_MEMORY,
105 sc->mem_rid, sc->mem_res);
106 }
107}
108
109static int
62static int
110stg_alloc_resource(device_t dev)
63stg_isa_probe(device_t dev)
111{
112 struct stg_softc *sc = device_get_softc(dev);
64{
65 struct stg_softc *sc = device_get_softc(dev);
113 u_long maddr, msize;
114 int error;
115
116 sc->port_rid = 0;
66 int error;
67
68 sc->port_rid = 0;
117 sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
118 0, ~0, STGIOSZ, RF_ACTIVE);
119 if (sc->port_res == NULL) {
120 stg_release_resource(dev);
121 return(ENOMEM);
122 }
123
124 sc->irq_rid = 0;
69 sc->irq_rid = 0;
125 sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
126 0, ~0, 1, RF_ACTIVE);
127 if (sc->irq_res == NULL) {
128 stg_release_resource(dev);
129 return(ENOMEM);
130 }
131
132 error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize);
133 if (error) {
134 return(0); /* XXX */
135 }
136
137 /* no need to allocate memory if not configured */
138 if (maddr == 0 || msize == 0) {
139 return(0);
140 }
141
142 sc->mem_rid = 0;
143 sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid,
144 0, ~0, 1, RF_ACTIVE);
145 if (sc->mem_res == NULL) {
146 stg_release_resource(dev);
147 return(ENOMEM);
148 }
149
150 return(0);
151}
152
153static int
154stg_isa_probe(device_t dev)
155{
156 struct stg_softc *sc = device_get_softc(dev);
157 int error;
158
159 bzero(sc, sizeof(struct stg_softc));
160
161 error = stg_alloc_resource(dev);
162 if (error) {
163 return(error);
164 }
165
70 error = stg_alloc_resource(dev);
71 if (error) {
72 return(error);
73 }
74
166 if (stgprobe(dev) == 0) {
75 if (stg_probe(dev) == 0) {
167 stg_release_resource(dev);
168 return(ENXIO);
169 }
170
171 stg_release_resource(dev);
172
173 return(0);
174}
175
176static int
177stg_isa_attach(device_t dev)
178{
179 struct stg_softc *sc = device_get_softc(dev);
180 int error;
181
76 stg_release_resource(dev);
77 return(ENXIO);
78 }
79
80 stg_release_resource(dev);
81
82 return(0);
83}
84
85static int
86stg_isa_attach(device_t dev)
87{
88 struct stg_softc *sc = device_get_softc(dev);
89 int error;
90
91 sc->port_rid = 0;
92 sc->irq_rid = 0;
182 error = stg_alloc_resource(dev);
183 if (error) {
184 return(error);
185 }
186
187 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY,
93 error = stg_alloc_resource(dev);
94 if (error) {
95 return(error);
96 }
97
98 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY,
188 stg_isa_intr, (void *)sc, &sc->stg_intrhand);
99 stg_intr, (void *)sc, &sc->stg_intrhand);
189 if (error) {
190 stg_release_resource(dev);
191 return(error);
192 }
193
100 if (error) {
101 stg_release_resource(dev);
102 return(error);
103 }
104
194 if (stgattach(dev) == 0) {
105 if (stg_attach(dev) == 0) {
195 stg_release_resource(dev);
196 return(ENXIO);
197 }
198
199 return(0);
200}
201
106 stg_release_resource(dev);
107 return(ENXIO);
108 }
109
110 return(0);
111}
112
202static void
203stg_isa_detach(device_t dev)
204{
205 stg_isa_unload(dev);
206 stg_release_resource(dev);
207}
208
209static device_method_t stg_isa_methods[] = {
210 /* Device interface */
211 DEVMETHOD(device_probe, stg_isa_probe),
212 DEVMETHOD(device_attach, stg_isa_attach),
113static device_method_t stg_isa_methods[] = {
114 /* Device interface */
115 DEVMETHOD(device_probe, stg_isa_probe),
116 DEVMETHOD(device_attach, stg_isa_attach),
213 DEVMETHOD(device_detach, stg_isa_detach),
117 DEVMETHOD(device_detach, stg_detach),
214
215 { 0, 0 }
216};
217
218static driver_t stg_isa_driver = {
219 "stg",
220 stg_isa_methods,
221 sizeof(struct stg_softc),
222};
223
118
119 { 0, 0 }
120};
121
122static driver_t stg_isa_driver = {
123 "stg",
124 stg_isa_methods,
125 sizeof(struct stg_softc),
126};
127
224static devclass_t stg_devclass;
225
226DRIVER_MODULE(stg, isa, stg_isa_driver, stg_devclass, 0, 0);
128DRIVER_MODULE(stg, isa, stg_isa_driver, stg_devclass, 0, 0);
227
228static void
229stg_isa_unload(device_t devi)
230{
231 struct stg_softc *sc = device_get_softc(devi);
232 intrmask_t s;
233
234 printf("%s: unload\n",sc->sc_sclow.sl_xname);
235 s = splcam();
236 scsi_low_deactivate((struct scsi_low_softc *)sc);
237 scsi_low_dettach(&sc->sc_sclow);
238 splx(s);
239}
240
241static int
242stgprobe(device_t devi)
243{
244 int rv;
245 struct stg_softc *sc = device_get_softc(devi);
246
247 rv = stgprobesubr(rman_get_bustag(sc->port_res),
248 rman_get_bushandle(sc->port_res),
249 device_get_flags(devi));
250
251 return rv;
252}
253
254static int
255stgattach(device_t devi)
256{
257 struct stg_softc *sc;
258 struct scsi_low_softc *slp;
259 u_int32_t flags = device_get_flags(devi);
260 u_int iobase = bus_get_resource_start(devi, SYS_RES_IOPORT, 0);
261 intrmask_t s;
262 char dvname[16];
263
264 strcpy(dvname,"stg");
265
266
267 if (iobase == 0)
268 {
269 printf("%s: no ioaddr is given\n", dvname);
270 return (0);
271 }
272
273 sc = device_get_softc(devi);
274 if (sc == NULL) {
275 return(0);
276 }
277
278 slp = &sc->sc_sclow;
279 slp->sl_dev = devi;
280 sc->sc_iot = rman_get_bustag(sc->port_res);
281 sc->sc_ioh = rman_get_bushandle(sc->port_res);
282
283 slp->sl_hostid = STG_HOSTID;
284 slp->sl_cfgflags = flags;
285
286 s = splcam();
287 stgattachsubr(sc);
288 splx(s);
289
290 return(STGIOSZ);
291}
129MODULE_DEPEND(stg, scsi_low, 1, 1, 1);