tmc18c30_pccard.c (107363) | tmc18c30_pccard.c (113205) |
---|---|
1/* $FreeBSD: head/sys/dev/stg/tmc18c30_pccard.c 107363 2002-11-28 01:15:01Z non $ */ | 1/* $FreeBSD: head/sys/dev/stg/tmc18c30_pccard.c 113205 2003-04-07 10:13:25Z mdodd $ */ |
2/* $NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $ */ 3/* $NetBSD$ */ 4 5/* 6 * [Ported for FreeBSD] 7 * Copyright (c) 2000 8 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe. 9 * All rights reserved. --- 43 unchanged lines hidden (view full) --- 53#include <dev/pccard/pccarddevs.h> 54#include <dev/pccard/pccardvar.h> 55 56#include <cam/scsi/scsi_low.h> 57#include <cam/scsi/scsi_low_pisa.h> 58 59#include <dev/stg/tmc18c30reg.h> 60#include <dev/stg/tmc18c30var.h> | 2/* $NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $ */ 3/* $NetBSD$ */ 4 5/* 6 * [Ported for FreeBSD] 7 * Copyright (c) 2000 8 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe. 9 * All rights reserved. --- 43 unchanged lines hidden (view full) --- 53#include <dev/pccard/pccarddevs.h> 54#include <dev/pccard/pccardvar.h> 55 56#include <cam/scsi/scsi_low.h> 57#include <cam/scsi/scsi_low_pisa.h> 58 59#include <dev/stg/tmc18c30reg.h> 60#include <dev/stg/tmc18c30var.h> |
61#include <dev/stg/tmc18c30.h> |
|
61 | 62 |
62#define STG_HOSTID 7 63 | |
64#include <sys/kernel.h> 65#include <sys/module.h> 66#if !defined(__FreeBSD__) || __FreeBSD_version < 500014 67#include <sys/select.h> 68#endif 69#include <pccard/cardinfo.h> 70#include <pccard/slot.h> 71 | 63#include <sys/kernel.h> 64#include <sys/module.h> 65#if !defined(__FreeBSD__) || __FreeBSD_version < 500014 66#include <sys/select.h> 67#endif 68#include <pccard/cardinfo.h> 69#include <pccard/slot.h> 70 |
72static int stgprobe(DEVPORT_PDEVICE devi); 73static int stgattach(DEVPORT_PDEVICE devi); 74 75static void stg_card_unload (DEVPORT_PDEVICE); 76 | |
77static const struct pccard_product stg_products[] = { 78 PCMCIA_CARD(FUTUREDOMAIN, SCSI2GO, 0), 79 PCMCIA_CARD(IBM, SCSICARD, 0), 80 PCMCIA_CARD(RATOC, REX5536, 0), 81 PCMCIA_CARD(RATOC, REX5536AM, 0), 82 PCMCIA_CARD(RATOC, REX5536M, 0), 83 { NULL } 84}; 85 86/* 87 * Additional code for FreeBSD new-bus PCCard frontend 88 */ 89 | 71static const struct pccard_product stg_products[] = { 72 PCMCIA_CARD(FUTUREDOMAIN, SCSI2GO, 0), 73 PCMCIA_CARD(IBM, SCSICARD, 0), 74 PCMCIA_CARD(RATOC, REX5536, 0), 75 PCMCIA_CARD(RATOC, REX5536AM, 0), 76 PCMCIA_CARD(RATOC, REX5536M, 0), 77 { NULL } 78}; 79 80/* 81 * Additional code for FreeBSD new-bus PCCard frontend 82 */ 83 |
90static void 91stg_pccard_intr(void * arg) 92{ 93 stgintr(arg); 94} 95 96static void 97stg_release_resource(DEVPORT_PDEVICE dev) 98{ 99 struct stg_softc *sc = device_get_softc(dev); 100 101 if (sc->stg_intrhand) { 102 bus_teardown_intr(dev, sc->irq_res, sc->stg_intrhand); 103 } 104 105 if (sc->port_res) { 106 bus_release_resource(dev, SYS_RES_IOPORT, 107 sc->port_rid, sc->port_res); 108 } 109 110 if (sc->irq_res) { 111 bus_release_resource(dev, SYS_RES_IRQ, 112 sc->irq_rid, sc->irq_res); 113 } 114 115 if (sc->mem_res) { 116 bus_release_resource(dev, SYS_RES_MEMORY, 117 sc->mem_rid, sc->mem_res); 118 } 119} 120 121static int 122stg_alloc_resource(DEVPORT_PDEVICE dev) 123{ 124 struct stg_softc *sc = device_get_softc(dev); 125 u_long ioaddr, iosize, maddr, msize; 126 int error; 127 128 error = bus_get_resource(dev, SYS_RES_IOPORT, 0, &ioaddr, &iosize); 129 if (error || iosize < STGIOSZ) { 130 return(ENOMEM); 131 } 132 133 sc->port_rid = 0; 134 sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid, 135 0, ~0, STGIOSZ, RF_ACTIVE); 136 if (sc->port_res == NULL) { 137 stg_release_resource(dev); 138 return(ENOMEM); 139 } 140 141 sc->irq_rid = 0; 142 sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid, 143 0, ~0, 1, RF_ACTIVE); 144 if (sc->irq_res == NULL) { 145 stg_release_resource(dev); 146 return(ENOMEM); 147 } 148 149 error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize); 150 if (error) { 151 return(0); /* XXX */ 152 } 153 154 /* no need to allocate memory if not configured */ 155 if (maddr == 0 || msize == 0) { 156 return(0); 157 } 158 159 sc->mem_rid = 0; 160 sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid, 161 0, ~0, 1, RF_ACTIVE); 162 if (sc->mem_res == NULL) { 163 stg_release_resource(dev); 164 return(ENOMEM); 165 } 166 167 return(0); 168} 169 | |
170static int stg_pccard_match(device_t dev) 171{ 172 const struct pccard_product *pp; 173 174 if ((pp = pccard_product_lookup(dev, stg_products, 175 sizeof(stg_products[0]), NULL)) != NULL) { 176 device_set_desc(dev, pp->pp_name); 177 return(0); 178 } 179 return(EIO); 180} 181 182static int 183stg_pccard_probe(DEVPORT_PDEVICE dev) 184{ 185 struct stg_softc *sc = device_get_softc(dev); 186 int error; 187 | 84static int stg_pccard_match(device_t dev) 85{ 86 const struct pccard_product *pp; 87 88 if ((pp = pccard_product_lookup(dev, stg_products, 89 sizeof(stg_products[0]), NULL)) != NULL) { 90 device_set_desc(dev, pp->pp_name); 91 return(0); 92 } 93 return(EIO); 94} 95 96static int 97stg_pccard_probe(DEVPORT_PDEVICE dev) 98{ 99 struct stg_softc *sc = device_get_softc(dev); 100 int error; 101 |
188 bzero(sc, sizeof(struct stg_softc)); 189 | 102 sc->port_rid = 0; 103 sc->irq_rid = 0; |
190 error = stg_alloc_resource(dev); 191 if (error) { 192 return(error); 193 } 194 | 104 error = stg_alloc_resource(dev); 105 if (error) { 106 return(error); 107 } 108 |
195 if (stgprobe(dev) == 0) { | 109 if (stg_probe(dev) == 0) { |
196 stg_release_resource(dev); 197 return(ENXIO); 198 } 199 200 stg_release_resource(dev); 201 202 return(0); 203} 204 205static int 206stg_pccard_attach(DEVPORT_PDEVICE dev) 207{ 208 struct stg_softc *sc = device_get_softc(dev); 209 int error; 210 | 110 stg_release_resource(dev); 111 return(ENXIO); 112 } 113 114 stg_release_resource(dev); 115 116 return(0); 117} 118 119static int 120stg_pccard_attach(DEVPORT_PDEVICE dev) 121{ 122 struct stg_softc *sc = device_get_softc(dev); 123 int error; 124 |
125 sc->port_rid = 0; 126 sc->irq_rid = 0; |
|
211 error = stg_alloc_resource(dev); 212 if (error) { 213 return(error); 214 } 215 216 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY, | 127 error = stg_alloc_resource(dev); 128 if (error) { 129 return(error); 130 } 131 132 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY, |
217 stg_pccard_intr, (void *)sc, &sc->stg_intrhand); | 133 stg_intr, (void *)sc, &sc->stg_intrhand); |
218 if (error) { 219 stg_release_resource(dev); 220 return(error); 221 } 222 | 134 if (error) { 135 stg_release_resource(dev); 136 return(error); 137 } 138 |
223 if (stgattach(dev) == 0) { | 139 if (stg_attach(dev) == 0) { |
224 stg_release_resource(dev); 225 return(ENXIO); 226 } 227 228 return(0); 229} 230 | 140 stg_release_resource(dev); 141 return(ENXIO); 142 } 143 144 return(0); 145} 146 |
231static void 232stg_pccard_detach(DEVPORT_PDEVICE dev) 233{ 234 stg_card_unload(dev); 235 stg_release_resource(dev); 236} 237 | |
238static device_method_t stg_pccard_methods[] = { 239 /* Device interface */ 240 DEVMETHOD(device_probe, pccard_compat_probe), 241 DEVMETHOD(device_attach, pccard_compat_attach), | 147static device_method_t stg_pccard_methods[] = { 148 /* Device interface */ 149 DEVMETHOD(device_probe, pccard_compat_probe), 150 DEVMETHOD(device_attach, pccard_compat_attach), |
242 DEVMETHOD(device_detach, stg_pccard_detach), | 151 DEVMETHOD(device_detach, stg_detach), |
243 244 /* Card interface */ 245 DEVMETHOD(card_compat_match, stg_pccard_match), 246 DEVMETHOD(card_compat_probe, stg_pccard_probe), 247 DEVMETHOD(card_compat_attach, stg_pccard_attach), 248 249 { 0, 0 } 250}; 251 252static driver_t stg_pccard_driver = { 253 "stg", 254 stg_pccard_methods, 255 sizeof(struct stg_softc), 256}; 257 | 152 153 /* Card interface */ 154 DEVMETHOD(card_compat_match, stg_pccard_match), 155 DEVMETHOD(card_compat_probe, stg_pccard_probe), 156 DEVMETHOD(card_compat_attach, stg_pccard_attach), 157 158 { 0, 0 } 159}; 160 161static driver_t stg_pccard_driver = { 162 "stg", 163 stg_pccard_methods, 164 sizeof(struct stg_softc), 165}; 166 |
258static devclass_t stg_devclass; 259 260MODULE_DEPEND(stg, scsi_low, 1, 1, 1); | |
261DRIVER_MODULE(stg, pccard, stg_pccard_driver, stg_devclass, 0, 0); | 167DRIVER_MODULE(stg, pccard, stg_pccard_driver, stg_devclass, 0, 0); |
262 263static void 264stg_card_unload(DEVPORT_PDEVICE devi) 265{ 266 struct stg_softc *sc = DEVPORT_PDEVGET_SOFTC(devi); 267 intrmask_t s; 268 269 printf("%s: unload\n",sc->sc_sclow.sl_xname); 270 s = splcam(); 271 scsi_low_deactivate((struct scsi_low_softc *)sc); 272 scsi_low_dettach(&sc->sc_sclow); 273 splx(s); 274} 275 276static int 277stgprobe(DEVPORT_PDEVICE devi) 278{ 279 int rv; 280 struct stg_softc *sc = device_get_softc(devi); 281 282 rv = stgprobesubr(rman_get_bustag(sc->port_res), 283 rman_get_bushandle(sc->port_res), 284 DEVPORT_PDEVFLAGS(devi)); 285 286 return rv; 287} 288 289static int 290stgattach(DEVPORT_PDEVICE devi) 291{ 292 struct stg_softc *sc; 293 struct scsi_low_softc *slp; 294 u_int32_t flags = DEVPORT_PDEVFLAGS(devi); 295 u_int iobase = DEVPORT_PDEVIOBASE(devi); 296 intrmask_t s; 297 char dvname[16]; 298 299 strcpy(dvname,"stg"); 300 301 if (iobase == 0) 302 { 303 printf("%s: no ioaddr is given\n", dvname); 304 return (0); 305 } 306 307 sc = DEVPORT_PDEVALLOC_SOFTC(devi); 308 if (sc == NULL) { 309 return(0); 310 } 311 312 slp = &sc->sc_sclow; 313 slp->sl_dev = devi; 314 sc->sc_iot = rman_get_bustag(sc->port_res); 315 sc->sc_ioh = rman_get_bushandle(sc->port_res); 316 317 slp->sl_hostid = STG_HOSTID; 318 slp->sl_cfgflags = flags; 319 320 s = splcam(); 321 stgattachsubr(sc); 322 splx(s); 323 324 return(STGIOSZ); 325} | 168MODULE_DEPEND(stg, scsi_low, 1, 1, 1); |