Home | History | Annotate | Line # | Download | only in vme
if_we_vme.c revision 1.1.2.1
      1  1.1.2.1    rmind /*	$NetBSD: if_we_vme.c,v 1.1.2.1 2010/05/30 05:16:41 rmind Exp $	*/
      2      1.1  tsutsui 
      3      1.1  tsutsui /*-
      4      1.1  tsutsui  * Copyright (c) 1997, 1998, 2010 The NetBSD Foundation, Inc.
      5      1.1  tsutsui  * All rights reserved.
      6      1.1  tsutsui  *
      7      1.1  tsutsui  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1  tsutsui  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9      1.1  tsutsui  * NASA Ames Research Center.
     10      1.1  tsutsui  *
     11      1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
     12      1.1  tsutsui  * modification, are permitted provided that the following conditions
     13      1.1  tsutsui  * are met:
     14      1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     15      1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     16      1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     17      1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     18      1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     19      1.1  tsutsui  *
     20      1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21      1.1  tsutsui  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22      1.1  tsutsui  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23      1.1  tsutsui  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24      1.1  tsutsui  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25      1.1  tsutsui  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26      1.1  tsutsui  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27      1.1  tsutsui  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28      1.1  tsutsui  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29      1.1  tsutsui  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30      1.1  tsutsui  * POSSIBILITY OF SUCH DAMAGE.
     31      1.1  tsutsui  */
     32      1.1  tsutsui 
     33      1.1  tsutsui /*
     34      1.1  tsutsui  * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
     35      1.1  tsutsui  * adapters.
     36      1.1  tsutsui  *
     37      1.1  tsutsui  * Copyright (c) 1994, 1995 Charles M. Hannum.  All rights reserved.
     38      1.1  tsutsui  *
     39      1.1  tsutsui  * Copyright (C) 1993, David Greenman.  This software may be used, modified,
     40      1.1  tsutsui  * copied, distributed, and sold, in both source and binary form provided that
     41      1.1  tsutsui  * the above copyright and these terms are retained.  Under no circumstances is
     42      1.1  tsutsui  * the author responsible for the proper functioning of this software, nor does
     43      1.1  tsutsui  * the author assume any responsibility for damages incurred with its use.
     44      1.1  tsutsui  */
     45      1.1  tsutsui 
     46      1.1  tsutsui /*
     47      1.1  tsutsui  * Device driver for the SMC Elite Ultra (8216) with SMC_TT VME-ISA bridge.
     48      1.1  tsutsui  * Based on:
     49      1.1  tsutsui  *	NetBSD: if_we_isa.c,v 1.20 2008/04/28 20:23:52 martin Exp
     50      1.1  tsutsui  */
     51      1.1  tsutsui 
     52      1.1  tsutsui #include <sys/cdefs.h>
     53  1.1.2.1    rmind __KERNEL_RCSID(0, "$NetBSD: if_we_vme.c,v 1.1.2.1 2010/05/30 05:16:41 rmind Exp $");
     54      1.1  tsutsui 
     55      1.1  tsutsui #include <sys/param.h>
     56      1.1  tsutsui #include <sys/systm.h>
     57      1.1  tsutsui #include <sys/device.h>
     58      1.1  tsutsui #include <sys/socket.h>
     59      1.1  tsutsui #include <sys/mbuf.h>
     60      1.1  tsutsui #include <sys/syslog.h>
     61      1.1  tsutsui 
     62      1.1  tsutsui #include <net/if.h>
     63      1.1  tsutsui #include <net/if_dl.h>
     64      1.1  tsutsui #include <net/if_types.h>
     65      1.1  tsutsui #include <net/if_media.h>
     66      1.1  tsutsui 
     67      1.1  tsutsui #include <net/if_ether.h>
     68      1.1  tsutsui 
     69      1.1  tsutsui #include <sys/bus.h>
     70      1.1  tsutsui #include <sys/intr.h>
     71      1.1  tsutsui 
     72      1.1  tsutsui #include <machine/cpu.h>
     73      1.1  tsutsui #include <machine/iomap.h>
     74      1.1  tsutsui #include <machine/scu.h>
     75      1.1  tsutsui 
     76      1.1  tsutsui #include <atari/vme/vmevar.h>
     77      1.1  tsutsui 
     78      1.1  tsutsui #include <dev/ic/dp8390reg.h>
     79      1.1  tsutsui #include <dev/ic/dp8390var.h>
     80      1.1  tsutsui #include <dev/ic/wereg.h>
     81      1.1  tsutsui #include <dev/ic/wevar.h>
     82      1.1  tsutsui 
     83      1.1  tsutsui /* #define WE_DEBUG */
     84      1.1  tsutsui #ifdef WE_DEBUG
     85      1.1  tsutsui #define DPRINTF(x)	printf x
     86      1.1  tsutsui #else
     87      1.1  tsutsui #define DPRINTF(x)	/**/
     88      1.1  tsutsui #endif
     89      1.1  tsutsui 
     90      1.1  tsutsui /* VME space mapped by SMC_TT VME-ISA bridge */
     91      1.1  tsutsui #define SMCTT_MEM_BASE	0xFE000000	/* base for shared memory space */
     92      1.1  tsutsui #define SMCTT_IOE_BASE	0xFE200000	/* base for I/O ports at even address */
     93      1.1  tsutsui #define SMCTT_IOO_BASE	0xFE300000	/* base for I/O ports at odd address */
     94      1.1  tsutsui 
     95      1.1  tsutsui #define SMCTT_IO_OFFSET	(SMCTT_IOO_BASE - SMCTT_IOE_BASE)
     96      1.1  tsutsui 
     97      1.1  tsutsui /* default SMC8216 settings for SMC_TT specified by a jumper switch at No.2 */
     98      1.1  tsutsui #define SMCTT_MEM_ADDR	0xD0000
     99      1.1  tsutsui #define SMCTT_IO_ADDR	0x280
    100      1.1  tsutsui 
    101      1.1  tsutsui /* SMC_TT uses IRQ4 on VME, IRQ3 on ISA, and interrupt vector 0xAA */
    102      1.1  tsutsui #define SMCTT_VME_IRQ	4
    103      1.1  tsutsui #define SMCTT_ISA_IRQ	3
    104      1.1  tsutsui #define SMCTT_VECTOR	0xAA
    105      1.1  tsutsui 
    106      1.1  tsutsui static int we_vme_probe(device_t, cfdata_t , void *);
    107      1.1  tsutsui static void we_vme_attach(device_t, device_t, void *);
    108      1.1  tsutsui 
    109      1.1  tsutsui static uint8_t smctt_bus_space_read_1(bus_space_tag_t, bus_space_handle_t,
    110      1.1  tsutsui     bus_size_t);
    111      1.1  tsutsui static void    smctt_bus_space_write_1(bus_space_tag_t, bus_space_handle_t,
    112      1.1  tsutsui     bus_size_t, uint8_t);
    113  1.1.2.1    rmind static int     smctt_bus_space_peek_1(bus_space_tag_t, bus_space_handle_t,
    114  1.1.2.1    rmind     bus_size_t);
    115      1.1  tsutsui 
    116      1.1  tsutsui struct we_vme_softc {
    117      1.1  tsutsui 	struct we_softc	sc_we;
    118      1.1  tsutsui 	struct atari_bus_space sc_bs;
    119      1.1  tsutsui };
    120      1.1  tsutsui 
    121      1.1  tsutsui CFATTACH_DECL_NEW(we_vme, sizeof(struct we_vme_softc),
    122      1.1  tsutsui     we_vme_probe, we_vme_attach, NULL, NULL);
    123      1.1  tsutsui 
    124      1.1  tsutsui static const int we_790_irq[] = {
    125      1.1  tsutsui 	-1, 9, 3, 5, 7, 10, 11, 15,
    126      1.1  tsutsui };
    127      1.1  tsutsui 
    128      1.1  tsutsui static int
    129      1.1  tsutsui we_vme_probe(device_t parent, cfdata_t cf, void *aux)
    130      1.1  tsutsui {
    131      1.1  tsutsui 	struct vme_attach_args *va = aux;
    132      1.1  tsutsui 	struct atari_bus_space t;
    133      1.1  tsutsui 	bus_space_tag_t asict, memt;
    134      1.1  tsutsui 	bus_space_handle_t asich, asich1, memh;
    135      1.1  tsutsui 	bus_size_t memsize;
    136      1.1  tsutsui 	bool asich_valid, asich1_valid, memh_valid;
    137      1.1  tsutsui 	int i, rv;
    138      1.1  tsutsui 	uint8_t sum, reg, type, hwr;
    139      1.1  tsutsui 
    140      1.1  tsutsui 	rv = 0;
    141      1.1  tsutsui 	asich_valid = false;
    142      1.1  tsutsui 	asich1_valid = false;
    143      1.1  tsutsui 	memh_valid = false;
    144      1.1  tsutsui 
    145      1.1  tsutsui 	if (va->va_iobase != IOBASEUNK &&
    146      1.1  tsutsui 	    va->va_iobase != SMCTT_IOE_BASE + SMCTT_IO_ADDR)
    147      1.1  tsutsui 		return 0;
    148      1.1  tsutsui 	if (va->va_maddr != IOBASEUNK &&
    149      1.1  tsutsui 	    va->va_maddr != SMCTT_MEM_BASE + SMCTT_MEM_ADDR)
    150      1.1  tsutsui 		return 0;
    151      1.1  tsutsui 	if (va->va_irq != IRQUNK &&
    152      1.1  tsutsui 	    va->va_irq != SMCTT_VME_IRQ)
    153      1.1  tsutsui 		return 0;
    154      1.1  tsutsui 
    155      1.1  tsutsui 	/* SMC_TT has a bit weird I/O address mappings */
    156      1.1  tsutsui 	asict = beb_alloc_bus_space_tag(&t);
    157      1.1  tsutsui 	/* XXX setup only simple byte functions used in MI we(4) driver */
    158      1.1  tsutsui 	asict->abs_r_1 = smctt_bus_space_read_1;
    159      1.1  tsutsui 	asict->abs_w_1 = smctt_bus_space_write_1;
    160  1.1.2.1    rmind 	asict->abs_p_1 = smctt_bus_space_peek_1;
    161      1.1  tsutsui 
    162      1.1  tsutsui 	/*
    163      1.1  tsutsui 	 * Only 16 bit accesses are allowed for memory space on SMC_TT,
    164      1.1  tsutsui 	 * but MI we(4) uses them on 16 bit mode.
    165      1.1  tsutsui 	 */
    166      1.1  tsutsui 	memt = va->va_memt;
    167      1.1  tsutsui 
    168      1.1  tsutsui 	/* Attempt to map the device. */
    169      1.1  tsutsui 	if (bus_space_map(asict, SMCTT_IOE_BASE + SMCTT_IO_ADDR, WE_NPORTS,
    170      1.1  tsutsui 	    0, &asich) != 0) {
    171      1.1  tsutsui 		DPRINTF(("%s: failed to map even I/O space", __func__));
    172      1.1  tsutsui 		goto out;
    173      1.1  tsutsui 	}
    174      1.1  tsutsui 	asich_valid = true;
    175      1.1  tsutsui 
    176      1.1  tsutsui 	if (bus_space_map(asict, SMCTT_IOO_BASE + SMCTT_IO_ADDR, WE_NPORTS,
    177      1.1  tsutsui 	    0, &asich1) != 0) {
    178      1.1  tsutsui 		DPRINTF(("%s: failed to map odd I/O space", __func__));
    179      1.1  tsutsui 		goto out;
    180      1.1  tsutsui 	}
    181      1.1  tsutsui 	asich1_valid = true;
    182      1.1  tsutsui 
    183      1.1  tsutsui 	/* XXX abuse stride for offset of odd ports from even ones */
    184      1.1  tsutsui 	asict->stride =
    185      1.1  tsutsui 	    (vaddr_t)bus_space_vaddr(asict, asich1) -
    186      1.1  tsutsui 	    (vaddr_t)bus_space_vaddr(asict, asich);
    187      1.1  tsutsui 
    188  1.1.2.1    rmind 	/* check if register regions are valid */
    189  1.1.2.1    rmind 	if (bus_space_peek_1(asict, asich, WE_PROM + 0) == 0 ||
    190  1.1.2.1    rmind 	    bus_space_peek_1(asict, asich, WE_PROM + 1) == 0)
    191  1.1.2.1    rmind 		goto out;
    192  1.1.2.1    rmind 
    193      1.1  tsutsui 	/*
    194      1.1  tsutsui 	 * Attempt to do a checksum over the station address PROM.
    195      1.1  tsutsui 	 * If it fails, it's probably not an SMC_TT board.
    196      1.1  tsutsui 	 */
    197      1.1  tsutsui 	DPRINTF(("%s: WE_PROM: ", __func__));
    198      1.1  tsutsui 	sum = 0;
    199      1.1  tsutsui 	for (i = 0; i < 8; i++) {
    200      1.1  tsutsui 		reg = bus_space_read_1(asict, asich, WE_PROM + i);
    201      1.1  tsutsui 		DPRINTF(("%02x ", reg));
    202      1.1  tsutsui 		sum += reg;
    203      1.1  tsutsui 	}
    204      1.1  tsutsui 	DPRINTF(("\n"));
    205      1.1  tsutsui 	DPRINTF(("%s: WE_ROM_SUM: 0x%02x\n", __func__, sum));
    206      1.1  tsutsui 
    207      1.1  tsutsui 	if (sum != WE_ROM_CHECKSUM_TOTAL)
    208      1.1  tsutsui 		goto out;
    209      1.1  tsutsui 
    210      1.1  tsutsui 	/*
    211      1.1  tsutsui 	 * Reset the card to force it into a known state.
    212      1.1  tsutsui 	 */
    213      1.1  tsutsui 	bus_space_write_1(asict, asich, WE_MSR, WE_MSR_RST);
    214      1.1  tsutsui 	delay(100);
    215      1.1  tsutsui 
    216      1.1  tsutsui 	bus_space_write_1(asict, asich, WE_MSR,
    217      1.1  tsutsui 	    bus_space_read_1(asict, asich, WE_MSR) & ~WE_MSR_RST);
    218      1.1  tsutsui 
    219      1.1  tsutsui 	/* Wait in case the card is reading it's EEPROM. */
    220      1.1  tsutsui 	delay(5000);
    221      1.1  tsutsui 
    222      1.1  tsutsui 	/*
    223      1.1  tsutsui 	 * Check card type.
    224      1.1  tsutsui 	 */
    225      1.1  tsutsui 	type = bus_space_read_1(asict, asich, WE_CARD_ID);
    226      1.1  tsutsui 	/* Assume SMT_TT has only 8216 */
    227      1.1  tsutsui 	if (type != WE_TYPE_SMC8216C && type != WE_TYPE_SMC8216T)
    228      1.1  tsutsui 		goto out;
    229      1.1  tsutsui 
    230      1.1  tsutsui 	hwr = bus_space_read_1(asict, asich, WE790_HWR);
    231      1.1  tsutsui 	bus_space_write_1(asict, asich, WE790_HWR, hwr | WE790_HWR_SWH);
    232      1.1  tsutsui 	switch (bus_space_read_1(asict, asich, WE790_RAR) & WE790_RAR_SZ64) {
    233      1.1  tsutsui 	case WE790_RAR_SZ64:
    234      1.1  tsutsui 		memsize = 65536;
    235      1.1  tsutsui 		break;
    236      1.1  tsutsui 	case WE790_RAR_SZ32:
    237      1.1  tsutsui 		memsize = 32768;
    238      1.1  tsutsui 		break;
    239      1.1  tsutsui 	case WE790_RAR_SZ16:
    240      1.1  tsutsui 		memsize = 16384;
    241      1.1  tsutsui 		break;
    242      1.1  tsutsui 	case WE790_RAR_SZ8:
    243      1.1  tsutsui 		memsize = 8192;
    244      1.1  tsutsui 		break;
    245      1.1  tsutsui 	default:
    246      1.1  tsutsui 		memsize = 16384;
    247      1.1  tsutsui 		break;
    248      1.1  tsutsui 	}
    249      1.1  tsutsui 	bus_space_write_1(asict, asich, WE790_HWR, hwr);
    250      1.1  tsutsui 
    251      1.1  tsutsui 	/* Attempt to map the memory space. */
    252      1.1  tsutsui 	if (bus_space_map(memt, SMCTT_MEM_BASE + SMCTT_MEM_ADDR, memsize,
    253      1.1  tsutsui 	    0, &memh) != 0) {
    254      1.1  tsutsui 		DPRINTF(("%s: failed to map shared memory", __func__));
    255      1.1  tsutsui 		goto out;
    256      1.1  tsutsui 	}
    257      1.1  tsutsui 	memh_valid = true;
    258      1.1  tsutsui 
    259  1.1.2.1    rmind 	/* check if memory region is valid */
    260  1.1.2.1    rmind 	if (bus_space_peek_2(memt, memh, 0) == 0)
    261  1.1.2.1    rmind 		goto out;
    262  1.1.2.1    rmind 
    263      1.1  tsutsui 	/*
    264      1.1  tsutsui 	 * Check the assigned interrupt number from the card.
    265      1.1  tsutsui 	 */
    266      1.1  tsutsui 
    267      1.1  tsutsui 	/* Assemble together the encoded interrupt number. */
    268      1.1  tsutsui 	hwr = bus_space_read_1(asict, asich, WE790_HWR);
    269      1.1  tsutsui 	bus_space_write_1(asict, asich, WE790_HWR, hwr | WE790_HWR_SWH);
    270      1.1  tsutsui 
    271      1.1  tsutsui 	reg = bus_space_read_1(asict, asich, WE790_GCR);
    272      1.1  tsutsui 	i = ((reg & WE790_GCR_IR2) >> 4) |
    273      1.1  tsutsui 	    ((reg & (WE790_GCR_IR1|WE790_GCR_IR0)) >> 2);
    274      1.1  tsutsui 	bus_space_write_1(asict, asich, WE790_HWR, hwr & ~WE790_HWR_SWH);
    275      1.1  tsutsui 
    276      1.1  tsutsui 	if (we_790_irq[i] != SMCTT_ISA_IRQ) {
    277      1.1  tsutsui 		DPRINTF(("%s: wrong IRQ (%d); check jumper settings\n",
    278      1.1  tsutsui 		    __func__, we_790_irq[i]));
    279      1.1  tsutsui 		goto out;
    280      1.1  tsutsui 	}
    281      1.1  tsutsui 
    282      1.1  tsutsui 	/* So, we say we've found it! */
    283      1.1  tsutsui 	va->va_iobase = SMCTT_IOE_BASE + SMCTT_IO_ADDR;
    284      1.1  tsutsui 	va->va_iosize = WE_NPORTS;
    285      1.1  tsutsui 	va->va_maddr = SMCTT_MEM_BASE + SMCTT_MEM_ADDR;
    286      1.1  tsutsui 	va->va_msize = memsize;
    287      1.1  tsutsui 	va->va_irq = SMCTT_VME_IRQ;
    288      1.1  tsutsui 
    289      1.1  tsutsui 	rv = 1;
    290      1.1  tsutsui 
    291      1.1  tsutsui  out:
    292      1.1  tsutsui 	if (asich_valid)
    293      1.1  tsutsui 		bus_space_unmap(asict, asich, WE_NPORTS);
    294      1.1  tsutsui 	if (asich1_valid)
    295      1.1  tsutsui 		bus_space_unmap(asict, asich1, WE_NPORTS);
    296      1.1  tsutsui 	if (memh_valid)
    297      1.1  tsutsui 		bus_space_unmap(memt, memh, memsize);
    298      1.1  tsutsui 	return rv;
    299      1.1  tsutsui }
    300      1.1  tsutsui 
    301      1.1  tsutsui void
    302      1.1  tsutsui we_vme_attach(device_t parent, device_t self, void *aux)
    303      1.1  tsutsui {
    304      1.1  tsutsui 	struct we_vme_softc *wvsc = device_private(self);
    305      1.1  tsutsui 	struct we_softc *wsc = &wvsc->sc_we;
    306      1.1  tsutsui 	struct dp8390_softc *sc = &wsc->sc_dp8390;
    307      1.1  tsutsui 	struct vme_attach_args *va = aux;
    308      1.1  tsutsui 	bus_space_tag_t nict, asict, memt;
    309      1.1  tsutsui 	bus_space_handle_t nich, asich, asich1, memh;
    310      1.1  tsutsui 	const char *typestr;
    311      1.1  tsutsui 
    312      1.1  tsutsui 	aprint_normal("\n");
    313      1.1  tsutsui 
    314      1.1  tsutsui 	sc->sc_dev = self;
    315      1.1  tsutsui 
    316      1.1  tsutsui 	/* See comments in the above probe function */
    317      1.1  tsutsui 	asict = beb_alloc_bus_space_tag(&wvsc->sc_bs);
    318      1.1  tsutsui 	asict->abs_r_1 = smctt_bus_space_read_1;
    319      1.1  tsutsui 	asict->abs_w_1 = smctt_bus_space_write_1;
    320      1.1  tsutsui 	nict = asict;
    321      1.1  tsutsui 
    322      1.1  tsutsui 	memt = va->va_memt;
    323      1.1  tsutsui 
    324      1.1  tsutsui 	/* Map the device. */
    325      1.1  tsutsui 	if (bus_space_map(asict, va->va_iobase, WE_NPORTS, 0, &asich) != 0) {
    326      1.1  tsutsui 		aprint_error_dev(self, "can't map even I/O space\n");
    327      1.1  tsutsui 		return;
    328      1.1  tsutsui 	}
    329      1.1  tsutsui 	if (bus_space_map(asict, va->va_iobase + SMCTT_IO_OFFSET, WE_NPORTS,
    330      1.1  tsutsui 	    0, &asich1) != 0) {
    331      1.1  tsutsui 		aprint_error_dev(self, "can't map odd I/O space\n");
    332      1.1  tsutsui 		goto out;
    333      1.1  tsutsui 	}
    334      1.1  tsutsui 	asict->stride =
    335      1.1  tsutsui 	    (vaddr_t)bus_space_vaddr(asict, asich1) -
    336      1.1  tsutsui 	    (vaddr_t)bus_space_vaddr(asict, asich);
    337      1.1  tsutsui 
    338      1.1  tsutsui 	if (bus_space_subregion(asict, asich, WE_NIC_OFFSET, WE_NIC_NPORTS,
    339      1.1  tsutsui 	    &nich) != 0) {
    340      1.1  tsutsui 		aprint_error_dev(self, "can't subregion I/O space\n");
    341      1.1  tsutsui 		goto out1;
    342      1.1  tsutsui 	}
    343      1.1  tsutsui 
    344      1.1  tsutsui 	/* Map memory space. */
    345      1.1  tsutsui 	if (bus_space_map(memt, va->va_maddr, va->va_msize, 0, &memh) != 0) {
    346      1.1  tsutsui 		aprint_error_dev(self, "can't map shared memory\n");
    347      1.1  tsutsui 		goto out1;
    348      1.1  tsutsui 	}
    349      1.1  tsutsui 
    350      1.1  tsutsui 	wsc->sc_asict = asict;
    351      1.1  tsutsui 	wsc->sc_asich = asich;
    352      1.1  tsutsui 
    353      1.1  tsutsui 	sc->sc_regt = nict;
    354      1.1  tsutsui 	sc->sc_regh = nich;
    355      1.1  tsutsui 
    356      1.1  tsutsui 	sc->sc_buft = memt;
    357      1.1  tsutsui 	sc->sc_bufh = memh;
    358      1.1  tsutsui 
    359      1.1  tsutsui 	wsc->sc_maddr = va->va_maddr & 0xfffff;
    360      1.1  tsutsui 	sc->mem_size = va->va_msize;
    361      1.1  tsutsui 
    362      1.1  tsutsui 	/* Interface is always enabled. */
    363      1.1  tsutsui 	sc->sc_enabled = 1;
    364      1.1  tsutsui 
    365      1.1  tsutsui 	/* SMC_TT assumes SMC8216 */
    366      1.1  tsutsui 	sc->is790 = 1;
    367      1.1  tsutsui 
    368      1.1  tsutsui 	/* SMC_TT supports only 16 bit access for shared memory */
    369      1.1  tsutsui 	wsc->sc_flags |= WE_16BIT_ENABLE;
    370      1.1  tsutsui 
    371      1.1  tsutsui 	/* Appeal the Atari spirit :-) */
    372      1.1  tsutsui 	typestr = "SMC8216 with SMC_TT VME-ISA bridge";
    373      1.1  tsutsui 
    374      1.1  tsutsui 	if (we_config(self, wsc, typestr) != 0)
    375      1.1  tsutsui 		goto out2;
    376      1.1  tsutsui 
    377      1.1  tsutsui 	/*
    378      1.1  tsutsui 	 * Enable the configured interrupt.
    379      1.1  tsutsui 	 */
    380      1.1  tsutsui 	bus_space_write_1(asict, asich, WE790_ICR,
    381      1.1  tsutsui 	    bus_space_read_1(asict, asich, WE790_ICR) | WE790_ICR_EIL);
    382      1.1  tsutsui 
    383      1.1  tsutsui 	/* Establish interrupt handler. */
    384      1.1  tsutsui 	wsc->sc_ih = intr_establish(SMCTT_VECTOR - 64, USER_VEC, 0,
    385      1.1  tsutsui 	    (hw_ifun_t)dp8390_intr, sc);
    386      1.1  tsutsui 	if (wsc->sc_ih == NULL) {
    387      1.1  tsutsui 		aprint_error_dev(self, "can't establish interrupt\n");
    388      1.1  tsutsui 		goto out2;
    389      1.1  tsutsui 	}
    390      1.1  tsutsui 	/*
    391      1.1  tsutsui 	 * Unmask the VME interrupt we're on.
    392      1.1  tsutsui 	 */
    393      1.1  tsutsui 	if ((machineid & ATARI_TT) != 0)
    394      1.1  tsutsui 		SCU->vme_mask |= 1 << va->va_irq;
    395      1.1  tsutsui 
    396      1.1  tsutsui 	return;
    397      1.1  tsutsui 
    398      1.1  tsutsui  out2:
    399      1.1  tsutsui 		bus_space_unmap(memt, memh, va->va_msize);
    400      1.1  tsutsui  out1:
    401      1.1  tsutsui 		bus_space_unmap(asict, asich1, WE_NPORTS);
    402      1.1  tsutsui  out:
    403      1.1  tsutsui 		bus_space_unmap(asict, asich, WE_NPORTS);
    404      1.1  tsutsui }
    405      1.1  tsutsui 
    406      1.1  tsutsui static uint8_t
    407      1.1  tsutsui smctt_bus_space_read_1(bus_space_tag_t bt, bus_space_handle_t bh,
    408      1.1  tsutsui     bus_size_t reg)
    409      1.1  tsutsui {
    410      1.1  tsutsui 	uint8_t rv;
    411      1.1  tsutsui 
    412      1.1  tsutsui 	if ((reg & 0x01) != 0) {
    413      1.1  tsutsui 		/* odd address space */
    414      1.1  tsutsui 		rv = *(volatile uint8_t *)(bh + bt->stride + (reg & ~0x01));
    415      1.1  tsutsui 	} else {
    416      1.1  tsutsui 		/* even address space */
    417      1.1  tsutsui 		rv = *(volatile uint8_t *)(bh + reg);
    418      1.1  tsutsui 	}
    419      1.1  tsutsui 
    420      1.1  tsutsui 	return rv;
    421      1.1  tsutsui }
    422      1.1  tsutsui 
    423      1.1  tsutsui static void
    424      1.1  tsutsui smctt_bus_space_write_1(bus_space_tag_t bt, bus_space_handle_t bh,
    425      1.1  tsutsui     bus_size_t reg, uint8_t val)
    426      1.1  tsutsui {
    427      1.1  tsutsui 
    428      1.1  tsutsui 	if ((reg & 0x01) != 0) {
    429      1.1  tsutsui 		/* odd address space */
    430      1.1  tsutsui 		*(volatile uint8_t *)(bh + bt->stride + (reg & ~0x01)) = val;
    431      1.1  tsutsui 	} else {
    432      1.1  tsutsui 		/* even address space */
    433      1.1  tsutsui 		*(volatile uint8_t *)(bh + reg) = val;
    434      1.1  tsutsui 	}
    435      1.1  tsutsui }
    436  1.1.2.1    rmind 
    437  1.1.2.1    rmind static int
    438  1.1.2.1    rmind smctt_bus_space_peek_1(bus_space_tag_t bt, bus_space_handle_t bh,
    439  1.1.2.1    rmind     bus_size_t reg)
    440  1.1.2.1    rmind {
    441  1.1.2.1    rmind 	uint8_t *va;
    442  1.1.2.1    rmind 
    443  1.1.2.1    rmind 	if ((reg & 0x01) != 0) {
    444  1.1.2.1    rmind 		/* odd address space */
    445  1.1.2.1    rmind 		va = (uint8_t *)(bh + bt->stride + (reg & ~0x01));
    446  1.1.2.1    rmind 	} else {
    447  1.1.2.1    rmind 		/* even address space */
    448  1.1.2.1    rmind 		va = (uint8_t *)(bh + reg);
    449  1.1.2.1    rmind 	}
    450  1.1.2.1    rmind 
    451  1.1.2.1    rmind 	return !badbaddr(va, sizeof(uint8_t));
    452  1.1.2.1    rmind }
    453