Some more small newbus cleanups. Remember to free all resources in case

of failures in foo_attach(), simplify iospace/memspace things a little.
This commit is contained in:
wpaul 1999-07-23 02:06:57 +00:00
parent 8f4f22aaa5
commit d259535fad
4 changed files with 95 additions and 75 deletions

View File

@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: if_sk.c,v 1.5 1999/07/22 04:04:11 wpaul Exp $
* $Id: if_sk.c,v 1.51 1999/07/14 21:48:19 wpaul Exp $
*/
/*
@ -102,7 +102,7 @@
#ifndef lint
static const char rcsid[] =
"$Id: if_sk.c,v 1.5 1999/07/22 04:04:11 wpaul Exp $";
"$Id: if_sk.c,v 1.51 1999/07/14 21:48:19 wpaul Exp $";
#endif
static struct sk_type sk_devs[] = {
@ -157,6 +157,14 @@ static u_int32_t sk_calchash __P((caddr_t));
static void sk_setfilt __P((struct sk_if_softc *, caddr_t, int));
static void sk_setmulti __P((struct sk_if_softc *));
#ifdef SK_USEIOSPACE
#define SK_RES SYS_RES_IOPORT
#define SK_RID SK_PCI_LOIO
#else
#define SK_RES SYS_RES_MEMORY
#define SK_RID SK_PCI_LOMEM
#endif
static device_method_t sk_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, sk_probe),
@ -1198,22 +1206,18 @@ static int sk_attach(dev)
error = ENXIO;
goto fail;
}
rid = SK_PCI_LOIO;
sc->sk_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
0, ~0, 1, RF_ACTIVE);
#else
if (!(command & PCIM_CMD_MEMEN)) {
printf("skc%d: failed to enable memory mapping!\n", unit);
error = ENXIO;
goto fail;
}
rid = SK_PCI_LOMEM;
sc->sk_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
0, ~0, 1, RF_ACTIVE);
#endif
rid = SK_RID;
sc->sk_res = bus_alloc_resource(dev, SK_RES, &rid,
0, ~0, 1, RF_ACTIVE);
if (sc->sk_res == NULL) {
printf("sk%d: couldn't map ports/memory\n", unit);
error = ENXIO;
@ -1230,6 +1234,7 @@ static int sk_attach(dev)
if (sc->sk_irq == NULL) {
printf("skc%d: couldn't map interrupt\n", unit);
bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
error = ENXIO;
goto fail;
}
@ -1239,6 +1244,8 @@ static int sk_attach(dev)
if (error) {
printf("skc%d: couldn't set up irq\n", unit);
bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_res);
goto fail;
}
@ -1271,6 +1278,9 @@ static int sk_attach(dev)
default:
printf("skc%d: unknown ram size: %d\n",
sc->sk_unit, sk_win_read_1(sc, SK_EPROM0));
bus_teardown_intr(dev, sc->sk_irq, sc->sk_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_irq);
bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
error = ENXIO;
goto fail;
break;
@ -1293,6 +1303,9 @@ static int sk_attach(dev)
default:
printf("skc%d: unknown media type: 0x%x\n",
sc->sk_unit, sk_win_read_1(sc, SK_PMDTYPE));
bus_teardown_intr(dev, sc->sk_irq, sc->sk_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_irq);
bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
error = ENXIO;
goto fail;
}
@ -1340,11 +1353,7 @@ static int sk_detach(dev)
bus_teardown_intr(dev, sc->sk_irq, sc->sk_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_irq);
#ifdef SK_USEIOSPACE
bus_release_resource(dev, SYS_RES_IOPORT, SK_PCI_LOIO, sc->sk_res);
#else
bus_release_resource(dev, SYS_RES_MEMORY, SK_PCI_LOMEM, sc->sk_res);
#endif
bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
splx(s);

View File

@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: if_sk.c,v 1.5 1999/07/22 04:04:11 wpaul Exp $
* $Id: if_sk.c,v 1.51 1999/07/14 21:48:19 wpaul Exp $
*/
/*
@ -102,7 +102,7 @@
#ifndef lint
static const char rcsid[] =
"$Id: if_sk.c,v 1.5 1999/07/22 04:04:11 wpaul Exp $";
"$Id: if_sk.c,v 1.51 1999/07/14 21:48:19 wpaul Exp $";
#endif
static struct sk_type sk_devs[] = {
@ -157,6 +157,14 @@ static u_int32_t sk_calchash __P((caddr_t));
static void sk_setfilt __P((struct sk_if_softc *, caddr_t, int));
static void sk_setmulti __P((struct sk_if_softc *));
#ifdef SK_USEIOSPACE
#define SK_RES SYS_RES_IOPORT
#define SK_RID SK_PCI_LOIO
#else
#define SK_RES SYS_RES_MEMORY
#define SK_RID SK_PCI_LOMEM
#endif
static device_method_t sk_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, sk_probe),
@ -1198,22 +1206,18 @@ static int sk_attach(dev)
error = ENXIO;
goto fail;
}
rid = SK_PCI_LOIO;
sc->sk_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
0, ~0, 1, RF_ACTIVE);
#else
if (!(command & PCIM_CMD_MEMEN)) {
printf("skc%d: failed to enable memory mapping!\n", unit);
error = ENXIO;
goto fail;
}
rid = SK_PCI_LOMEM;
sc->sk_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
0, ~0, 1, RF_ACTIVE);
#endif
rid = SK_RID;
sc->sk_res = bus_alloc_resource(dev, SK_RES, &rid,
0, ~0, 1, RF_ACTIVE);
if (sc->sk_res == NULL) {
printf("sk%d: couldn't map ports/memory\n", unit);
error = ENXIO;
@ -1230,6 +1234,7 @@ static int sk_attach(dev)
if (sc->sk_irq == NULL) {
printf("skc%d: couldn't map interrupt\n", unit);
bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
error = ENXIO;
goto fail;
}
@ -1239,6 +1244,8 @@ static int sk_attach(dev)
if (error) {
printf("skc%d: couldn't set up irq\n", unit);
bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_res);
goto fail;
}
@ -1271,6 +1278,9 @@ static int sk_attach(dev)
default:
printf("skc%d: unknown ram size: %d\n",
sc->sk_unit, sk_win_read_1(sc, SK_EPROM0));
bus_teardown_intr(dev, sc->sk_irq, sc->sk_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_irq);
bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
error = ENXIO;
goto fail;
break;
@ -1293,6 +1303,9 @@ static int sk_attach(dev)
default:
printf("skc%d: unknown media type: 0x%x\n",
sc->sk_unit, sk_win_read_1(sc, SK_PMDTYPE));
bus_teardown_intr(dev, sc->sk_irq, sc->sk_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_irq);
bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
error = ENXIO;
goto fail;
}
@ -1340,11 +1353,7 @@ static int sk_detach(dev)
bus_teardown_intr(dev, sc->sk_irq, sc->sk_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_irq);
#ifdef SK_USEIOSPACE
bus_release_resource(dev, SYS_RES_IOPORT, SK_PCI_LOIO, sc->sk_res);
#else
bus_release_resource(dev, SYS_RES_MEMORY, SK_PCI_LOMEM, sc->sk_res);
#endif
bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
splx(s);

View File

@ -339,6 +339,14 @@ static void tl_dio_clrbit __P((struct tl_softc *, int, int));
static void tl_dio_setbit16 __P((struct tl_softc *, int, int));
static void tl_dio_clrbit16 __P((struct tl_softc *, int, int));
#ifdef TL_USEIOSPACE
#define TL_RES SYS_RES_IOPORT
#define TL_RID TL_PCI_LOIO
#else
#define TL_RES SYS_RES_MEMORY
#define TL_RID TL_PCI_LOMEM
#endif
static device_method_t tl_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, tl_probe),
@ -1531,9 +1539,6 @@ static int tl_attach(dev)
device_t dev;
{
int s, i, phys = 0;
#ifndef TL_USEIOSPACE
vm_offset_t pbase, vbase;
#endif
u_int32_t command;
u_int16_t did, vid;
struct tl_type *t;
@ -1635,6 +1640,7 @@ static int tl_attach(dev)
RF_SHAREABLE | RF_ACTIVE);
if (sc->tl_irq == NULL) {
bus_release_resource(dev, TL_RES, TL_RID, sc->tl_res);
printf("tl%d: couldn't map interrupt\n", unit);
error = ENXIO;
goto fail;
@ -1644,6 +1650,8 @@ static int tl_attach(dev)
tl_intr, sc, &sc->tl_intrhand);
if (error) {
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->tl_res);
bus_release_resource(dev, TL_RES, TL_RID, sc->tl_res);
printf("tl%d: couldn't set up irq\n", unit);
goto fail;
}
@ -1664,14 +1672,9 @@ static int tl_attach(dev)
M_DEVBUF, M_NOWAIT);
if (sc->tl_ldata_ptr == NULL) {
bus_teardown_intr(dev, sc->tl_irq, sc->tl_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->tl_irq);
#ifdef TL_USEIOSPACE
bus_release_resource(dev, SYS_RES_IOPORT,
TL_PCI_LOIO, sc->tl_res);
#else
bus_release_resource(dev, SYS_RES_MEMORY,
TL_PCI_LOMEM, sc->tl_res);
#endif
bus_release_resource(dev, TL_RES, TL_RID, sc->tl_res);
printf("tl%d: no memory for list buffers!\n", unit);
error = ENXIO;
goto fail;
@ -1713,14 +1716,9 @@ static int tl_attach(dev)
*/
if (tl_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr,
sc->tl_eeaddr, ETHER_ADDR_LEN)) {
bus_teardown_intr(dev, sc->tl_irq, sc->tl_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->tl_irq);
#ifdef TL_USEIOSPACE
bus_release_resource(dev, SYS_RES_IOPORT,
TL_PCI_LOIO, sc->tl_res);
#else
bus_release_resource(dev, SYS_RES_MEMORY,
TL_PCI_LOMEM, sc->tl_res);
#endif
bus_release_resource(dev, TL_RES, TL_RID, sc->tl_res);
free(sc->tl_ldata_ptr, M_DEVBUF);
printf("tl%d: failed to read station address\n", unit);
error = ENXIO;
@ -1793,14 +1791,9 @@ static int tl_attach(dev)
if (!sc->tl_phy_sts)
continue;
if (tl_attach_phy(sc)) {
bus_teardown_intr(dev, sc->tl_irq, sc->tl_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->tl_irq);
#ifdef TL_USEIOSPACE
bus_release_resource(dev, SYS_RES_IOPORT,
TL_PCI_LOIO, sc->tl_res);
#else
bus_release_resource(dev, SYS_RES_MEMORY,
TL_PCI_LOMEM, sc->tl_res);
#endif
bus_release_resource(dev, TL_RES, TL_RID, sc->tl_res);
free(sc->tl_ldata_ptr, M_DEVBUF);
printf("tl%d: failed to attach a phy %d\n", unit, i);
error = ENXIO;
@ -1876,11 +1869,7 @@ static int tl_detach(dev)
bus_teardown_intr(dev, sc->tl_irq, sc->tl_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->tl_irq);
#ifdef TL_USEIOSPACE
bus_release_resource(dev, SYS_RES_IOPORT, TL_PCI_LOIO, sc->tl_res);
#else
bus_release_resource(dev, SYS_RES_MEMORY, TL_PCI_LOMEM, sc->tl_res);
#endif
bus_release_resource(dev, TL_RES, TL_RID, sc->tl_res);
splx(s);

View File

@ -269,6 +269,14 @@ static void xl_mediacheck __P((struct xl_softc *));
static void xl_testpacket __P((struct xl_softc *));
#endif
#ifdef XL_USEIOSPACE
#define XL_RES SYS_RES_IOPORT
#define XL_RID XL_PCI_LOIO
#else
#define XL_RES SYS_RES_MEMORY
#define XL_RID XL_PCI_LOMEM
#endif
static device_method_t xl_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, xl_probe),
@ -1398,8 +1406,7 @@ static void xl_mediacheck(sc)
* Attach the interface. Allocate softc structures, do ifmedia
* setup and ethernet/BPF attach.
*/
static int
xl_attach(dev)
static int xl_attach(dev)
device_t dev;
{
int s, i;
@ -1477,24 +1484,20 @@ xl_attach(dev)
error = ENXIO;
goto fail;
}
rid = XL_PCI_LOIO;
sc->xl_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
0, ~0, 1, RF_ACTIVE);
#else
if (!(command & PCIM_CMD_MEMEN)) {
printf("xl%d: failed to enable memory mapping!\n", unit);
error = ENXIO;
goto fail;
}
rid = XL_PCI_LOMEM;
sc->xl_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
0, ~0, 1, RF_ACTIVE);
#endif
rid = XL_RID;
sc->xl_res = bus_alloc_resource(dev, XL_RES, &rid,
0, ~0, 1, RF_ACTIVE);
if (sc->xl_res == NULL) {
printf ("xl%d: couldn't map ports\n", unit);
printf ("xl%d: couldn't map ports/memory\n", unit);
error = ENXIO;
goto fail;
}
@ -1508,6 +1511,7 @@ xl_attach(dev)
if (sc->xl_irq == NULL) {
printf("xl%d: couldn't map interrupt\n", unit);
bus_release_resource(dev, XL_RES, XL_RID, sc->xl_res);
error = ENXIO;
goto fail;
}
@ -1516,6 +1520,8 @@ xl_attach(dev)
xl_intr, sc, &sc->xl_intrhand);
if (error) {
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->xl_irq);
bus_release_resource(dev, XL_RES, XL_RID, sc->xl_res);
printf("xl%d: couldn't set up irq\n", unit);
goto fail;
}
@ -1528,6 +1534,9 @@ xl_attach(dev)
*/
if (xl_read_eeprom(sc, (caddr_t)&eaddr, XL_EE_OEM_ADR0, 3, 1)) {
printf("xl%d: failed to read station address\n", sc->xl_unit);
bus_teardown_intr(dev, sc->xl_irq, sc->xl_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->xl_irq);
bus_release_resource(dev, XL_RES, XL_RID, sc->xl_res);
error = ENXIO;
goto fail;
}
@ -1545,6 +1554,9 @@ xl_attach(dev)
M_DEVBUF, M_NOWAIT);
if (sc->xl_ldata_ptr == NULL) {
printf("xl%d: no memory for list buffers!\n", unit);
bus_teardown_intr(dev, sc->xl_irq, sc->xl_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->xl_irq);
bus_release_resource(dev, XL_RES, XL_RID, sc->xl_res);
error = ENXIO;
goto fail;
}
@ -1665,6 +1677,11 @@ xl_attach(dev)
sc->xl_unit, sc->xl_pinfo->xl_name);
} else {
printf("xl%d: MII without any phy!\n", sc->xl_unit);
bus_teardown_intr(dev, sc->xl_irq, sc->xl_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->xl_irq);
bus_release_resource(dev, XL_RES, XL_RID, sc->xl_res);
error = ENXIO;
goto fail;
}
}
@ -1838,11 +1855,7 @@ static int xl_detach(dev)
bus_teardown_intr(dev, sc->xl_irq, sc->xl_intrhand);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->xl_irq);
#ifdef XL_USEIOSPACE
bus_release_resource(dev, SYS_RES_IOPORT, XL_PCI_LOIO, sc->xl_res);
#else
bus_release_resource(dev, SYS_RES_MEMORY, XL_PCI_LOMEM, sc->xl_res);
#endif
bus_release_resource(dev, XL_RES, XL_RID, sc->xl_res);
free(sc->xl_ldata_ptr, M_DEVBUF);
ifmedia_removeall(&sc->ifmedia);