9 #include <sys/kernel.h>
10 #include <sys/module.h>
12 #include <sys/fcntl.h>
18 #include <sys/mutex.h>
20 #include <machine/bus.h>
21 #include <machine/resource.h>
24 #include <isa/isavar.h>
26 #include <dev/mcd/mcdreg.h>
27 #include <dev/mcd/mcdvar.h>
29 static int mcd_isa_probe (device_t);
30 static int mcd_isa_attach (device_t);
31 static int mcd_isa_detach (device_t);
33 static int mcd_alloc_resources (device_t);
34 static void mcd_release_resources (device_t);
37 mcd_isa_probe (device_t dev)
39 struct mcd_softc * sc;
43 if (isa_get_vendorid(dev))
46 /* IO port must be configured. */
47 if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0)
50 sc = device_get_softc(dev);
53 sc->port_type = SYS_RES_IOPORT;
54 error = mcd_alloc_resources(dev);
58 error = mcd_probe(sc);
60 device_printf(dev, "Probe failed.\n");
64 device_set_desc(dev, sc->data.name);
67 mcd_release_resources(dev);
72 mcd_isa_attach (device_t dev)
74 struct mcd_softc * sc;
77 sc = device_get_softc(dev);
82 sc->port_type = SYS_RES_IOPORT;
83 error = mcd_alloc_resources(dev);
87 error = mcd_probe(sc);
89 device_printf(dev, "Re-Probe failed.\n");
93 error = mcd_attach(sc);
95 device_printf(dev, "Attach failed.\n");
101 mcd_release_resources(dev);
106 mcd_isa_detach (device_t dev)
108 struct mcd_softc * sc;
111 sc = device_get_softc(dev);
114 destroy_dev(sc->mcd_dev_t);
116 mcd_release_resources(dev);
122 mcd_alloc_resources (device_t dev)
124 struct mcd_softc * sc;
127 sc = device_get_softc(dev);
131 sc->port = bus_alloc_resource_any(dev, sc->port_type,
132 &sc->port_rid, RF_ACTIVE);
133 if (sc->port == NULL) {
134 device_printf(dev, "Unable to allocate PORT resource.\n");
138 sc->port_bst = rman_get_bustag(sc->port);
139 sc->port_bsh = rman_get_bushandle(sc->port);
143 sc->irq = bus_alloc_resource_any(dev, sc->irq_type,
144 &sc->irq_rid, RF_ACTIVE);
145 if (sc->irq == NULL) {
146 device_printf(dev, "Unable to allocate IRQ resource.\n");
153 sc->drq = bus_alloc_resource_any(dev, sc->drq_type,
154 &sc->drq_rid, RF_ACTIVE);
155 if (sc->drq == NULL) {
156 device_printf(dev, "Unable to allocate DRQ resource.\n");
162 mtx_init(&sc->mtx, device_get_nameunit(dev),
163 "Interrupt lock", MTX_DEF | MTX_RECURSE);
170 mcd_release_resources (device_t dev)
172 struct mcd_softc * sc;
174 sc = device_get_softc(dev);
177 bus_teardown_intr(dev, sc->irq, sc->irq_ih);
179 bus_release_resource(dev, sc->port_type, sc->port_rid, sc->port);
184 bus_release_resource(dev, sc->irq_type, sc->irq_rid, sc->irq);
186 bus_release_resource(dev, sc->drq_type, sc->drq_rid, sc->drq);
188 if (mtx_initialized(&sc->mtx) != 0)
189 mtx_destroy(&sc->mtx);
194 static device_method_t mcd_isa_methods[] = {
195 DEVMETHOD(device_probe, mcd_isa_probe),
196 DEVMETHOD(device_attach, mcd_isa_attach),
197 DEVMETHOD(device_detach, mcd_isa_detach),
202 static driver_t mcd_isa_driver = {
205 sizeof(struct mcd_softc)
208 static devclass_t mcd_devclass;
210 DRIVER_MODULE(mcd, isa, mcd_isa_driver, mcd_devclass, NULL, 0);