diff options
author | imp <imp@FreeBSD.org> | 2009-04-20 01:19:59 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 2009-04-20 01:19:59 +0000 |
commit | dce30a548c74852941ae18fa0911daf1fc988db1 (patch) | |
tree | 17e178d9691ef1ad4763204b9338f58d61e0c1ec | |
parent | b958422b5e64017476e2f902ba8ee01dc2141be6 (diff) | |
download | FreeBSD-src-dce30a548c74852941ae18fa0911daf1fc988db1.zip FreeBSD-src-dce30a548c74852941ae18fa0911daf1fc988db1.tar.gz |
Cleanup resource allocation code a bit. Store the rids on the
resources rather than on the softc. When we allocate resources for PC
Card, if we only get 16 ports, try again to get the others.
-rw-r--r-- | sys/dev/ed/if_ed.c | 30 | ||||
-rw-r--r-- | sys/dev/ed/if_ed_cbus.c | 9 | ||||
-rw-r--r-- | sys/dev/ed/if_ed_isa.c | 7 | ||||
-rw-r--r-- | sys/dev/ed/if_ed_pccard.c | 44 | ||||
-rw-r--r-- | sys/dev/ed/if_edvar.h | 5 |
5 files changed, 48 insertions, 47 deletions
diff --git a/sys/dev/ed/if_ed.c b/sys/dev/ed/if_ed.c index f9a32bf..0cc38cd 100644 --- a/sys/dev/ed/if_ed.c +++ b/sys/dev/ed/if_ed.c @@ -164,7 +164,6 @@ ed_alloc_port(device_t dev, int rid, int size) res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0ul, ~0ul, size, RF_ACTIVE); if (res) { - sc->port_rid = rid; sc->port_res = res; sc->port_used = size; sc->port_bst = rman_get_bustag(res); @@ -186,7 +185,6 @@ ed_alloc_memory(device_t dev, int rid, int size) res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0ul, ~0ul, size, RF_ACTIVE); if (res) { - sc->mem_rid = rid; sc->mem_res = res; sc->mem_used = size; sc->mem_bst = rman_get_bustag(res); @@ -207,7 +205,6 @@ ed_alloc_irq(device_t dev, int rid, int flags) res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE | flags); if (res) { - sc->irq_rid = rid; sc->irq_res = res; return (0); } @@ -222,21 +219,18 @@ ed_release_resources(device_t dev) { struct ed_softc *sc = device_get_softc(dev); - if (sc->port_res) { - bus_release_resource(dev, SYS_RES_IOPORT, - sc->port_rid, sc->port_res); - sc->port_res = 0; - } - if (sc->mem_res) { - bus_release_resource(dev, SYS_RES_MEMORY, - sc->mem_rid, sc->mem_res); - sc->mem_res = 0; - } - if (sc->irq_res) { - bus_release_resource(dev, SYS_RES_IRQ, - sc->irq_rid, sc->irq_res); - sc->irq_res = 0; - } + if (sc->port_res) + bus_free_resource(dev, SYS_RES_IOPORT, sc->port_res); + if (sc->port_res2) + bus_free_resource(dev, SYS_RES_IOPORT, sc->port_res2); + if (sc->mem_res) + bus_free_resource(dev, SYS_RES_MEMORY, sc->mem_res); + if (sc->irq_res) + bus_free_resource(dev, SYS_RES_IRQ, sc->irq_res); + sc->port_res = 0; + sc->port_res2 = 0; + sc->mem_res = 0; + sc->irq_res = 0; if (sc->ifp) if_free(sc->ifp); } diff --git a/sys/dev/ed/if_ed_cbus.c b/sys/dev/ed/if_ed_cbus.c index 7302619..c3660a7 100644 --- a/sys/dev/ed/if_ed_cbus.c +++ b/sys/dev/ed/if_ed_cbus.c @@ -233,14 +233,14 @@ ed_cbus_attach(dev) if (sc->port_used > 0) { if (ED_TYPE98(flags) == ED_TYPE98_GENERIC) - ed_alloc_port(dev, sc->port_rid, sc->port_used); + ed_alloc_port(dev, 0, sc->port_used); else - ed98_alloc_port(dev, sc->port_rid); + ed98_alloc_port(dev, 0); } if (sc->mem_used) - ed_alloc_memory(dev, sc->mem_rid, sc->mem_used); + ed_alloc_memory(dev, 0, sc->mem_used); - ed_alloc_irq(dev, sc->irq_rid, 0); + ed_alloc_irq(dev, 0, 0); if (sc->sc_media_ioctl == NULL) ed_gen_ifmedia_init(sc); @@ -541,7 +541,6 @@ ed98_alloc_port(device_t dev, int rid) if (!res) return (ENOENT); - sc->port_rid = rid; sc->port_res = res; sc->port_used = n; sc->port_bst = rman_get_bustag(res); diff --git a/sys/dev/ed/if_ed_isa.c b/sys/dev/ed/if_ed_isa.c index c3fd8f6..0d7a583 100644 --- a/sys/dev/ed/if_ed_isa.c +++ b/sys/dev/ed/if_ed_isa.c @@ -163,11 +163,10 @@ ed_isa_attach(device_t dev) int error; if (sc->port_used > 0) - ed_alloc_port(dev, sc->port_rid, sc->port_used); + ed_alloc_port(dev, 0, sc->port_used); if (sc->mem_used) - ed_alloc_memory(dev, sc->mem_rid, sc->mem_used); - - ed_alloc_irq(dev, sc->irq_rid, 0); + ed_alloc_memory(dev, 0, sc->mem_used); + ed_alloc_irq(dev, 0, 0); if (sc->sc_media_ioctl == NULL) ed_gen_ifmedia_init(sc); diff --git a/sys/dev/ed/if_ed_pccard.c b/sys/dev/ed/if_ed_pccard.c index 4db2fcf..84e54c2 100644 --- a/sys/dev/ed/if_ed_pccard.c +++ b/sys/dev/ed/if_ed_pccard.c @@ -383,10 +383,7 @@ ed_pccard_rom_mac(device_t dev, uint8_t *enaddr) static int ed_pccard_add_modem(device_t dev) { - struct ed_softc *sc = device_get_softc(dev); - - device_printf(dev, "Need to write this code: modem rid is %d\n", - sc->modem_rid); + device_printf(dev, "Need to write this code\n"); return 0; } @@ -439,7 +436,7 @@ ed_pccard_attach(device_t dev) u_char sum; u_char enaddr[ETHER_ADDR_LEN]; const struct ed_product *pp; - int error, i, flags; + int error, i, flags, port_rid, modem_rid; struct ed_softc *sc = device_get_softc(dev); u_long size; static uint16_t *intr_vals[] = {NULL, NULL}; @@ -447,29 +444,42 @@ ed_pccard_attach(device_t dev) sc->dev = dev; if ((pp = (const struct ed_product *) pccard_product_lookup(dev, (const struct pccard_product *) ed_pccard_products, - sizeof(ed_pccard_products[0]), NULL)) == NULL) + sizeof(ed_pccard_products[0]), NULL)) == NULL) { + printf("Can't find\n"); return (ENXIO); - sc->modem_rid = -1; + } + modem_rid = port_rid = -1; if (pp->flags & NE2000DVF_MODEM) { - sc->port_rid = -1; for (i = 0; i < 4; i++) { size = bus_get_resource_count(dev, SYS_RES_IOPORT, i); if (size == ED_NOVELL_IO_PORTS) - sc->port_rid = i; + port_rid = i; else if (size == 8) - sc->modem_rid = i; + modem_rid = i; } - if (sc->port_rid == -1) { + if (port_rid == -1) { device_printf(dev, "Cannot locate my ports!\n"); return (ENXIO); } } else { - sc->port_rid = 0; + port_rid = 0; } /* Allocate the port resource during setup. */ - error = ed_alloc_port(dev, sc->port_rid, ED_NOVELL_IO_PORTS); - if (error) + error = ed_alloc_port(dev, port_rid, ED_NOVELL_IO_PORTS); + if (error) { + printf("alloc_port failed\n"); return (error); + } + if (rman_get_size(sc->port_res) == ED_NOVELL_IO_PORTS / 2) { + port_rid++; + sc->port_res2 = bus_alloc_resource(dev, SYS_RES_IOPORT, + &port_rid, 0ul, ~0ul, 1, RF_ACTIVE); + if (sc->port_res2 == NULL || + rman_get_size(sc->port_res2) != ED_NOVELL_IO_PORTS / 2) { + error = ENXIO; + goto bad; + } + } error = ed_alloc_irq(dev, 0, 0); if (error) goto bad; @@ -489,8 +499,10 @@ ed_pccard_attach(device_t dev) error = ed_pccard_ax88x90(dev, pp); if (error != 0) error = ed_pccard_tc5299j(dev, pp); - if (error != 0) + if (error != 0) { error = ed_probe_Novell_generic(dev, flags); + printf("Novell probe generic %d\n", error); + } if (error != 0 && (pp->flags & NE2000DVF_TOSHIBA)) { flags |= ED_FLAGS_TOSH_ETHER; flags |= ED_FLAGS_PCCARD; @@ -586,7 +598,7 @@ ed_pccard_attach(device_t dev) } else { ed_gen_ifmedia_init(sc); } - if (sc->modem_rid != -1) + if (modem_rid != -1) ed_pccard_add_modem(dev); error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE, diff --git a/sys/dev/ed/if_edvar.h b/sys/dev/ed/if_edvar.h index 27dd669..56e241a 100644 --- a/sys/dev/ed/if_edvar.h +++ b/sys/dev/ed/if_edvar.h @@ -47,20 +47,17 @@ struct ed_softc { u_char xmit_busy; /* transmitter is busy */ u_char enaddr[6]; - int port_rid; /* resource id for port range */ int port_used; /* nonzero if ports used */ struct resource* port_res; /* resource for port range */ + struct resource* port_res2; /* resource for port range */ bus_space_tag_t port_bst; bus_space_handle_t port_bsh; - int mem_rid; /* resource id for memory range */ int mem_used; /* nonzero if memory used */ struct resource* mem_res; /* resource for memory range */ bus_space_tag_t mem_bst; bus_space_handle_t mem_bsh; - int irq_rid; /* resource id for irq */ struct resource* irq_res; /* resource for irq */ void* irq_handle; /* handle for irq handler */ - int modem_rid; /* resource ID for modem part of device */ int (*sc_media_ioctl)(struct ed_softc *sc, struct ifreq *ifr, u_long command); void (*sc_mediachg)(struct ed_softc *); |