- Release allocated resources on error.
Reported by YAMAMOTO Shigeru <shigeru@iij.ad.jp> - Clean up some code. - Set the value of rid variable to PCI_BASEADR0(== 0x10) (adv_pci.c).
This commit is contained in:
parent
cae3675927
commit
8f230c9baf
@ -142,6 +142,7 @@ adv_isa_probe(device_t dev)
|
||||
bus_size_t maxsize;
|
||||
bus_addr_t lowaddr;
|
||||
int error;
|
||||
struct adv_softc *adv;
|
||||
|
||||
if (port_addr == 0)
|
||||
/* Already been attached */
|
||||
@ -157,164 +158,172 @@ adv_isa_probe(device_t dev)
|
||||
continue;
|
||||
|
||||
if (adv_find_signature(rman_get_bustag(iores),
|
||||
rman_get_bushandle(iores))) {
|
||||
/*
|
||||
* Got one. Now allocate our softc
|
||||
* and see if we can initialize the card.
|
||||
*/
|
||||
struct adv_softc *adv;
|
||||
adv = adv_alloc(dev, rman_get_bustag(iores),
|
||||
rman_get_bushandle(iores));
|
||||
if (adv == NULL)
|
||||
return ENXIO;
|
||||
rman_get_bushandle(iores)) == 0) {
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Stop the chip.
|
||||
*/
|
||||
ADV_OUTB(adv, ADV_CHIP_CTRL, ADV_CC_HALT);
|
||||
ADV_OUTW(adv, ADV_CHIP_STATUS, 0);
|
||||
/*
|
||||
* Determine the chip version.
|
||||
*/
|
||||
adv->chip_version = ADV_INB(adv,
|
||||
ADV_NONEISA_CHIP_REVISION);
|
||||
if ((adv->chip_version >= ADV_CHIP_MIN_VER_VL)
|
||||
&& (adv->chip_version <= ADV_CHIP_MAX_VER_VL)) {
|
||||
adv->type = ADV_VL;
|
||||
maxsegsz = ADV_VL_MAX_DMA_COUNT;
|
||||
maxsize = BUS_SPACE_MAXSIZE_32BIT;
|
||||
lowaddr = ADV_VL_MAX_DMA_ADDR;
|
||||
bus_delete_resource(dev, SYS_RES_DRQ, 0);
|
||||
} else if ((adv->chip_version >= ADV_CHIP_MIN_VER_ISA)
|
||||
&& (adv->chip_version <= ADV_CHIP_MAX_VER_ISA)) {
|
||||
if (adv->chip_version >= ADV_CHIP_MIN_VER_ISA_PNP) {
|
||||
adv->type = ADV_ISAPNP;
|
||||
ADV_OUTB(adv, ADV_REG_IFC,
|
||||
ADV_IFC_INIT_DEFAULT);
|
||||
} else {
|
||||
adv->type = ADV_ISA;
|
||||
}
|
||||
maxsegsz = ADV_ISA_MAX_DMA_COUNT;
|
||||
maxsize = BUS_SPACE_MAXSIZE_24BIT;
|
||||
lowaddr = ADV_ISA_MAX_DMA_ADDR;
|
||||
adv->isa_dma_speed = ADV_DEF_ISA_DMA_SPEED;
|
||||
adv->isa_dma_channel =
|
||||
adv_get_isa_dma_channel(adv);
|
||||
bus_set_resource(dev, SYS_RES_DRQ, 0,
|
||||
adv->isa_dma_channel, 1);
|
||||
/*
|
||||
* Got one. Now allocate our softc
|
||||
* and see if we can initialize the card.
|
||||
*/
|
||||
adv = adv_alloc(dev, rman_get_bustag(iores),
|
||||
rman_get_bushandle(iores));
|
||||
if (adv == NULL) {
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
/*
|
||||
* Stop the chip.
|
||||
*/
|
||||
ADV_OUTB(adv, ADV_CHIP_CTRL, ADV_CC_HALT);
|
||||
ADV_OUTW(adv, ADV_CHIP_STATUS, 0);
|
||||
/*
|
||||
* Determine the chip version.
|
||||
*/
|
||||
adv->chip_version = ADV_INB(adv, ADV_NONEISA_CHIP_REVISION);
|
||||
if ((adv->chip_version >= ADV_CHIP_MIN_VER_VL)
|
||||
&& (adv->chip_version <= ADV_CHIP_MAX_VER_VL)) {
|
||||
adv->type = ADV_VL;
|
||||
maxsegsz = ADV_VL_MAX_DMA_COUNT;
|
||||
maxsize = BUS_SPACE_MAXSIZE_32BIT;
|
||||
lowaddr = ADV_VL_MAX_DMA_ADDR;
|
||||
bus_delete_resource(dev, SYS_RES_DRQ, 0);
|
||||
} else if ((adv->chip_version >= ADV_CHIP_MIN_VER_ISA)
|
||||
&& (adv->chip_version <= ADV_CHIP_MAX_VER_ISA)) {
|
||||
if (adv->chip_version >= ADV_CHIP_MIN_VER_ISA_PNP) {
|
||||
adv->type = ADV_ISAPNP;
|
||||
ADV_OUTB(adv, ADV_REG_IFC,
|
||||
ADV_IFC_INIT_DEFAULT);
|
||||
} else {
|
||||
panic("advisaprobe: Unknown card revision\n");
|
||||
adv->type = ADV_ISA;
|
||||
}
|
||||
maxsegsz = ADV_ISA_MAX_DMA_COUNT;
|
||||
maxsize = BUS_SPACE_MAXSIZE_24BIT;
|
||||
lowaddr = ADV_ISA_MAX_DMA_ADDR;
|
||||
adv->isa_dma_speed = ADV_DEF_ISA_DMA_SPEED;
|
||||
adv->isa_dma_channel = adv_get_isa_dma_channel(adv);
|
||||
bus_set_resource(dev, SYS_RES_DRQ, 0,
|
||||
adv->isa_dma_channel, 1);
|
||||
} else {
|
||||
panic("advisaprobe: Unknown card revision\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a parent dmatag for all tags created
|
||||
* by the MI portions of the advansys driver
|
||||
*/
|
||||
/* XXX Should be a child of the ISA bus dma tag */
|
||||
error =
|
||||
bus_dma_tag_create(/*parent*/NULL,
|
||||
/*alignemnt*/1,
|
||||
/*
|
||||
* Allocate a parent dmatag for all tags created
|
||||
* by the MI portions of the advansys driver
|
||||
*/
|
||||
/* XXX Should be a child of the ISA bus dma tag */
|
||||
error = bus_dma_tag_create(/*parent*/NULL,
|
||||
/*alignemnt*/1,
|
||||
/*boundary*/0,
|
||||
lowaddr,
|
||||
/*highaddr*/BUS_SPACE_MAXADDR,
|
||||
/*filter*/NULL,
|
||||
/*filterarg*/NULL,
|
||||
maxsize,
|
||||
/*nsegs*/BUS_SPACE_UNRESTRICTED,
|
||||
maxsegsz,
|
||||
/*flags*/0,
|
||||
&adv->parent_dmat);
|
||||
|
||||
if (error != 0) {
|
||||
printf("%s: Could not allocate DMA tag - error %d\n",
|
||||
adv_name(adv), error);
|
||||
adv_free(adv);
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
adv->init_level++;
|
||||
|
||||
if (overrun_buf == NULL) {
|
||||
/* Need to allocate our overrun buffer */
|
||||
if (bus_dma_tag_create(adv->parent_dmat,
|
||||
/*alignment*/8,
|
||||
/*boundary*/0,
|
||||
lowaddr,
|
||||
/*highaddr*/BUS_SPACE_MAXADDR,
|
||||
ADV_ISA_MAX_DMA_ADDR,
|
||||
BUS_SPACE_MAXADDR,
|
||||
/*filter*/NULL,
|
||||
/*filterarg*/NULL,
|
||||
maxsize,
|
||||
/*nsegs*/BUS_SPACE_UNRESTRICTED,
|
||||
maxsegsz,
|
||||
ADV_OVERRUN_BSIZE,
|
||||
/*nsegments*/1,
|
||||
BUS_SPACE_MAXSIZE_32BIT,
|
||||
/*flags*/0,
|
||||
&adv->parent_dmat);
|
||||
|
||||
if (error != 0) {
|
||||
printf("%s: Could not allocate DMA tag - error %d\n",
|
||||
adv_name(adv), error);
|
||||
adv_free(adv);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
adv->init_level++;
|
||||
|
||||
if (overrun_buf == NULL) {
|
||||
/* Need to allocate our overrun buffer */
|
||||
if (bus_dma_tag_create(adv->parent_dmat,
|
||||
/*alignment*/8,
|
||||
/*boundary*/0,
|
||||
ADV_ISA_MAX_DMA_ADDR,
|
||||
BUS_SPACE_MAXADDR,
|
||||
/*filter*/NULL,
|
||||
/*filterarg*/NULL,
|
||||
ADV_OVERRUN_BSIZE,
|
||||
/*nsegments*/1,
|
||||
BUS_SPACE_MAXSIZE_32BIT,
|
||||
/*flags*/0,
|
||||
&overrun_dmat) != 0) {
|
||||
adv_free(adv);
|
||||
return ENXIO;
|
||||
}
|
||||
if (bus_dmamem_alloc(overrun_dmat,
|
||||
(void **)&overrun_buf,
|
||||
BUS_DMA_NOWAIT,
|
||||
&overrun_dmamap) != 0) {
|
||||
bus_dma_tag_destroy(overrun_dmat);
|
||||
adv_free(adv);
|
||||
return ENXIO;
|
||||
}
|
||||
/* And permanently map it in */
|
||||
bus_dmamap_load(overrun_dmat, overrun_dmamap,
|
||||
overrun_buf, ADV_OVERRUN_BSIZE,
|
||||
adv_map, &overrun_physbase,
|
||||
/*flags*/0);
|
||||
}
|
||||
|
||||
adv->overrun_physbase = overrun_physbase;
|
||||
|
||||
if (adv_init(adv) != 0) {
|
||||
&overrun_dmat) != 0) {
|
||||
adv_free(adv);
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0,
|
||||
iores);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
switch (adv->type) {
|
||||
case ADV_ISAPNP:
|
||||
if (adv->chip_version == ADV_CHIP_VER_ASYN_BUG){
|
||||
adv->bug_fix_control
|
||||
|= ADV_BUG_FIX_ASYN_USE_SYN;
|
||||
adv->fix_asyn_xfer = ~0;
|
||||
}
|
||||
/* Fall Through */
|
||||
case ADV_ISA:
|
||||
adv->max_dma_count = ADV_ISA_MAX_DMA_COUNT;
|
||||
adv->max_dma_addr = ADV_ISA_MAX_DMA_ADDR;
|
||||
adv_set_isa_dma_settings(adv);
|
||||
break;
|
||||
|
||||
case ADV_VL:
|
||||
adv->max_dma_count = ADV_VL_MAX_DMA_COUNT;
|
||||
adv->max_dma_addr = ADV_VL_MAX_DMA_ADDR;
|
||||
break;
|
||||
default:
|
||||
panic("advisaprobe: Invalid card type\n");
|
||||
}
|
||||
|
||||
/* Determine our IRQ */
|
||||
if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL))
|
||||
bus_set_resource(dev, SYS_RES_IRQ, 0,
|
||||
adv_get_chip_irq(adv), 1);
|
||||
else
|
||||
adv_set_chip_irq(adv, irq);
|
||||
|
||||
irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
|
||||
0, ~0, 1, RF_ACTIVE);
|
||||
if (irqres == NULL ||
|
||||
bus_setup_intr(dev, irqres, INTR_TYPE_CAM,
|
||||
adv_intr, adv, &ih)) {
|
||||
if (bus_dmamem_alloc(overrun_dmat,
|
||||
(void **)&overrun_buf,
|
||||
BUS_DMA_NOWAIT,
|
||||
&overrun_dmamap) != 0) {
|
||||
bus_dma_tag_destroy(overrun_dmat);
|
||||
adv_free(adv);
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0,
|
||||
iores);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
/* Mark as probed */
|
||||
adv_isa_ioports[port_index] = 0;
|
||||
return 0;
|
||||
/* And permanently map it in */
|
||||
bus_dmamap_load(overrun_dmat, overrun_dmamap,
|
||||
overrun_buf, ADV_OVERRUN_BSIZE,
|
||||
adv_map, &overrun_physbase,
|
||||
/*flags*/0);
|
||||
}
|
||||
|
||||
adv->overrun_physbase = overrun_physbase;
|
||||
|
||||
if (adv_init(adv) != 0) {
|
||||
adv_free(adv);
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
switch (adv->type) {
|
||||
case ADV_ISAPNP:
|
||||
if (adv->chip_version == ADV_CHIP_VER_ASYN_BUG) {
|
||||
adv->bug_fix_control
|
||||
|= ADV_BUG_FIX_ASYN_USE_SYN;
|
||||
adv->fix_asyn_xfer = ~0;
|
||||
}
|
||||
/* Fall Through */
|
||||
case ADV_ISA:
|
||||
adv->max_dma_count = ADV_ISA_MAX_DMA_COUNT;
|
||||
adv->max_dma_addr = ADV_ISA_MAX_DMA_ADDR;
|
||||
adv_set_isa_dma_settings(adv);
|
||||
break;
|
||||
|
||||
case ADV_VL:
|
||||
adv->max_dma_count = ADV_VL_MAX_DMA_COUNT;
|
||||
adv->max_dma_addr = ADV_VL_MAX_DMA_ADDR;
|
||||
break;
|
||||
default:
|
||||
panic("advisaprobe: Invalid card type\n");
|
||||
}
|
||||
|
||||
/* Determine our IRQ */
|
||||
if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL))
|
||||
bus_set_resource(dev, SYS_RES_IRQ, 0,
|
||||
adv_get_chip_irq(adv), 1);
|
||||
else
|
||||
adv_set_chip_irq(adv, irq);
|
||||
|
||||
irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
|
||||
RF_ACTIVE);
|
||||
if (irqres == NULL ||
|
||||
bus_setup_intr(dev, irqres, INTR_TYPE_CAM, adv_intr, adv,
|
||||
&ih)) {
|
||||
adv_free(adv);
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
/* Mark as probed */
|
||||
adv_isa_ioports[port_index] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ENXIO;
|
||||
|
@ -136,8 +136,7 @@ adv_pci_attach(device_t dev)
|
||||
struct adv_softc *adv;
|
||||
u_int32_t id;
|
||||
u_int32_t command;
|
||||
int error;
|
||||
int rid = 0;
|
||||
int error, rid;
|
||||
void *ih;
|
||||
struct resource *iores, *irqres;
|
||||
|
||||
@ -166,18 +165,23 @@ adv_pci_attach(device_t dev)
|
||||
pci_write_config(dev, PCIR_LATTIMER, /*value*/0, /*bytes*/1);
|
||||
}
|
||||
|
||||
rid = PCI_BASEADR0;
|
||||
iores = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
|
||||
RF_ACTIVE);
|
||||
if (iores == NULL)
|
||||
return ENXIO;
|
||||
|
||||
if (adv_find_signature(rman_get_bustag(iores),
|
||||
rman_get_bushandle(iores)) == 0)
|
||||
rman_get_bushandle(iores)) == 0) {
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
adv = adv_alloc(dev, rman_get_bustag(iores), rman_get_bushandle(iores));
|
||||
if (adv == NULL)
|
||||
if (adv == NULL) {
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
/* Allocate a dmatag for our transfer DMA maps */
|
||||
/* XXX Should be a child of the PCI bus dma tag */
|
||||
@ -196,6 +200,7 @@ adv_pci_attach(device_t dev)
|
||||
printf("%s: Could not allocate DMA tag - error %d\n",
|
||||
adv_name(adv), error);
|
||||
adv_free(adv);
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
@ -212,6 +217,7 @@ adv_pci_attach(device_t dev)
|
||||
&overrun_dmat) != 0) {
|
||||
bus_dma_tag_destroy(adv->parent_dmat);
|
||||
adv_free(adv);
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
return ENXIO;
|
||||
}
|
||||
if (bus_dmamem_alloc(overrun_dmat,
|
||||
@ -221,6 +227,7 @@ adv_pci_attach(device_t dev)
|
||||
bus_dma_tag_destroy(overrun_dmat);
|
||||
bus_dma_tag_destroy(adv->parent_dmat);
|
||||
adv_free(adv);
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
return ENXIO;
|
||||
}
|
||||
/* And permanently map it in */
|
||||
@ -258,6 +265,7 @@ adv_pci_attach(device_t dev)
|
||||
|
||||
if (adv_init(adv) != 0) {
|
||||
adv_free(adv);
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
@ -281,11 +289,13 @@ adv_pci_attach(device_t dev)
|
||||
adv->fix_asyn_xfer = ~0;
|
||||
}
|
||||
|
||||
rid = 0;
|
||||
irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
|
||||
RF_SHAREABLE | RF_ACTIVE);
|
||||
if (irqres == NULL ||
|
||||
bus_setup_intr(dev, irqres, INTR_TYPE_CAM, adv_intr, adv, &ih)) {
|
||||
adv_free(adv);
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user