4 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
6 * [NetBSD for NEC PC-98 series]
7 * Copyright (c) 1996, 1997, 1998
8 * NetBSD/pc98 porting staff. All rights reserved.
9 * Copyright (c) 1996, 1997, 1998
10 * Naofumi HONDA. All rights reserved.
11 * Copyright (c) 1996, 1997, 1998
12 * Kouichi Matsuda. All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
45 #include <sys/socket.h>
47 #include <sys/module.h>
50 #include <machine/bus.h>
51 #include <machine/resource.h>
54 #include <cam/scsi/scsi_low.h>
56 #include <dev/stg/tmc18c30reg.h>
57 #include <dev/stg/tmc18c30var.h>
58 #include <dev/stg/tmc18c30.h>
62 devclass_t stg_devclass;
65 stg_alloc_resource(device_t dev)
67 struct stg_softc * sc = device_get_softc(dev);
71 sc->port_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
72 &sc->port_rid, RF_ACTIVE);
73 if (sc->port_res == NULL) {
74 stg_release_resource(dev);
78 sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
80 if (sc->irq_res == NULL) {
81 stg_release_resource(dev);
84 error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize);
89 /* no need to allocate memory if not configured */
90 if (maddr == 0 || msize == 0) {
94 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid,
96 if (sc->mem_res == NULL) {
97 stg_release_resource(dev);
105 stg_release_resource(device_t dev)
107 struct stg_softc *sc = device_get_softc(dev);
109 if (sc->stg_intrhand)
110 bus_teardown_intr(dev, sc->irq_res, sc->stg_intrhand);
112 bus_release_resource(dev, SYS_RES_IOPORT,
113 sc->port_rid, sc->port_res);
115 bus_release_resource(dev, SYS_RES_IRQ,
116 sc->irq_rid, sc->irq_res);
118 bus_release_resource(dev, SYS_RES_MEMORY,
119 sc->mem_rid, sc->mem_res);
124 stg_probe(device_t dev)
127 struct stg_softc *sc = device_get_softc(dev);
129 rv = stgprobesubr(rman_get_bustag(sc->port_res),
130 rman_get_bushandle(sc->port_res),
131 device_get_flags(dev));
137 stg_attach(device_t dev)
139 struct stg_softc *sc;
140 struct scsi_low_softc *slp;
141 u_int32_t flags = device_get_flags(dev);
145 sc = device_get_softc(dev);
147 strcpy(dvname,"stg");
151 sc->sc_iot = rman_get_bustag(sc->port_res);
152 sc->sc_ioh = rman_get_bushandle(sc->port_res);
154 slp->sl_hostid = STG_HOSTID;
155 slp->sl_cfgflags = flags;
165 stg_detach (device_t dev)
167 struct stg_softc *sc = device_get_softc(dev);
171 scsi_low_deactivate((struct scsi_low_softc *)sc);
172 scsi_low_dettach(&sc->sc_sclow);
174 stg_release_resource(dev);