Deleted Added
full compact
mcd_isa.c (104445) mcd_isa.c (104519)
1/*
1/*
2 * $FreeBSD: head/sys/dev/mcd/mcd_isa.c 104445 2002-10-04 07:14:19Z mdodd $
2 * $FreeBSD: head/sys/dev/mcd/mcd_isa.c 104519 2002-10-05 16:35:33Z phk $
3 */
4
3 */
4
5#include "opt_geom.h"
6#ifdef NO_GEOM
7
5#include <sys/param.h>
6#include <sys/systm.h>
7#include <sys/kernel.h>
8#include <sys/module.h>
9#include <sys/conf.h>
10#include <sys/fcntl.h>
11#include <sys/bio.h>
12#include <sys/cdio.h>
13#include <sys/disklabel.h>
14#include <sys/bus.h>
15
16#include <sys/mutex.h>
17
18#include <machine/bus_pio.h>
19#include <machine/bus.h>
20#include <machine/resource.h>
21#include <sys/rman.h>
22
23#include <isa/isavar.h>
24
25#include <dev/mcd/mcdreg.h>
26#include <dev/mcd/mcdvar.h>
27
28static int mcd_isa_probe (device_t);
29static int mcd_isa_attach (device_t);
30static int mcd_isa_detach (device_t);
31
32static int mcd_alloc_resources (device_t);
33static void mcd_release_resources (device_t);
34
35static int
36mcd_isa_probe (device_t dev)
37{
38 struct mcd_softc * sc;
39 int error;
40
41 /* No pnp support */
42 if (isa_get_vendorid(dev))
43 return (ENXIO);
44
45 /* IO port must be configured. */
46 if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0)
47 return (ENXIO);
48
49 sc = device_get_softc(dev);
50 sc->dev = dev;
51 sc->port_rid = 0;
52 sc->port_type = SYS_RES_IOPORT;
53 error = mcd_alloc_resources(dev);
54 if (error)
55 goto fail;
56
57 error = mcd_probe(sc);
58 if (error) {
59 device_printf(dev, "Probe failed.\n");
60 goto fail;
61 }
62
63 device_set_desc(dev, sc->data.name);
64
65fail:
66 mcd_release_resources(dev);
67 return (error);
68}
69
70static int
71mcd_isa_attach (device_t dev)
72{
73 struct mcd_softc * sc;
74 int error;
75
76 sc = device_get_softc(dev);
77 error = 0;
78
79 sc->dev = dev;
80 sc->port_rid = 0;
81 sc->port_type = SYS_RES_IOPORT;
82 error = mcd_alloc_resources(dev);
83 if (error)
84 goto fail;
85
86 error = mcd_probe(sc);
87 if (error) {
88 device_printf(dev, "Re-Probe failed.\n");
89 goto fail;
90 }
91
92 error = mcd_attach(sc);
93 if (error) {
94 device_printf(dev, "Attach failed.\n");
95 goto fail;
96 }
97
98 return (0);
99fail:
100 mcd_release_resources(dev);
101 return (error);
102}
103
104static int
105mcd_isa_detach (device_t dev)
106{
107 struct mcd_softc * sc;
108 int error;
109
110 sc = device_get_softc(dev);
111 error = 0;
112
113 destroy_dev(sc->mcd_dev_t[2]);
114 destroy_dev(sc->mcd_dev_t[1]);
115 destroy_dev(sc->mcd_dev_t[0]);
116
117 mcd_release_resources(dev);
118
119 return (error);
120}
121
122static int
123mcd_alloc_resources (device_t dev)
124{
125 struct mcd_softc * sc;
126 int error;
127
128 sc = device_get_softc(dev);
129 error = 0;
130
131 if (sc->port_type) {
132 sc->port = bus_alloc_resource(dev, sc->port_type, &sc->port_rid,
133 0, ~0, 1, RF_ACTIVE);
134 if (sc->port == NULL) {
135 device_printf(dev, "Unable to allocate PORT resource.\n");
136 error = ENOMEM;
137 goto bad;
138 }
139 sc->port_bst = rman_get_bustag(sc->port);
140 sc->port_bsh = rman_get_bushandle(sc->port);
141 }
142
143 if (sc->irq_type) {
144 sc->irq = bus_alloc_resource(dev, sc->irq_type, &sc->irq_rid,
145 0, ~0, 1, RF_ACTIVE);
146 if (sc->irq == NULL) {
147 device_printf(dev, "Unable to allocate IRQ resource.\n");
148 error = ENOMEM;
149 goto bad;
150 }
151 }
152
153 if (sc->drq_type) {
154 sc->drq = bus_alloc_resource(dev, sc->drq_type, &sc->drq_rid,
155 0, ~0, 1, RF_ACTIVE);
156 if (sc->drq == NULL) {
157 device_printf(dev, "Unable to allocate DRQ resource.\n");
158 error = ENOMEM;
159 goto bad;
160 }
161 }
162
163 mtx_init(&sc->mtx, device_get_nameunit(dev),
164 "Interrupt lock", MTX_DEF | MTX_RECURSE);
165
166bad:
167 return (error);
168}
169
170void
171mcd_release_resources (device_t dev)
172{
173 struct mcd_softc * sc;
174
175 sc = device_get_softc(dev);
176
177 if (sc->irq_ih)
178 bus_teardown_intr(dev, sc->irq, sc->irq_ih);
179 if (sc->port) {
180 bus_release_resource(dev, sc->port_type, sc->port_rid, sc->port);
181 sc->port_bst = 0;
182 sc->port_bsh = 0;
183 }
184 if (sc->irq)
185 bus_release_resource(dev, sc->irq_type, sc->irq_rid, sc->irq);
186 if (sc->drq)
187 bus_release_resource(dev, sc->drq_type, sc->drq_rid, sc->drq);
188
189 if (mtx_initialized(&sc->mtx) != 0)
190 mtx_destroy(&sc->mtx);
191
192 return;
193}
194
195static device_method_t mcd_isa_methods[] = {
196 DEVMETHOD(device_probe, mcd_isa_probe),
197 DEVMETHOD(device_attach, mcd_isa_attach),
198 DEVMETHOD(device_detach, mcd_isa_detach),
199
200 { 0, 0 }
201};
202
203static driver_t mcd_isa_driver = {
204 "mcd",
205 mcd_isa_methods,
206 sizeof(struct mcd_softc)
207};
208
209static devclass_t mcd_devclass;
210
211DRIVER_MODULE(mcd, isa, mcd_isa_driver, mcd_devclass, NULL, 0);
8#include <sys/param.h>
9#include <sys/systm.h>
10#include <sys/kernel.h>
11#include <sys/module.h>
12#include <sys/conf.h>
13#include <sys/fcntl.h>
14#include <sys/bio.h>
15#include <sys/cdio.h>
16#include <sys/disklabel.h>
17#include <sys/bus.h>
18
19#include <sys/mutex.h>
20
21#include <machine/bus_pio.h>
22#include <machine/bus.h>
23#include <machine/resource.h>
24#include <sys/rman.h>
25
26#include <isa/isavar.h>
27
28#include <dev/mcd/mcdreg.h>
29#include <dev/mcd/mcdvar.h>
30
31static int mcd_isa_probe (device_t);
32static int mcd_isa_attach (device_t);
33static int mcd_isa_detach (device_t);
34
35static int mcd_alloc_resources (device_t);
36static void mcd_release_resources (device_t);
37
38static int
39mcd_isa_probe (device_t dev)
40{
41 struct mcd_softc * sc;
42 int error;
43
44 /* No pnp support */
45 if (isa_get_vendorid(dev))
46 return (ENXIO);
47
48 /* IO port must be configured. */
49 if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0)
50 return (ENXIO);
51
52 sc = device_get_softc(dev);
53 sc->dev = dev;
54 sc->port_rid = 0;
55 sc->port_type = SYS_RES_IOPORT;
56 error = mcd_alloc_resources(dev);
57 if (error)
58 goto fail;
59
60 error = mcd_probe(sc);
61 if (error) {
62 device_printf(dev, "Probe failed.\n");
63 goto fail;
64 }
65
66 device_set_desc(dev, sc->data.name);
67
68fail:
69 mcd_release_resources(dev);
70 return (error);
71}
72
73static int
74mcd_isa_attach (device_t dev)
75{
76 struct mcd_softc * sc;
77 int error;
78
79 sc = device_get_softc(dev);
80 error = 0;
81
82 sc->dev = dev;
83 sc->port_rid = 0;
84 sc->port_type = SYS_RES_IOPORT;
85 error = mcd_alloc_resources(dev);
86 if (error)
87 goto fail;
88
89 error = mcd_probe(sc);
90 if (error) {
91 device_printf(dev, "Re-Probe failed.\n");
92 goto fail;
93 }
94
95 error = mcd_attach(sc);
96 if (error) {
97 device_printf(dev, "Attach failed.\n");
98 goto fail;
99 }
100
101 return (0);
102fail:
103 mcd_release_resources(dev);
104 return (error);
105}
106
107static int
108mcd_isa_detach (device_t dev)
109{
110 struct mcd_softc * sc;
111 int error;
112
113 sc = device_get_softc(dev);
114 error = 0;
115
116 destroy_dev(sc->mcd_dev_t[2]);
117 destroy_dev(sc->mcd_dev_t[1]);
118 destroy_dev(sc->mcd_dev_t[0]);
119
120 mcd_release_resources(dev);
121
122 return (error);
123}
124
125static int
126mcd_alloc_resources (device_t dev)
127{
128 struct mcd_softc * sc;
129 int error;
130
131 sc = device_get_softc(dev);
132 error = 0;
133
134 if (sc->port_type) {
135 sc->port = bus_alloc_resource(dev, sc->port_type, &sc->port_rid,
136 0, ~0, 1, RF_ACTIVE);
137 if (sc->port == NULL) {
138 device_printf(dev, "Unable to allocate PORT resource.\n");
139 error = ENOMEM;
140 goto bad;
141 }
142 sc->port_bst = rman_get_bustag(sc->port);
143 sc->port_bsh = rman_get_bushandle(sc->port);
144 }
145
146 if (sc->irq_type) {
147 sc->irq = bus_alloc_resource(dev, sc->irq_type, &sc->irq_rid,
148 0, ~0, 1, RF_ACTIVE);
149 if (sc->irq == NULL) {
150 device_printf(dev, "Unable to allocate IRQ resource.\n");
151 error = ENOMEM;
152 goto bad;
153 }
154 }
155
156 if (sc->drq_type) {
157 sc->drq = bus_alloc_resource(dev, sc->drq_type, &sc->drq_rid,
158 0, ~0, 1, RF_ACTIVE);
159 if (sc->drq == NULL) {
160 device_printf(dev, "Unable to allocate DRQ resource.\n");
161 error = ENOMEM;
162 goto bad;
163 }
164 }
165
166 mtx_init(&sc->mtx, device_get_nameunit(dev),
167 "Interrupt lock", MTX_DEF | MTX_RECURSE);
168
169bad:
170 return (error);
171}
172
173void
174mcd_release_resources (device_t dev)
175{
176 struct mcd_softc * sc;
177
178 sc = device_get_softc(dev);
179
180 if (sc->irq_ih)
181 bus_teardown_intr(dev, sc->irq, sc->irq_ih);
182 if (sc->port) {
183 bus_release_resource(dev, sc->port_type, sc->port_rid, sc->port);
184 sc->port_bst = 0;
185 sc->port_bsh = 0;
186 }
187 if (sc->irq)
188 bus_release_resource(dev, sc->irq_type, sc->irq_rid, sc->irq);
189 if (sc->drq)
190 bus_release_resource(dev, sc->drq_type, sc->drq_rid, sc->drq);
191
192 if (mtx_initialized(&sc->mtx) != 0)
193 mtx_destroy(&sc->mtx);
194
195 return;
196}
197
198static device_method_t mcd_isa_methods[] = {
199 DEVMETHOD(device_probe, mcd_isa_probe),
200 DEVMETHOD(device_attach, mcd_isa_attach),
201 DEVMETHOD(device_detach, mcd_isa_detach),
202
203 { 0, 0 }
204};
205
206static driver_t mcd_isa_driver = {
207 "mcd",
208 mcd_isa_methods,
209 sizeof(struct mcd_softc)
210};
211
212static devclass_t mcd_devclass;
213
214DRIVER_MODULE(mcd, isa, mcd_isa_driver, mcd_devclass, NULL, 0);
215
216#endif /* GEOM */