dpt_isa.c (104710) | dpt_isa.c (112780) |
---|---|
1/*- 2 * Copyright (c) 2000 Matthew N. Dodd <winter@jurai.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 2000 Matthew N. Dodd <winter@jurai.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/dev/dpt/dpt_isa.c 104710 2002-10-09 08:54:32Z peter $ | 26 * $FreeBSD: head/sys/dev/dpt/dpt_isa.c 112780 2003-03-29 08:30:45Z mdodd $ |
27 */ 28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/kernel.h> 32#include <sys/module.h> 33#include <sys/bus.h> 34 35#include <machine/bus_pio.h> 36#include <machine/bus.h> 37#include <machine/resource.h> 38#include <sys/rman.h> 39 40#include <isa/isavar.h> 41 42#include <cam/scsi/scsi_all.h> 43 44#include <dev/dpt/dpt.h> 45 | 27 */ 28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/kernel.h> 32#include <sys/module.h> 33#include <sys/bus.h> 34 35#include <machine/bus_pio.h> 36#include <machine/bus.h> 37#include <machine/resource.h> 38#include <sys/rman.h> 39 40#include <isa/isavar.h> 41 42#include <cam/scsi/scsi_all.h> 43 44#include <dev/dpt/dpt.h> 45 |
46static void dpt_isa_identify (driver_t *, device_t); |
|
46static int dpt_isa_probe (device_t); 47static int dpt_isa_attach (device_t); | 47static int dpt_isa_probe (device_t); 48static int dpt_isa_attach (device_t); |
49static int dpt_isa_detach (device_t); |
|
48 | 50 |
51static int dpt_isa_valid_irq (int); 52static int dpt_isa_valid_ioport (int); 53 |
|
49static int | 54static int |
55dpt_isa_valid_irq (int irq) 56{ 57 switch (irq) { 58 case 11: 59 case 12: 60 case 14: 61 case 15: 62 return (0); 63 default: 64 return (1); 65 }; 66 return (1); 67} 68 69static int 70dpt_isa_valid_ioport (int ioport) 71{ 72 switch (ioport) { 73 case 0x170: 74 case 0x1f0: 75 case 0x230: 76 case 0x330: 77 return (0); 78 default: 79 return (1); 80 }; 81 return (1); 82} 83 84static void 85dpt_isa_identify (driver_t *driver, device_t parent) 86{ 87 device_t child; 88 dpt_conf_t * conf; 89 int isa_bases[] = { 0x1f0, 0x170, 0x330, 0x230, 0 }; 90 int i; 91 92 for (i = 0; isa_bases[i]; i++) { 93 conf = dpt_pio_get_conf(isa_bases[i]); 94 if (!conf) { 95 if (bootverbose) 96 device_printf(parent, "dpt: dpt_pio_get_conf(%x) failed.\n", 97 isa_bases[i]); 98 continue; 99 } 100 101 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "dpt", -1); 102 if (child == 0) { 103 device_printf(parent, "dpt: BUS_ADD_CHILD() failed!\n"); 104 continue; 105 } 106 device_set_driver(child, driver); 107 bus_set_resource(child, SYS_RES_IOPORT, 0, isa_bases[i], 0x9); 108 } 109 return; 110} 111 112static int |
|
50dpt_isa_probe (device_t dev) 51{ 52 dpt_conf_t * conf; 53 u_int32_t io_base; 54 55 /* No pnp support */ 56 if (isa_get_vendorid(dev)) 57 return (ENXIO); 58 59 if ((io_base = bus_get_resource_start(dev, SYS_RES_IOPORT, 0)) == 0) 60 return (ENXIO); 61 | 113dpt_isa_probe (device_t dev) 114{ 115 dpt_conf_t * conf; 116 u_int32_t io_base; 117 118 /* No pnp support */ 119 if (isa_get_vendorid(dev)) 120 return (ENXIO); 121 122 if ((io_base = bus_get_resource_start(dev, SYS_RES_IOPORT, 0)) == 0) 123 return (ENXIO); 124 |
125 if (dpt_isa_valid_ioport(io_base)) 126 ; 127 |
|
62 conf = dpt_pio_get_conf(io_base); | 128 conf = dpt_pio_get_conf(io_base); |
63 if (!conf) { 64 printf("dpt: dpt_pio_get_conf() failed.\n"); 65 return (ENXIO); 66 } | 129 if (!conf) { 130 printf("dpt: dpt_pio_get_conf() failed.\n"); 131 return (ENXIO); 132 } |
67 | 133 |
134 if (dpt_isa_valid_irq(conf->IRQ)) 135 ; 136 |
|
68 device_set_desc(dev, "ISA DPT SCSI controller"); 69 bus_set_resource(dev, SYS_RES_IRQ, 0, conf->IRQ, 1); 70 bus_set_resource(dev, SYS_RES_DRQ, 0, ((8 - conf->DMA_channel) & 7), 1); 71 72 return 0; 73} 74 75static int 76dpt_isa_attach (device_t dev) 77{ | 137 device_set_desc(dev, "ISA DPT SCSI controller"); 138 bus_set_resource(dev, SYS_RES_IRQ, 0, conf->IRQ, 1); 139 bus_set_resource(dev, SYS_RES_DRQ, 0, ((8 - conf->DMA_channel) & 7), 1); 140 141 return 0; 142} 143 144static int 145dpt_isa_attach (device_t dev) 146{ |
78 dpt_softc_t * dpt = NULL; 79 struct resource *io = 0; 80 struct resource *irq = 0; 81 struct resource *drq = 0; | 147 dpt_softc_t * dpt; |
82 int s; | 148 int s; |
83 int rid; 84 void * ih; | |
85 int error = 0; 86 | 149 int error = 0; 150 |
87 rid = 0; 88 io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE); 89 if (!io) { 90 device_printf(dev, "No I/O space?!\n"); 91 error = ENOMEM; 92 goto bad; 93 } | 151 dpt = device_get_softc(dev); |
94 | 152 |
95 rid = 0; 96 irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE); 97 if (!irq) { 98 device_printf(dev, "No IRQ!\n"); 99 error = ENOMEM; | 153 154 dpt->io_rid = 0; 155 dpt->io_type = SYS_RES_IOPORT; 156 dpt->irq_rid = 0; 157 158 error = dpt_alloc_resources(dev); 159 if (error) { |
100 goto bad; 101 } 102 | 160 goto bad; 161 } 162 |
103 rid = 0; 104 drq = bus_alloc_resource(dev, SYS_RES_DRQ, &rid, 0, ~0, 1, RF_ACTIVE); 105 if (!drq) { 106 device_printf(dev, "No DRQ?!\n"); | 163 dpt->drq_rid = 0; 164 dpt->drq_res = bus_alloc_resource(dev, SYS_RES_DRQ, &dpt->drq_rid, 165 0, ~0, 1, RF_ACTIVE); 166 if (!dpt->drq_res) { 167 device_printf(dev, "No DRQ!\n"); |
107 error = ENOMEM; 108 goto bad; 109 } | 168 error = ENOMEM; 169 goto bad; 170 } |
171 isa_dma_acquire(rman_get_start(dpt->drq_res)); 172 isa_dmacascade(rman_get_start(dpt->drq_res)); |
|
110 | 173 |
111 dpt = dpt_alloc(dev, rman_get_bustag(io), rman_get_bushandle(io)); 112 if (dpt == NULL) { 113 error = ENXIO; 114 goto bad; 115 } | 174 dpt_alloc(dev); |
116 | 175 |
117 isa_dmacascade(rman_get_start(drq)); 118 | |
119 /* Allocate a dmatag representing the capabilities of this attachment */ 120 if (bus_dma_tag_create( /* parent */ NULL, 121 /* alignemnt */ 1, 122 /* boundary */ 0, | 176 /* Allocate a dmatag representing the capabilities of this attachment */ 177 if (bus_dma_tag_create( /* parent */ NULL, 178 /* alignemnt */ 1, 179 /* boundary */ 0, |
123 /* lowaddr */ BUS_SPACE_MAXADDR_24BIT, | 180 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT, |
124 /* highaddr */ BUS_SPACE_MAXADDR, 125 /* filter */ NULL, 126 /* filterarg */ NULL, 127 /* maxsize */ BUS_SPACE_MAXSIZE_32BIT, 128 /* nsegments */ ~0, 129 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT, 130 /* flags */ 0, 131 &dpt->parent_dmat) != 0) { --- 9 unchanged lines hidden (view full) --- 141 goto bad; 142 } 143 144 /* Register with the XPT */ 145 dpt_attach(dpt); 146 147 splx(s); 148 | 181 /* highaddr */ BUS_SPACE_MAXADDR, 182 /* filter */ NULL, 183 /* filterarg */ NULL, 184 /* maxsize */ BUS_SPACE_MAXSIZE_32BIT, 185 /* nsegments */ ~0, 186 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT, 187 /* flags */ 0, 188 &dpt->parent_dmat) != 0) { --- 9 unchanged lines hidden (view full) --- 198 goto bad; 199 } 200 201 /* Register with the XPT */ 202 dpt_attach(dpt); 203 204 splx(s); 205 |
149 if (bus_setup_intr(dev, irq, INTR_TYPE_CAM | INTR_ENTROPY, dpt_intr, 150 dpt, &ih)) { | 206 if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY, 207 dpt_intr, dpt, &dpt->ih)) { |
151 device_printf(dev, "Unable to register interrupt handler\n"); 152 error = ENXIO; 153 goto bad; 154 } 155 156 return (error); 157 158 bad: | 208 device_printf(dev, "Unable to register interrupt handler\n"); 209 error = ENXIO; 210 goto bad; 211 } 212 213 return (error); 214 215 bad: |
216 if (dpt->drq_res) { 217 isa_dma_release(rman_get_start(dpt->drq_res)); 218 } 219 220 dpt_release_resources(dev); 221 |
|
159 if (dpt) 160 dpt_free(dpt); | 222 if (dpt) 223 dpt_free(dpt); |
161 if (io) 162 bus_release_resource(dev, SYS_RES_IOPORT, 0, io); 163 if (irq) 164 bus_release_resource(dev, SYS_RES_IRQ, 0, irq); 165 if (drq) 166 bus_release_resource(dev, SYS_RES_DRQ, 0, drq); | |
167 168 return (error); 169} 170 | 224 225 return (error); 226} 227 |
228static int 229dpt_isa_detach (device_t dev) 230{ 231 dpt_softc_t * dpt; 232 int dma; 233 int error; 234 235 dpt = device_get_softc(dev); 236 237 dma = rman_get_start(dpt->drq_res); 238 error = dpt_detach(dev); 239 isa_dma_release(dma); 240 241 return (error); 242} 243 244 |
|
171static device_method_t dpt_isa_methods[] = { 172 /* Device interface */ | 245static device_method_t dpt_isa_methods[] = { 246 /* Device interface */ |
247#ifdef notyet 248 DEVMETHOD(device_identify, dpt_isa_identify), 249#endif |
|
173 DEVMETHOD(device_probe, dpt_isa_probe), 174 DEVMETHOD(device_attach, dpt_isa_attach), | 250 DEVMETHOD(device_probe, dpt_isa_probe), 251 DEVMETHOD(device_attach, dpt_isa_attach), |
252 DEVMETHOD(device_detach, dpt_isa_detach), |
|
175 176 { 0, 0 } 177}; 178 179static driver_t dpt_isa_driver = { 180 "dpt", 181 dpt_isa_methods, 182 sizeof(dpt_softc_t), 183}; 184 | 253 254 { 0, 0 } 255}; 256 257static driver_t dpt_isa_driver = { 258 "dpt", 259 dpt_isa_methods, 260 sizeof(dpt_softc_t), 261}; 262 |
185static devclass_t dpt_devclass; 186 | |
187DRIVER_MODULE(dpt, isa, dpt_isa_driver, dpt_devclass, 0, 0); | 263DRIVER_MODULE(dpt, isa, dpt_isa_driver, dpt_devclass, 0, 0); |