Module Name:    src
Committed By:   tsutsui
Date:           Thu Apr  1 17:07:52 UTC 2010

Modified Files:
        src/sys/arch/atari/atari: autoconf.c
        src/sys/arch/atari/conf: GENERIC.in HADES.in MILAN.in files.atari
Added Files:
        src/sys/arch/atari/dev: if_ne_mb.c

Log Message:
Add support for the EtherNEC.

The EtherNEC is yet another user designed device for Atari machines,
an NE2000 based ISA board connected to Atari's ROM cartridge slot with
simple but ingenious interface and cartridge port adapter, and
it's the most available network solution for the old Atari machines.

See following pages for more details about EtherNEC:
http://hardware.atari.org/ether/
http://home.arcor.de/thomas.redelberger/prj/atari/etherne/
http://www.freemint.org/ethernec/ethernec.html


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/atari/atari/autoconf.c
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/atari/conf/GENERIC.in
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/atari/conf/HADES.in
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/atari/conf/MILAN.in
cvs rdiff -u -r1.116 -r1.117 src/sys/arch/atari/conf/files.atari
cvs rdiff -u -r0 -r1.1 src/sys/arch/atari/dev/if_ne_mb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/atari/atari/autoconf.c
diff -u src/sys/arch/atari/atari/autoconf.c:1.56 src/sys/arch/atari/atari/autoconf.c:1.57
--- src/sys/arch/atari/atari/autoconf.c:1.56	Sun Mar  8 05:25:30 2009
+++ src/sys/arch/atari/atari/autoconf.c	Thu Apr  1 17:07:51 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.56 2009/03/08 05:25:30 tsutsui Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.57 2010/04/01 17:07:51 tsutsui Exp $	*/
 
 /*
  * Copyright (c) 1995 Leo Weppelman
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.56 2009/03/08 05:25:30 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.57 2010/04/01 17:07:51 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -280,6 +280,7 @@
 	config_found(dp, __UNCONST("nvr")     , simple_devprint);
 	config_found(dp, __UNCONST("lpt")     , simple_devprint);
 	config_found(dp, __UNCONST("wdc")     , simple_devprint);
+	config_found(dp, __UNCONST("ne")      , simple_devprint);
 	config_found(dp, __UNCONST("isab")    , simple_devprint);
 	config_found(dp, __UNCONST("pcib")    , simple_devprint);
 	config_found(dp, __UNCONST("avmebus") , simple_devprint);

Index: src/sys/arch/atari/conf/GENERIC.in
diff -u src/sys/arch/atari/conf/GENERIC.in:1.84 src/sys/arch/atari/conf/GENERIC.in:1.85
--- src/sys/arch/atari/conf/GENERIC.in:1.84	Sat Mar 13 16:30:02 2010
+++ src/sys/arch/atari/conf/GENERIC.in	Thu Apr  1 17:07:51 2010
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: GENERIC.in,v 1.84 2010/03/13 16:30:02 tsutsui Exp $
+#	$NetBSD: GENERIC.in,v 1.85 2010/04/01 17:07:51 tsutsui Exp $
 #
 # Generic atari
 #
@@ -349,6 +349,7 @@
 ite2		at grfcc2	# 3rd tty
 lp0		at mainbus0	# centronics printer
 ser0		at mainbus0	# UART on first 68901 (ttyB0)
+ne0		at mainbus0	# EtherNEC on Atari ROM cartridge slot
 
 #if defined(TT030_KERNEL)
 avmebus0	at mainbus0	# VME bus

Index: src/sys/arch/atari/conf/HADES.in
diff -u src/sys/arch/atari/conf/HADES.in:1.9 src/sys/arch/atari/conf/HADES.in:1.10
--- src/sys/arch/atari/conf/HADES.in:1.9	Sat Jan 24 00:19:47 2009
+++ src/sys/arch/atari/conf/HADES.in	Thu Apr  1 17:07:51 2010
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: HADES.in,v 1.9 2009/01/24 00:19:47 abs Exp $
+#	$NetBSD: HADES.in,v 1.10 2010/04/01 17:07:51 tsutsui Exp $
 #
 # Medusa-Hades
 #
@@ -21,6 +21,7 @@
 nvr0		at mainbus0	# nvram driver
 lp0		at mainbus0	# centronics printer
 ser0		at mainbus0	# UART on first 68901 (ttyB0)
+ne0		at mainbus0	# EtherNEC on Atari ROM cartridge slot
 grfbus0		at mainbus0	# bitmapped display's
 grfet0		at grfbus0	# et4000/et6000/et6100 consoles
 ite0		at grfet0

Index: src/sys/arch/atari/conf/MILAN.in
diff -u src/sys/arch/atari/conf/MILAN.in:1.23 src/sys/arch/atari/conf/MILAN.in:1.24
--- src/sys/arch/atari/conf/MILAN.in:1.23	Wed Dec 23 09:17:41 2009
+++ src/sys/arch/atari/conf/MILAN.in	Thu Apr  1 17:07:51 2010
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: MILAN.in,v 1.23 2009/12/23 09:17:41 mbalmer Exp $
+#	$NetBSD: MILAN.in,v 1.24 2010/04/01 17:07:51 tsutsui Exp $
 #
 # Milan
 #
@@ -45,6 +45,7 @@
 pci0 		at pcib0
 nvr0 		at mainbus0			# nvram driver
 ser0 		at mainbus0
+ne0		at mainbus0			# EtherNEC
 fdcisa0 	at isa? port 0x3f0 irq 6 drq 2	# standard PC floppy contr.
 fdisa0 		at fdcisa0 drive 0
 

Index: src/sys/arch/atari/conf/files.atari
diff -u src/sys/arch/atari/conf/files.atari:1.116 src/sys/arch/atari/conf/files.atari:1.117
--- src/sys/arch/atari/conf/files.atari:1.116	Sat Mar 13 16:30:03 2010
+++ src/sys/arch/atari/conf/files.atari	Thu Apr  1 17:07:51 2010
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: files.atari,v 1.116 2010/03/13 16:30:03 tsutsui Exp $
+#	$NetBSD: files.atari,v 1.117 2010/04/01 17:07:51 tsutsui Exp $
 
 maxpartitions 16
 
@@ -182,6 +182,10 @@
 attach	wdc at mainbus with wdc_mb: mbdma
 file	arch/atari/dev/wdc_mb.c		wdc_mb
 
+# EtherNEC on Atari ROM cartridge slot
+attach	ne at mainbus with ne_mb: rtl80x9
+file	arch/atari/dev/if_ne_mb.c	ne_mb
+
 # ISA Plug 'n Play devices
 file	arch/atari/isa/isapnp_machdep.c	isapnp
 

Added files:

Index: src/sys/arch/atari/dev/if_ne_mb.c
diff -u /dev/null src/sys/arch/atari/dev/if_ne_mb.c:1.1
--- /dev/null	Thu Apr  1 17:07:52 2010
+++ src/sys/arch/atari/dev/if_ne_mb.c	Thu Apr  1 17:07:52 2010
@@ -0,0 +1,459 @@
+/*	$NetBSD: if_ne_mb.c,v 1.1 2010/04/01 17:07:52 tsutsui Exp $	*/
+
+/*
+ * Copyright (c) 2010 Izumi Tsutsui.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Device driver for the EtherNEC,
+ * NE2000 in 8bit mode over Atari ROM cartridge slot.
+ * http://hardware.atari.org/ether/
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: if_ne_mb.c,v 1.1 2010/04/01 17:07:52 tsutsui Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <sys/callout.h>
+
+#include <sys/bus.h>
+#include <sys/intr.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_ether.h>
+#include <net/if_media.h>
+
+#include <machine/cpu.h>
+#include <machine/iomap.h>
+
+#include <atari/atari/device.h>
+
+#include <dev/ic/dp8390reg.h>
+#include <dev/ic/dp8390var.h>
+#include <dev/ic/ne2000reg.h>
+#include <dev/ic/ne2000var.h>
+
+/*
+ * EtherNEC specific address configuration
+ */
+
+/* I/O read ops are through /ROM4 area (0xFA0000) */
+#define AD_CART_ROM4		(AD_CART + 0x00000)
+#define ETHERNEC_READ_PORT	AD_CART_ROM4
+
+/* I/O write ops are through /ROM3 area (0xFB0000) */
+#define AD_CART_ROM3		(AD_CART + 0x10000)
+#define ETHERNEC_WRITE_PORT	AD_CART_ROM3
+
+/* CPU address lines A13-A9 are connected to ISA A4-A0 */
+#define ETHERNEC_PORT_STRIDE	9
+
+/* Using A8-A1 lines to specify write data (no A0 but UDS/LDS on m68k) */
+#define ETHERNEC_WR_ADDR_SHIFT	1
+
+/* interrupt polling per HZ */
+#define ETHERNEC_TICK		1
+
+static int  ne_mb_probe(device_t, cfdata_t, void *);
+static void ne_mb_attach(device_t, device_t, void *);
+
+static void ne_mb_poll(void *);
+
+static bus_space_tag_t ethernec_init_bus_space_tag(bus_space_tag_t);
+static void    ethernec_bus_space_unimpl(void);
+
+static int     ethernec_bus_space_peek_1(bus_space_tag_t, bus_space_handle_t,
+    bus_size_t);
+static uint8_t ethernec_bus_space_read_1(bus_space_tag_t, bus_space_handle_t,
+    bus_size_t);
+static void    ethernec_bus_space_write_1(bus_space_tag_t, bus_space_handle_t,
+    bus_size_t, uint8_t);
+static void    ethernec_bus_space_read_multi_1(bus_space_tag_t,
+    bus_space_handle_t, bus_size_t, uint8_t *, bus_size_t);
+static void    ethernec_bus_space_read_multi_2(bus_space_tag_t,
+    bus_space_handle_t, bus_size_t, uint16_t *, bus_size_t);
+static void    ethernec_bus_space_write_multi_1(bus_space_tag_t,
+    bus_space_handle_t, bus_size_t, const uint8_t *, bus_size_t);
+static void    ethernec_bus_space_write_multi_2(bus_space_tag_t,
+    bus_space_handle_t, bus_size_t, const uint16_t *, bus_size_t);
+
+struct ne_mb_softc {
+	struct ne2000_softc sc_ne2000;		/* MI ne2000 softc */
+
+	struct atari_bus_space sc_bs;
+	struct callout sc_poll;
+};
+
+CFATTACH_DECL_NEW(ne_mb, sizeof(struct ne_mb_softc),
+    ne_mb_probe, ne_mb_attach, NULL, NULL);
+
+static int
+ne_mb_probe(device_t parent, cfdata_t cf, void *aux)
+{
+	static bool ne_matched = false;
+	struct atari_bus_space bs;
+	bus_space_tag_t iot, asict;
+	bus_space_handle_t ioh, iowh, asich;
+	int netype, rv;
+
+	rv = 0;
+
+	if (!atari_realconfig)
+		goto out;
+	if (strcmp("ne", aux) || ne_matched)
+		goto out;
+
+	iot = ethernec_init_bus_space_tag(&bs);
+
+	/* map I/O space for read ops */
+	if (bus_space_map(iot, ETHERNEC_READ_PORT,
+	    NE2000_NPORTS << ETHERNEC_PORT_STRIDE, 0, &ioh) != 0)
+		goto out;
+
+	/* map I/O space for write ops */
+	if (bus_space_map(iot, ETHERNEC_WRITE_PORT,
+	    NE2000_NPORTS << ETHERNEC_PORT_STRIDE, 0, &iowh) != 0)
+		goto out1;
+
+	/* XXX abuse stride for offset of write ports from read ones */
+	iot->stride =
+	    (vaddr_t)bus_space_vaddr(iot, iowh) -
+	    (vaddr_t)bus_space_vaddr(iot, ioh);
+
+	/* check if register regions are vaild */
+	if (bus_space_peek_1(iot, ioh, 0) == 0)
+		goto out2;
+
+	asict = iot;
+	if (bus_space_subregion(iot, ioh,
+	    NE2000_ASIC_OFFSET << ETHERNEC_PORT_STRIDE,
+	    NE2000_ASIC_NPORTS << ETHERNEC_PORT_STRIDE, &asich))
+		goto out2;
+
+	/* Look for an NE2000 compatible card */
+	netype = ne2000_detect(iot, ioh, asict, asich);
+	switch (netype) {
+	/* XXX should we reject non RTL8019 variants? */
+	case NE2000_TYPE_NE1000:
+	case NE2000_TYPE_NE2000:
+	case NE2000_TYPE_RTL8019:
+		ne_matched = true;
+		rv = 1;
+		break;
+	default:
+		break;
+	}
+
+ out2:
+	bus_space_unmap(iot, iowh, NE2000_NPORTS << ETHERNEC_PORT_STRIDE);
+ out1:
+	bus_space_unmap(iot, ioh, NE2000_NPORTS << ETHERNEC_PORT_STRIDE);
+ out:
+	return rv;
+}
+
+static void
+ne_mb_attach(device_t parent, device_t self, void *aux)
+{
+	struct ne_mb_softc *sc = device_private(self);
+	struct ne2000_softc *nsc = &sc->sc_ne2000;
+	struct dp8390_softc *dsc = &nsc->sc_dp8390;
+	bus_space_tag_t iot, asict;
+	bus_space_handle_t ioh, iowh, asich;
+	const char *typestr;
+	int netype;
+
+	dsc->sc_dev = self;
+	aprint_normal(": EtherNEC on Atari ROM cartridge slot\n");
+
+	iot = ethernec_init_bus_space_tag(&sc->sc_bs);
+
+	/* map I/O space for read ops */
+	if (bus_space_map(iot, ETHERNEC_READ_PORT,
+	    NE2000_NPORTS << ETHERNEC_PORT_STRIDE, 0, &ioh) != 0)
+		goto out;
+
+	/* map I/O space for write ops */
+	if (bus_space_map(iot, ETHERNEC_WRITE_PORT,
+	    NE2000_NPORTS << ETHERNEC_PORT_STRIDE, 0, &iowh) != 0)
+		goto out1;
+
+	/* XXX abuse stride */
+	iot->stride =
+	    (vaddr_t)bus_space_vaddr(iot, iowh) -
+	    (vaddr_t)bus_space_vaddr(iot, ioh);
+
+	asict = iot;
+	if (bus_space_subregion(iot, ioh,
+	    NE2000_ASIC_OFFSET << ETHERNEC_PORT_STRIDE,
+	    NE2000_ASIC_NPORTS << ETHERNEC_PORT_STRIDE, &asich))
+		goto out2;
+
+	dsc->sc_regt = iot;
+	dsc->sc_regh = ioh;
+
+	nsc->sc_asict = asict;
+	nsc->sc_asich = asich;
+
+	/* EtherNEC uses 8-bit data bus */
+	nsc->sc_quirk = NE2000_QUIRK_8BIT;
+
+	/*
+	 * detect it again, so we can print some information about
+	 * the interface.
+	 * XXX: Should we accept only RTL8019?
+	 */
+	netype = ne2000_detect(iot, ioh, asict, asich);
+	switch (netype) {
+	case NE2000_TYPE_NE1000:
+		typestr = "NE1000";
+		break;
+
+	case NE2000_TYPE_NE2000:
+		typestr = "NE2000";
+		break;
+
+	case NE2000_TYPE_RTL8019:
+		typestr = "NE2000 (RTL8019)";
+		break;
+
+	default:
+		aprint_error_dev(self, "where did the card go?!\n");
+		goto out2;
+	}
+
+	aprint_normal_dev(self, "%s Ethernet (8-bit)\n", typestr);
+
+	/* this interface is always enabled */
+	dsc->sc_enabled = 1;
+
+	/* call MI ne2000 attach function */
+	ne2000_attach(nsc, NULL);
+
+	/* emulate interrupts by callout(9) */
+	aprint_normal_dev(self, "using %d Hz polling\n", hz / ETHERNEC_TICK);
+	callout_init(&sc->sc_poll, 0);
+	callout_reset(&sc->sc_poll, ETHERNEC_TICK, ne_mb_poll, sc);
+
+	return;
+
+ out2:
+	bus_space_unmap(iot, iowh, NE2000_NPORTS << ETHERNEC_PORT_STRIDE);
+ out1:
+	bus_space_unmap(iot, ioh, NE2000_NPORTS << ETHERNEC_PORT_STRIDE);
+ out:
+	return;
+}
+
+static void
+ne_mb_poll(void *arg)
+{
+	struct ne_mb_softc *sc;
+	struct ne2000_softc *nsc;
+	struct dp8390_softc *dsc;
+	int s;
+
+	sc = arg;
+	nsc = &sc->sc_ne2000;
+	dsc = &nsc->sc_dp8390;
+
+	s = splnet();
+	(void)dp8390_intr(dsc);
+	splx(s);
+
+	callout_reset(&sc->sc_poll, ETHERNEC_TICK, ne_mb_poll, sc);
+}
+
+/*
+ * bus_space(9) functions for EtherNEC
+ *
+ *  XXX: should these belong to an independent cartridge slot bus?
+ */
+static bus_space_tag_t
+ethernec_init_bus_space_tag(bus_space_tag_t en_t)
+{
+
+	if (en_t == NULL)
+		return NULL;
+
+	memset(en_t, 0, sizeof(*en_t));
+
+	/* XXX: implement functions used by MI ne2000 and dp8390 only */
+	en_t->abs_p_1   = ethernec_bus_space_peek_1;
+	en_t->abs_p_2   = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_p_4   = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_p_8   = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_r_1   = ethernec_bus_space_read_1;
+	en_t->abs_r_2   = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_r_4   = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_r_8   = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rs_1  = ethernec_bus_space_read_1;
+	en_t->abs_rs_2  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rs_4  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rs_8  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rm_1  = ethernec_bus_space_read_multi_1;
+	en_t->abs_rm_2  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rm_4  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rm_8  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rms_1 = ethernec_bus_space_read_multi_1;
+	en_t->abs_rms_2 = ethernec_bus_space_read_multi_2;	/* XXX dummy */
+	en_t->abs_rms_4 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rms_8 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rr_1  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rr_2  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rr_4  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rr_8  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rrs_1 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rrs_2 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rrs_4 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_rrs_8 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_w_1   = ethernec_bus_space_write_1;
+	en_t->abs_w_2   = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_w_4   = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_w_8   = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_ws_1  = ethernec_bus_space_write_1;
+	en_t->abs_ws_2  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_ws_4  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_ws_8  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wm_1  = ethernec_bus_space_write_multi_1;
+	en_t->abs_wm_2  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wm_4  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wm_8  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wms_1 = ethernec_bus_space_write_multi_1;
+	en_t->abs_wms_2 = ethernec_bus_space_write_multi_2;	/* XXX dummy */
+	en_t->abs_wms_4 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wms_8 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wr_1  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wr_2  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wr_4  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wr_8  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wrs_1 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wrs_2 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wrs_4 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_wrs_8 = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_sm_1  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_sm_2  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_sm_4  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_sm_8  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_sr_1  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_sr_2  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_sr_4  = (void *)ethernec_bus_space_unimpl;
+	en_t->abs_sr_8  = (void *)ethernec_bus_space_unimpl;
+
+	return en_t;
+}
+
+static void
+ethernec_bus_space_unimpl(void)
+{
+
+	panic("%s: unimplemented EtherNEC bus_space(9) function called",
+	    __func__);
+}
+
+static int
+ethernec_bus_space_peek_1(bus_space_tag_t bt, bus_space_handle_t bh,
+    bus_size_t reg)
+{
+	uint8_t *va;
+
+	va = (uint8_t *)(bh + (reg << ETHERNEC_PORT_STRIDE));
+
+	return !badbaddr(va, sizeof(uint8_t));
+}
+
+static uint8_t
+ethernec_bus_space_read_1(bus_space_tag_t bt, bus_space_handle_t bh,
+    bus_size_t reg)
+{
+	volatile uint8_t *ba;
+
+	ba = (volatile uint8_t *)(bh + (reg << ETHERNEC_PORT_STRIDE));
+
+	return *ba;
+}
+
+static void
+ethernec_bus_space_write_1(bus_space_tag_t bt, bus_space_handle_t bh,
+    bus_size_t reg, uint8_t val)
+{
+	volatile uint8_t *wport;
+
+	/*
+	 * Write ops are done by read against write region (ROM3) address.
+	 * 8-bit write data is specified via lower address bits.
+	 */
+	wport = (volatile uint8_t *)(bh +
+	    bt->stride + (reg << ETHERNEC_PORT_STRIDE));
+	wport += (u_int)val << ETHERNEC_WR_ADDR_SHIFT;
+
+	(void)*wport;
+}
+
+static void
+ethernec_bus_space_read_multi_1(bus_space_tag_t bt, bus_space_handle_t bh,
+    bus_size_t reg, uint8_t *a, bus_size_t c)
+{
+	volatile uint8_t *ba;
+
+	ba = (volatile uint8_t *)(bh + (reg << ETHERNEC_PORT_STRIDE));
+	for (; c != 0; c--)
+		*a++ = *ba;
+}
+
+static void
+ethernec_bus_space_read_multi_2(bus_space_tag_t bt, bus_space_handle_t bh,
+    bus_size_t reg, uint16_t *a, bus_size_t c)
+{
+
+	/* XXX: dummy function for probe ops in ne2000_detect() */
+}
+
+static void
+ethernec_bus_space_write_multi_1(bus_space_tag_t bt, bus_space_handle_t bh,
+    bus_size_t reg, const uint8_t *a, bus_size_t c)
+{
+	volatile uint8_t *ba, *wport;
+	u_int val;
+
+	ba = (volatile uint8_t *)(bh +
+	    bt->stride + (reg << ETHERNEC_PORT_STRIDE));
+
+	for (; c != 0; c--) {
+		val = *a++;
+		wport = ba + (val << ETHERNEC_WR_ADDR_SHIFT);
+		(void)*wport;
+	}
+}
+
+static void
+ethernec_bus_space_write_multi_2(bus_space_tag_t bt, bus_space_handle_t bh,
+    bus_size_t reg, const uint16_t *a, bus_size_t c)
+{
+
+	/* XXX: dummy function for probe ops in ne2000_detect() */
+}

Reply via email to