1 /* $FreeBSD: src/sys/dev/stg/tmc18c30_isa.c,v 1.2.2.4 2001/09/04 04:45:23 non Exp $ */
2 /* $DragonFly: src/sys/dev/disk/stg/tmc18c30_isa.c,v 1.5 2004/02/12 00:00:18 dillon Exp $ */
3 /* $NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $ */
9 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
10 * All rights reserved.
11 * [NetBSD for NEC PC-98 series]
12 * Copyright (c) 1996, 1997, 1998
13 * NetBSD/pc98 porting staff. All rights reserved.
14 * Copyright (c) 1996, 1997, 1998
15 * Naofumi HONDA. All rights reserved.
16 * Copyright (c) 1996, 1997, 1998
17 * Kouichi Matsuda. All rights reserved.
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
22 * 1. Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
27 * 3. The name of the author may not be used to endorse or promote products
28 * derived from this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
31 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
34 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
39 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/module.h>
48 #include <sys/disklabel.h>
50 #include <sys/queue.h>
51 #include <sys/malloc.h>
52 #include <sys/errno.h>
56 #include <machine/bus_pio.h>
57 #include <machine/bus.h>
58 #include <machine/resource.h>
61 #include <bus/isa/isavar.h>
63 #include <machine/dvcfg.h>
65 #include <sys/device_port.h>
67 #include <bus/cam/scsi/scsi_low.h>
68 #include <bus/isa/isa_common.h>
69 #include <bus/cam/scsi/scsi_low_pisa.h>
71 #include "tmc18c30reg.h"
72 #include "tmc18c30var.h"
76 #include <sys/kernel.h>
77 #include <sys/module.h>
79 static int stgprobe(device_t devi);
80 static int stgattach(device_t devi);
82 static void stg_isa_unload (device_t);
85 stg_isa_intr(void * arg)
91 stg_release_resource(device_t dev)
93 struct stg_softc *sc = device_get_softc(dev);
95 if (sc->stg_intrhand) {
96 bus_teardown_intr(dev, sc->irq_res, sc->stg_intrhand);
100 bus_release_resource(dev, SYS_RES_IOPORT,
101 sc->port_rid, sc->port_res);
105 bus_release_resource(dev, SYS_RES_IRQ,
106 sc->irq_rid, sc->irq_res);
110 bus_release_resource(dev, SYS_RES_MEMORY,
111 sc->mem_rid, sc->mem_res);
116 stg_alloc_resource(device_t dev)
118 struct stg_softc *sc = device_get_softc(dev);
123 sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
124 0, ~0, STGIOSZ, RF_ACTIVE);
125 if (sc->port_res == NULL) {
126 stg_release_resource(dev);
131 sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
132 0, ~0, 1, RF_ACTIVE);
133 if (sc->irq_res == NULL) {
134 stg_release_resource(dev);
138 error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize);
143 /* no need to allocate memory if not configured */
144 if (maddr == 0 || msize == 0) {
149 sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid,
150 0, ~0, 1, RF_ACTIVE);
151 if (sc->mem_res == NULL) {
152 stg_release_resource(dev);
160 stg_isa_probe(device_t dev)
162 struct stg_softc *sc = device_get_softc(dev);
165 bzero(sc, sizeof(struct stg_softc));
167 error = stg_alloc_resource(dev);
172 if (stgprobe(dev) == 0) {
173 stg_release_resource(dev);
177 stg_release_resource(dev);
183 stg_isa_attach(device_t dev)
185 struct stg_softc *sc = device_get_softc(dev);
188 error = stg_alloc_resource(dev);
193 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM,
194 stg_isa_intr, (void *)sc, &sc->stg_intrhand);
196 stg_release_resource(dev);
200 if (stgattach(dev) == 0) {
201 stg_release_resource(dev);
209 stg_isa_detach(device_t dev)
212 stg_release_resource(dev);
215 static device_method_t stg_isa_methods[] = {
216 /* Device interface */
217 DEVMETHOD(device_probe, stg_isa_probe),
218 DEVMETHOD(device_attach, stg_isa_attach),
219 DEVMETHOD(device_detach, stg_isa_detach),
224 static driver_t stg_isa_driver = {
227 sizeof(struct stg_softc),
230 static devclass_t stg_devclass;
232 DRIVER_MODULE(stg, isa, stg_isa_driver, stg_devclass, 0, 0);
235 stg_isa_unload(device_t devi)
237 struct stg_softc *sc = device_get_softc(devi);
240 printf("%s: unload\n",sc->sc_sclow.sl_xname);
242 scsi_low_deactivate((struct scsi_low_softc *)sc);
243 scsi_low_dettach(&sc->sc_sclow);
248 stgprobe(device_t devi)
251 struct stg_softc *sc = device_get_softc(devi);
253 rv = stgprobesubr(rman_get_bustag(sc->port_res),
254 rman_get_bushandle(sc->port_res),
255 device_get_flags(devi));
261 stgattach(device_t devi)
263 struct stg_softc *sc;
264 struct scsi_low_softc *slp;
265 u_int32_t flags = device_get_flags(devi);
266 u_int iobase = bus_get_resource_start(devi, SYS_RES_IOPORT, 0);
270 strcpy(dvname,"stg");
275 printf("%s: no ioaddr is given\n", dvname);
279 sc = device_get_softc(devi);
286 sc->sc_iot = rman_get_bustag(sc->port_res);
287 sc->sc_ioh = rman_get_bushandle(sc->port_res);
289 slp->sl_hostid = STG_HOSTID;
290 slp->sl_cfgflags = flags;