1 /* $FreeBSD: src/sys/dev/stg/tmc18c30_isa.c,v 1.2.2.4 2001/09/04 04:45:23 non Exp $ */
2 /* $NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $ */
8 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
10 * [NetBSD for NEC PC-98 series]
11 * Copyright (c) 1996, 1997, 1998
12 * NetBSD/pc98 porting staff. All rights reserved.
13 * Copyright (c) 1996, 1997, 1998
14 * Naofumi HONDA. All rights reserved.
15 * Copyright (c) 1996, 1997, 1998
16 * Kouichi Matsuda. All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. The name of the author may not be used to endorse or promote products
27 * derived from this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
30 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
45 #include <sys/module.h>
47 #include <sys/disklabel.h>
48 #if defined(__FreeBSD__) && __FreeBSD_version >= 500001
52 #include <sys/queue.h>
53 #include <sys/malloc.h>
54 #include <sys/errno.h>
58 #include <machine/bus_pio.h>
59 #include <machine/bus.h>
60 #include <machine/resource.h>
63 #include <isa/isavar.h>
65 #include <machine/dvcfg.h>
67 #include <sys/device_port.h>
69 #include <cam/scsi/scsi_low.h>
70 #include <isa/isa_common.h>
71 #include <cam/scsi/scsi_low_pisa.h>
73 #include <dev/stg/tmc18c30reg.h>
74 #include <dev/stg/tmc18c30var.h>
78 #include <sys/kernel.h>
79 #include <sys/module.h>
81 static int stgprobe(device_t devi);
82 static int stgattach(device_t devi);
84 static void stg_isa_unload __P((device_t));
87 stg_isa_intr(void * arg)
93 stg_release_resource(device_t dev)
95 struct stg_softc *sc = device_get_softc(dev);
97 if (sc->stg_intrhand) {
98 bus_teardown_intr(dev, sc->irq_res, sc->stg_intrhand);
102 bus_release_resource(dev, SYS_RES_IOPORT,
103 sc->port_rid, sc->port_res);
107 bus_release_resource(dev, SYS_RES_IRQ,
108 sc->irq_rid, sc->irq_res);
112 bus_release_resource(dev, SYS_RES_MEMORY,
113 sc->mem_rid, sc->mem_res);
118 stg_alloc_resource(device_t dev)
120 struct stg_softc *sc = device_get_softc(dev);
125 sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
126 0, ~0, STGIOSZ, RF_ACTIVE);
127 if (sc->port_res == NULL) {
128 stg_release_resource(dev);
133 sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
134 0, ~0, 1, RF_ACTIVE);
135 if (sc->irq_res == NULL) {
136 stg_release_resource(dev);
140 error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize);
145 /* no need to allocate memory if not configured */
146 if (maddr == 0 || msize == 0) {
151 sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid,
152 0, ~0, 1, RF_ACTIVE);
153 if (sc->mem_res == NULL) {
154 stg_release_resource(dev);
162 stg_isa_probe(device_t dev)
164 struct stg_softc *sc = device_get_softc(dev);
167 bzero(sc, sizeof(struct stg_softc));
169 error = stg_alloc_resource(dev);
174 if (stgprobe(dev) == 0) {
175 stg_release_resource(dev);
179 stg_release_resource(dev);
185 stg_isa_attach(device_t dev)
187 struct stg_softc *sc = device_get_softc(dev);
190 error = stg_alloc_resource(dev);
195 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM,
196 stg_isa_intr, (void *)sc, &sc->stg_intrhand);
198 stg_release_resource(dev);
202 if (stgattach(dev) == 0) {
203 stg_release_resource(dev);
211 stg_isa_detach(device_t dev)
214 stg_release_resource(dev);
217 static device_method_t stg_isa_methods[] = {
218 /* Device interface */
219 DEVMETHOD(device_probe, stg_isa_probe),
220 DEVMETHOD(device_attach, stg_isa_attach),
221 DEVMETHOD(device_detach, stg_isa_detach),
226 static driver_t stg_isa_driver = {
229 sizeof(struct stg_softc),
232 static devclass_t stg_devclass;
234 DRIVER_MODULE(stg, isa, stg_isa_driver, stg_devclass, 0, 0);
237 stg_isa_unload(device_t devi)
239 struct stg_softc *sc = device_get_softc(devi);
242 printf("%s: unload\n",sc->sc_sclow.sl_xname);
244 scsi_low_deactivate((struct scsi_low_softc *)sc);
245 scsi_low_dettach(&sc->sc_sclow);
250 stgprobe(device_t devi)
253 struct stg_softc *sc = device_get_softc(devi);
255 rv = stgprobesubr(rman_get_bustag(sc->port_res),
256 rman_get_bushandle(sc->port_res),
257 device_get_flags(devi));
263 stgattach(device_t devi)
265 struct stg_softc *sc;
266 struct scsi_low_softc *slp;
267 u_int32_t flags = device_get_flags(devi);
268 u_int iobase = bus_get_resource_start(devi, SYS_RES_IOPORT, 0);
272 strcpy(dvname,"stg");
277 printf("%s: no ioaddr is given\n", dvname);
281 sc = device_get_softc(devi);
288 sc->sc_iot = rman_get_bustag(sc->port_res);
289 sc->sc_ioh = rman_get_bushandle(sc->port_res);
291 slp->sl_hostid = STG_HOSTID;
292 slp->sl_cfgflags = flags;