summaryrefslogtreecommitdiffstats
path: root/sys/dev/hme
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2004-08-12 20:37:02 +0000
committermarius <marius@FreeBSD.org>2004-08-12 20:37:02 +0000
commit00b723c98e12d2b81faf26ac4151bc1a09058f7c (patch)
tree0d96771eaa2d64946a88ca6aef1fbcfeaad81e01 /sys/dev/hme
parentc5a462b4d9c262be85ebc8bcaf384b7fedf6635f (diff)
downloadFreeBSD-src-00b723c98e12d2b81faf26ac4151bc1a09058f7c.zip
FreeBSD-src-00b723c98e12d2b81faf26ac4151bc1a09058f7c.tar.gz
- Use bus_space_subregion() rather than arithmetic on bus_space_handle_t. [1]
- Properly use the error variable and return it on failure in the attach- routines. Reviewed by: tmm Inspired by: NetBSD [1]
Diffstat (limited to 'sys/dev/hme')
-rw-r--r--sys/dev/hme/if_hme.c4
-rw-r--r--sys/dev/hme/if_hme_pci.c27
-rw-r--r--sys/dev/hme/if_hme_sbus.c22
-rw-r--r--sys/dev/hme/if_hmevar.h5
4 files changed, 30 insertions, 28 deletions
diff --git a/sys/dev/hme/if_hme.c b/sys/dev/hme/if_hme.c
index b74cb92..99d3c08 100644
--- a/sys/dev/hme/if_hme.c
+++ b/sys/dev/hme/if_hme.c
@@ -138,10 +138,10 @@ MODULE_DEPEND(hme, miibus, 1, 1, 1);
#define HME_SPC_READ_4(spc, sc, offs) \
bus_space_read_4((sc)->sc_ ## spc ## t, (sc)->sc_ ## spc ## h, \
- (sc)->sc_ ## spc ## o + (offs))
+ (offs))
#define HME_SPC_WRITE_4(spc, sc, offs, v) \
bus_space_write_4((sc)->sc_ ## spc ## t, (sc)->sc_ ## spc ## h, \
- (sc)->sc_ ## spc ## o + (offs), (v))
+ (offs), (v))
#define HME_SEB_READ_4(sc, offs) HME_SPC_READ_4(seb, (sc), (offs))
#define HME_SEB_WRITE_4(sc, offs, v) HME_SPC_WRITE_4(seb, (sc), (offs), (v))
diff --git a/sys/dev/hme/if_hme_pci.c b/sys/dev/hme/if_hme_pci.c
index d988050..419f554 100644
--- a/sys/dev/hme/if_hme_pci.c
+++ b/sys/dev/hme/if_hme_pci.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: NetBSD: if_hme_pci.c,v 1.4 2001/08/27 22:18:49 augustss Exp
+ * from: NetBSD: if_hme_pci.c,v 1.7 2001/10/05 17:49:43 thorpej Exp
*/
#include <sys/cdefs.h>
@@ -133,7 +133,7 @@ hme_pci_attach(device_t dev)
{
struct hme_pci_softc *hsc = device_get_softc(dev);
struct hme_softc *sc = &hsc->hsc_hme;
- int error;
+ int error = 0;
pci_enable_busmaster(dev);
/*
@@ -171,15 +171,20 @@ hme_pci_attach(device_t dev)
error = ENXIO;
goto fail_sres;
}
+ hsc->hsc_memt = rman_get_bustag(hsc->hsc_sres);
+ hsc->hsc_memh = rman_get_bushandle(hsc->hsc_sres);
sc->sc_sebt = sc->sc_etxt = sc->sc_erxt = sc->sc_mact = sc->sc_mift =
- rman_get_bustag(hsc->hsc_sres);
- sc->sc_sebh = sc->sc_etxh = sc->sc_erxh = sc->sc_mach = sc->sc_mifh =
- rman_get_bushandle(hsc->hsc_sres);
- sc->sc_sebo = 0;
- sc->sc_etxo = 0x2000;
- sc->sc_erxo = 0x4000;
- sc->sc_maco = 0x6000;
- sc->sc_mifo = 0x7000;
+ hsc->hsc_memt;
+ bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x0000, 0x1000,
+ &sc->sc_sebh);
+ bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x2000, 0x1000,
+ &sc->sc_etxh);
+ bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x4000, 0x1000,
+ &sc->sc_erxh);
+ bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x6000, 0x1000,
+ &sc->sc_mach);
+ bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x7000, 0x1000,
+ &sc->sc_mifh);
OF_getetheraddr(dev, sc->sc_arpcom.ac_enaddr);
@@ -205,7 +210,7 @@ fail_ires:
bus_release_resource(dev, SYS_RES_IRQ, hsc->hsc_irid, hsc->hsc_ires);
fail_sres:
bus_release_resource(dev, SYS_RES_MEMORY, hsc->hsc_srid, hsc->hsc_sres);
- return (ENXIO);
+ return (error);
}
static int
diff --git a/sys/dev/hme/if_hme_sbus.c b/sys/dev/hme/if_hme_sbus.c
index 06c0d8a..769ceb5 100644
--- a/sys/dev/hme/if_hme_sbus.c
+++ b/sys/dev/hme/if_hme_sbus.c
@@ -33,7 +33,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * from: NetBSD: if_hme_sbus.c,v 1.9 2001/11/13 06:58:17 lukem Exp
+ * from: NetBSD: if_hme_sbus.c,v 1.19 2004/03/17 17:04:58 pk Exp
*/
#include <sys/cdefs.h>
@@ -150,7 +150,7 @@ hme_sbus_attach(device_t dev)
struct hme_softc *sc = &hsc->hsc_hme;
u_int32_t burst;
u_long start, count;
- int error;
+ int error = 0;
/*
* Map five register banks:
@@ -162,7 +162,6 @@ hme_sbus_attach(device_t dev)
* bank 4: HME MIF registers
*
*/
- sc->sc_sebo = sc->sc_etxo = sc->sc_erxo = sc->sc_maco = sc->sc_mifo = 0;
hsc->hsc_seb_rid = 0;
hsc->hsc_seb_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
&hsc->hsc_seb_rid, RF_ACTIVE);
@@ -178,6 +177,7 @@ hme_sbus_attach(device_t dev)
&hsc->hsc_etx_rid, RF_ACTIVE);
if (hsc->hsc_etx_res == NULL) {
device_printf(dev, "cannot map ETX registers\n");
+ error = ENXIO;
goto fail_seb_res;
}
sc->sc_etxt = rman_get_bustag(hsc->hsc_etx_res);
@@ -188,6 +188,7 @@ hme_sbus_attach(device_t dev)
&hsc->hsc_erx_rid, RF_ACTIVE);
if (hsc->hsc_erx_res == NULL) {
device_printf(dev, "cannot map ERX registers\n");
+ error = ENXIO;
goto fail_etx_res;
}
sc->sc_erxt = rman_get_bustag(hsc->hsc_erx_res);
@@ -198,6 +199,7 @@ hme_sbus_attach(device_t dev)
&hsc->hsc_mac_rid, RF_ACTIVE);
if (hsc->hsc_mac_res == NULL) {
device_printf(dev, "cannot map MAC registers\n");
+ error = ENXIO;
goto fail_erx_res;
}
sc->sc_mact = rman_get_bustag(hsc->hsc_mac_res);
@@ -205,7 +207,7 @@ hme_sbus_attach(device_t dev)
/*
* At least on some HMEs, the MIF registers seem to be inside the MAC
- * range, so map try to kluge around it.
+ * range, so try to kludge around it.
*/
hsc->hsc_mif_rid = 4;
hsc->hsc_mif_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
@@ -214,18 +216,20 @@ hme_sbus_attach(device_t dev)
if (bus_get_resource(dev, SYS_RES_MEMORY, hsc->hsc_mif_rid,
&start, &count) != 0) {
device_printf(dev, "cannot get MIF registers\n");
+ error = ENXIO;
goto fail_mac_res;
}
if (start < rman_get_start(hsc->hsc_mac_res) ||
start + count - 1 > rman_get_end(hsc->hsc_mac_res)) {
device_printf(dev, "cannot move MIF registers to MAC "
"bank\n");
+ error = ENXIO;
goto fail_mac_res;
}
sc->sc_mift = sc->sc_mact;
- sc->sc_mifh = sc->sc_mach;
- sc->sc_mifo = sc->sc_maco + start -
- rman_get_start(hsc->hsc_mac_res);
+ bus_space_subregion(sc->sc_mact, sc->sc_mach,
+ start - rman_get_start(hsc->hsc_mac_res), count,
+ &sc->sc_mifh);
} else {
sc->sc_mift = rman_get_bustag(hsc->hsc_mif_res);
sc->sc_mifh = rman_get_bushandle(hsc->hsc_mif_res);
@@ -240,7 +244,6 @@ hme_sbus_attach(device_t dev)
goto fail_mif_res;
}
-
OF_getetheraddr(dev, sc->sc_arpcom.ac_enaddr);
burst = sbus_get_burstsz(dev);
@@ -262,7 +265,6 @@ hme_sbus_attach(device_t dev)
goto fail_ires;
}
-
if ((error = bus_setup_intr(dev, hsc->hsc_ires, INTR_TYPE_NET, hme_intr,
sc, &hsc->hsc_ih)) != 0) {
device_printf(dev, "couldn't establish interrupt\n");
@@ -290,7 +292,7 @@ fail_etx_res:
fail_seb_res:
bus_release_resource(dev, SYS_RES_MEMORY, hsc->hsc_seb_rid,
hsc->hsc_seb_res);
- return (ENXIO);
+ return (error);
}
static int
diff --git a/sys/dev/hme/if_hmevar.h b/sys/dev/hme/if_hmevar.h
index 4c65528..4482fd4 100644
--- a/sys/dev/hme/if_hmevar.h
+++ b/sys/dev/hme/if_hmevar.h
@@ -131,11 +131,6 @@ struct hme_softc {
bus_space_tag_t sc_etxt; /* HME ETX registers */
bus_space_tag_t sc_mact; /* HME MAC registers */
bus_space_tag_t sc_mift; /* HME MIF registers */
- bus_addr_t sc_sebo; /* HME Global registers */
- bus_addr_t sc_erxo; /* HME ERX registers */
- bus_addr_t sc_etxo; /* HME ETX registers */
- bus_addr_t sc_maco; /* HME MAC registers */
- bus_addr_t sc_mifo; /* HME MIF registers */
int sc_burst; /* DVMA burst size in effect */
int sc_phys[2]; /* MII instance -> PHY map */
OpenPOWER on IntegriCloud