Home | History | Annotate | Line # | Download | only in isa
      1  1.36   thorpej /*	$NetBSD: if_ai.c,v 1.36 2022/07/12 02:03:57 thorpej Exp $	*/
      2   1.1        pk 
      3   1.1        pk /*-
      4   1.1        pk  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5   1.1        pk  * All rights reserved.
      6   1.1        pk  *
      7   1.1        pk  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1        pk  * by Rafal K. Boni.
      9   1.1        pk  *
     10   1.1        pk  * Redistribution and use in source and binary forms, with or without
     11   1.1        pk  * modification, are permitted provided that the following conditions
     12   1.1        pk  * are met:
     13   1.1        pk  * 1. Redistributions of source code must retain the above copyright
     14   1.1        pk  *    notice, this list of conditions and the following disclaimer.
     15   1.1        pk  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1        pk  *    notice, this list of conditions and the following disclaimer in the
     17   1.1        pk  *    documentation and/or other materials provided with the distribution.
     18   1.1        pk  *
     19   1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1        pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1        pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1        pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1        pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1        pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1        pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1        pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1        pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1        pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1        pk  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1        pk  */
     31  1.12     lukem 
     32  1.12     lukem #include <sys/cdefs.h>
     33  1.36   thorpej __KERNEL_RCSID(0, "$NetBSD: if_ai.c,v 1.36 2022/07/12 02:03:57 thorpej Exp $");
     34   1.1        pk 
     35   1.1        pk #include <sys/param.h>
     36   1.1        pk #include <sys/systm.h>
     37   1.1        pk #include <sys/mbuf.h>
     38   1.1        pk #include <sys/errno.h>
     39   1.1        pk #include <sys/device.h>
     40   1.1        pk #include <sys/protosw.h>
     41   1.1        pk #include <sys/socket.h>
     42   1.1        pk 
     43   1.1        pk #include <net/if.h>
     44   1.1        pk #include <net/if_dl.h>
     45   1.1        pk #include <net/if_types.h>
     46   1.1        pk #include <net/if_media.h>
     47   1.1        pk #include <net/if_ether.h>
     48   1.1        pk 
     49  1.26        ad #include <sys/cpu.h>
     50  1.26        ad #include <sys/bus.h>
     51  1.26        ad #include <sys/intr.h>
     52   1.1        pk 
     53   1.1        pk #include <dev/isa/isareg.h>
     54   1.1        pk #include <dev/isa/isavar.h>
     55   1.1        pk 
     56   1.1        pk #include <dev/ic/i82586reg.h>
     57   1.1        pk #include <dev/ic/i82586var.h>
     58   1.1        pk #include <dev/isa/if_aireg.h>
     59   1.1        pk 
     60   1.1        pk #ifdef AI_DEBUG
     61   1.1        pk #define DPRINTF(x)	printf x
     62   1.1        pk #else
     63   1.2        pk #define DPRINTF(x)
     64   1.1        pk #endif
     65   1.1        pk 
     66   1.1        pk struct ai_softc {
     67   1.1        pk 	struct ie_softc sc_ie;
     68   1.1        pk 
     69   1.1        pk 	bus_space_tag_t sc_regt;	/* space tag for registers */
     70   1.1        pk 	bus_space_handle_t sc_regh;	/* space handle for registers */
     71   1.1        pk 
     72  1.34   msaitoh 	uint8_t	card_rev;
     73  1.34   msaitoh 	uint8_t	card_type;
     74   1.1        pk 
     75   1.2        pk 	void		*sc_ih;		/* interrupt handle */
     76   1.1        pk };
     77   1.1        pk 
     78  1.34   msaitoh static const char *ai_names[] = {
     79   1.1        pk         "StarLAN 10",
     80   1.1        pk         "EN100",
     81   1.1        pk         "StarLAN Fiber",
     82   1.1        pk };
     83   1.1        pk 
     84   1.1        pk /* Functions required by the i82586 MI driver */
     85  1.20     perry static void 	ai_reset(struct ie_softc *, int);
     86  1.20     perry static void 	ai_atten(struct ie_softc *, int);
     87   1.1        pk 
     88  1.20     perry static void	ai_copyin(struct ie_softc *, void *, int, size_t);
     89  1.20     perry static void	ai_copyout(struct ie_softc *, const void *, int, size_t);
     90   1.2        pk 
     91  1.34   msaitoh static uint16_t ai_read_16(struct ie_softc *, int);
     92  1.34   msaitoh static void	ai_write_16(struct ie_softc *, int, uint16_t);
     93  1.20     perry static void	ai_write_24(struct ie_softc *, int, int);
     94   1.2        pk 
     95   1.1        pk /* Local support functions */
     96  1.20     perry static int 	check_ie_present(struct ie_softc*, bus_space_tag_t,
     97  1.20     perry 					bus_space_handle_t, bus_size_t);
     98  1.20     perry static int	ai_find_mem_size(struct ai_softc*, bus_space_tag_t,
     99  1.20     perry 					bus_size_t);
    100   1.1        pk 
    101  1.34   msaitoh static int	ai_match(device_t, cfdata_t, void *);
    102  1.34   msaitoh static void	ai_attach(device_t, device_t, void *);
    103   1.1        pk 
    104   1.1        pk /*
    105   1.1        pk  * AT&T StarLan support routines
    106   1.1        pk  */
    107   1.1        pk static void
    108  1.29       dsl ai_reset(struct ie_softc *sc, int why)
    109   1.1        pk {
    110  1.34   msaitoh 	struct ai_softc *asc = (struct ai_softc *)sc;
    111   1.1        pk 
    112   1.2        pk 	switch (why) {
    113   1.2        pk 	case CHIP_PROBE:
    114  1.34   msaitoh 		/* Reset to chip to see if it responds */
    115   1.2        pk 		bus_space_write_1(asc->sc_regt, asc->sc_regh, AI_RESET, 0);
    116   1.2        pk 		DELAY(100);
    117   1.2        pk 		break;
    118   1.2        pk 
    119   1.2        pk 	case CARD_RESET:
    120   1.2        pk 		/*
    121  1.34   msaitoh 		 * This takes around 10sec, and we can get
    122   1.2        pk 		 * by quite well w/out it...
    123   1.2        pk 		 */
    124   1.2        pk 		break;
    125   1.2        pk 	}
    126   1.1        pk }
    127   1.1        pk 
    128   1.1        pk static void
    129  1.25  christos ai_atten(struct ie_softc *sc, int why)
    130   1.1        pk {
    131  1.34   msaitoh 	struct ai_softc *asc = (struct ai_softc *)sc;
    132  1.34   msaitoh 
    133  1.34   msaitoh 	bus_space_write_1(asc->sc_regt, asc->sc_regh, AI_ATTN, 0);
    134   1.1        pk }
    135   1.1        pk 
    136   1.1        pk static void
    137  1.34   msaitoh ai_copyin(struct ie_softc *sc, void *dst, int offset, size_t size)
    138   1.1        pk {
    139   1.2        pk 	int dribble;
    140  1.34   msaitoh 	uint8_t *bptr = dst;
    141   1.1        pk 
    142   1.2        pk 	if (offset % 2) {
    143   1.2        pk 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    144   1.2        pk 		offset++; bptr++; size--;
    145   1.2        pk 	}
    146   1.2        pk 
    147   1.2        pk 	dribble = size % 2;
    148  1.34   msaitoh 	bus_space_read_region_2(sc->bt, sc->bh, offset, (uint16_t *)bptr,
    149  1.34   msaitoh 	    size >> 1);
    150   1.2        pk 
    151   1.2        pk 	if (dribble) {
    152   1.2        pk 		bptr += size - 1;
    153   1.2        pk 		offset += size - 1;
    154   1.2        pk 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    155   1.2        pk 	}
    156   1.1        pk }
    157   1.1        pk 
    158   1.1        pk static void
    159  1.34   msaitoh ai_copyout(struct ie_softc *sc, const void *src, int offset, size_t size)
    160   1.1        pk {
    161   1.2        pk 	int dribble;
    162  1.34   msaitoh 	const uint8_t *bptr = src;
    163   1.2        pk 
    164   1.2        pk 	if (offset % 2) {
    165   1.2        pk 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    166   1.2        pk 		offset++; bptr++; size--;
    167   1.2        pk 	}
    168   1.2        pk 
    169   1.2        pk 	dribble = size % 2;
    170  1.22  christos 	bus_space_write_region_2(sc->bt, sc->bh, offset,
    171  1.34   msaitoh 	    (const uint16_t *)bptr, size >> 1);
    172   1.2        pk 	if (dribble) {
    173   1.2        pk 		bptr += size - 1;
    174   1.2        pk 		offset += size - 1;
    175   1.2        pk 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    176   1.2        pk 	}
    177   1.1        pk }
    178   1.1        pk 
    179  1.34   msaitoh static uint16_t
    180  1.34   msaitoh ai_read_16(struct ie_softc *sc, int offset)
    181   1.1        pk {
    182  1.34   msaitoh 
    183   1.1        pk         return bus_space_read_2(sc->bt, sc->bh, offset);
    184   1.1        pk }
    185   1.1        pk 
    186   1.1        pk static void
    187  1.34   msaitoh ai_write_16(struct ie_softc *sc, int offset, uint16_t value)
    188   1.1        pk {
    189  1.34   msaitoh 
    190   1.1        pk         bus_space_write_2(sc->bt, sc->bh, offset, value);
    191   1.1        pk }
    192   1.1        pk 
    193   1.1        pk static void
    194  1.34   msaitoh ai_write_24(struct ie_softc *sc, int offset, int addr)
    195   1.1        pk {
    196  1.34   msaitoh 
    197   1.1        pk         bus_space_write_4(sc->bt, sc->bh, offset, addr +
    198  1.34   msaitoh 	    (u_long)sc->sc_maddr - (u_long)sc->sc_iobase);
    199   1.1        pk }
    200   1.1        pk 
    201   1.1        pk int
    202  1.32    cegger ai_match(device_t parent, cfdata_t cf, void *aux)
    203   1.1        pk {
    204   1.2        pk 	int rv = 0;
    205  1.34   msaitoh 	uint8_t val, type;
    206   1.2        pk 	bus_size_t memsize;
    207   1.3        pk 	bus_space_tag_t iot;
    208   1.2        pk 	bus_space_handle_t ioh;
    209   1.2        pk 	struct isa_attach_args * const ia = aux;
    210   1.3        pk 	struct ai_softc asc;
    211   1.2        pk 
    212  1.14   thorpej 	if (ia->ia_nio < 1)
    213  1.34   msaitoh 		return 0;
    214  1.14   thorpej 	if (ia->ia_niomem < 1)
    215  1.34   msaitoh 		return 0;
    216  1.14   thorpej 	if (ia->ia_nirq < 1)
    217  1.34   msaitoh 		return 0;
    218  1.14   thorpej 
    219  1.14   thorpej 	if (ISA_DIRECT_CONFIG(ia))
    220  1.34   msaitoh 		return 0;
    221   1.2        pk 
    222   1.2        pk 	/* Punt if wildcarded port, IRQ or memory address */
    223  1.19  drochner 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT ||
    224  1.19  drochner 	    ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM ||
    225  1.19  drochner 	    ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) {
    226   1.2        pk 		DPRINTF((
    227   1.2        pk 		 "ai_match: wildcarded IRQ, IOAddr, or memAddr, skipping\n"));
    228  1.34   msaitoh 		return 0;
    229   1.2        pk 	}
    230   1.2        pk 
    231   1.3        pk 	iot = ia->ia_iot;
    232   1.3        pk 
    233   1.2        pk 	/*
    234   1.2        pk 	 * This probe is horribly bad, but I have no info on this card other
    235   1.2        pk 	 * than the former driver, and it was just as bad!
    236   1.2        pk 	 */
    237  1.14   thorpej 	if (bus_space_map(iot, ia->ia_io[0].ir_addr,
    238   1.2        pk 			  AI_IOSIZE, 0, &ioh) != 0) {
    239   1.2        pk 
    240   1.2        pk 		DPRINTF(("ai_match: cannot map %d IO ports @ 0x%x\n",
    241  1.35   msaitoh 			 AI_IOSIZE, ia->ia_io[0].ir_addr));
    242  1.34   msaitoh 		return 0;
    243   1.2        pk 	}
    244   1.2        pk 
    245   1.3        pk 	val = bus_space_read_1(iot, ioh, AI_REVISION);
    246   1.2        pk 
    247   1.2        pk 	type = SL_BOARD(val);
    248   1.5        pk 	if (type != SL10_BOARD && type != EN100_BOARD &&
    249   1.2        pk 	    type != SLFIBER_BOARD) {
    250   1.2        pk 		DPRINTF(("ai_match: unknown board code 0x%02x @ 0x%x\n",
    251  1.35   msaitoh 			 type, ia->ia_io[0].ir_addr));
    252   1.2        pk 		goto out;
    253   1.2        pk 	}
    254   1.1        pk 
    255   1.3        pk 	/*
    256   1.3        pk 	 * Fill in just about enough of our local `ai_softc' for
    257   1.3        pk 	 * ai_find_mem_size() to do its job.
    258   1.3        pk 	 */
    259  1.11   thorpej 	memset(&asc, 0, sizeof asc);
    260   1.3        pk 	asc.sc_regt = iot;
    261   1.3        pk 	asc.sc_regh = ioh;
    262   1.1        pk 
    263  1.14   thorpej 	if ((memsize = ai_find_mem_size(&asc, ia->ia_memt,
    264  1.14   thorpej 	     ia->ia_iomem[0].ir_addr)) == 0) {
    265   1.2        pk 		DPRINTF(("ai_match: cannot size memory of board @ 0x%x\n",
    266  1.14   thorpej 			 ia->ia_io[0].ir_addr));
    267   1.3        pk 		goto out;
    268   1.2        pk 	}
    269   1.1        pk 
    270  1.14   thorpej 	if (ia->ia_iomem[0].ir_size != 0 &&
    271  1.14   thorpej 	    ia->ia_iomem[0].ir_size != memsize) {
    272   1.2        pk 		DPRINTF((
    273   1.2        pk 		   "ai_match: memsize of board @ 0x%x doesn't match config\n",
    274  1.35   msaitoh 		   ia->ia_io[0].ir_addr));
    275   1.2        pk 		goto out;
    276   1.2        pk 	}
    277   1.2        pk 
    278   1.2        pk 	rv = 1;
    279  1.14   thorpej 
    280  1.14   thorpej 	ia->ia_nio = 1;
    281  1.14   thorpej 	ia->ia_io[0].ir_size = AI_IOSIZE;
    282  1.14   thorpej 
    283  1.14   thorpej 	ia->ia_niomem = 1;
    284  1.14   thorpej 	ia->ia_iomem[0].ir_size = memsize;
    285  1.14   thorpej 
    286  1.14   thorpej 	ia->ia_nirq = 1;
    287  1.14   thorpej 
    288  1.14   thorpej 	ia->ia_ndrq = 0;
    289  1.14   thorpej 
    290  1.35   msaitoh 	DPRINTF(("ai_match: found board @ 0x%x\n", ia->ia_io[0].ir_addr));
    291   1.1        pk 
    292   1.1        pk out:
    293   1.3        pk 	bus_space_unmap(iot, ioh, AI_IOSIZE);
    294   1.2        pk 	return rv;
    295   1.1        pk }
    296   1.1        pk 
    297   1.1        pk void
    298  1.32    cegger ai_attach(device_t parent, device_t self, void *aux)
    299   1.1        pk {
    300  1.33   tsutsui 	struct ai_softc *asc = device_private(self);
    301   1.2        pk 	struct ie_softc *sc = &asc->sc_ie;
    302   1.2        pk 	struct isa_attach_args *ia = aux;
    303  1.34   msaitoh 	uint8_t val = 0;
    304   1.2        pk 	bus_space_handle_t ioh, memh;
    305  1.34   msaitoh 	uint8_t ethaddr[ETHER_ADDR_LEN];
    306   1.5        pk 	char name[80];
    307   1.2        pk 
    308  1.33   tsutsui 	sc->sc_dev = self;
    309  1.33   tsutsui 
    310  1.14   thorpej 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr,
    311  1.14   thorpej 			  ia->ia_io[0].ir_size, 0, &ioh) != 0) {
    312   1.2        pk 		DPRINTF(("\n%s: can't map i/o space 0x%x-0x%x\n",
    313  1.33   tsutsui 			 device_xname(self),
    314  1.14   thorpej 		         ia->ia_io[0].ir_addr, ia->ia_io[0].ir_addr +
    315  1.14   thorpej 		         ia->ia_io[0].ir_size - 1));
    316   1.2        pk 		return;
    317   1.2        pk 	}
    318   1.2        pk 
    319  1.14   thorpej 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr,
    320  1.14   thorpej 			  ia->ia_iomem[0].ir_size, 0, &memh) != 0) {
    321   1.2        pk 		DPRINTF(("\n%s: can't map iomem space 0x%x-0x%x\n",
    322  1.33   tsutsui 			 device_xname(self),
    323  1.14   thorpej 			 ia->ia_iomem[0].ir_addr, ia->ia_iomem[0].ir_addr +
    324  1.14   thorpej 			 ia->ia_iomem[0].ir_size - 1));
    325  1.14   thorpej 		bus_space_unmap(ia->ia_iot, ioh, ia->ia_io[0].ir_size);
    326   1.2        pk 		return;
    327   1.2        pk 	}
    328   1.2        pk 
    329   1.2        pk 	asc->sc_regt = ia->ia_iot;
    330   1.2        pk 	asc->sc_regh = ioh;
    331   1.2        pk 
    332   1.2        pk 	sc->hwinit = NULL;
    333   1.2        pk 	sc->intrhook = NULL;
    334   1.2        pk 	sc->hwreset = ai_reset;
    335   1.2        pk 	sc->chan_attn = ai_atten;
    336   1.9     bjh21 
    337   1.9     bjh21 	sc->ie_bus_barrier = NULL;
    338   1.2        pk 
    339   1.2        pk 	sc->memcopyin = ai_copyin;
    340   1.2        pk 	sc->memcopyout = ai_copyout;
    341   1.2        pk 	sc->ie_bus_read16 = ai_read_16;
    342   1.2        pk 	sc->ie_bus_write16 = ai_write_16;
    343   1.2        pk 	sc->ie_bus_write24 = ai_write_24;
    344   1.2        pk 
    345   1.2        pk 	sc->do_xmitnopchain = 0;
    346   1.2        pk 
    347   1.2        pk 	sc->sc_mediachange = NULL;
    348   1.2        pk 	sc->sc_mediastatus = NULL;
    349   1.2        pk 
    350   1.2        pk 	sc->bt = ia->ia_memt;
    351   1.2        pk 	sc->bh = memh;
    352   1.2        pk 
    353   1.2        pk 	/* Map i/o space. */
    354  1.14   thorpej 	sc->sc_msize = ia->ia_iomem[0].ir_size;
    355   1.7  augustss 	sc->sc_maddr = (void *)memh;
    356   1.7  augustss 	sc->sc_iobase = (char *)sc->sc_maddr + sc->sc_msize - (1 << 24);
    357   1.2        pk 
    358  1.34   msaitoh 	/* Set up pointers to important on-card control structures */
    359   1.2        pk 	sc->iscp = 0;
    360   1.2        pk 	sc->scb = IE_ISCP_SZ;
    361   1.2        pk 	sc->scp = sc->sc_msize + IE_SCP_ADDR - (1 << 24);
    362   1.2        pk 
    363   1.2        pk 	sc->buf_area = sc->scb + IE_SCB_SZ;
    364   1.2        pk 	sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ;
    365   1.2        pk 
    366  1.34   msaitoh 	/* Zero card memory */
    367   1.2        pk 	bus_space_set_region_1(sc->bt, sc->bh, 0, 0, sc->sc_msize);
    368   1.2        pk 
    369  1.34   msaitoh 	/* Set card to 16-bit bus mode */
    370  1.21     perry 	bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp),
    371  1.34   msaitoh 	    IE_SYSBUS_16BIT);
    372   1.2        pk 
    373  1.34   msaitoh 	/* Set up pointers to key structures */
    374  1.34   msaitoh 	ai_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long)sc->iscp);
    375  1.34   msaitoh 	ai_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long)sc->scb);
    376  1.34   msaitoh 	ai_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long)sc->iscp);
    377   1.2        pk 
    378  1.34   msaitoh 	/* Flush setup of pointers, check if chip answers */
    379   1.2        pk 	if (!i82586_proberam(sc)) {
    380   1.2        pk 		DPRINTF(("\n%s: can't talk to i82586!\n",
    381  1.33   tsutsui 			device_xname(self)));
    382  1.14   thorpej 		bus_space_unmap(ia->ia_iot, ioh, ia->ia_io[0].ir_size);
    383  1.14   thorpej 		bus_space_unmap(ia->ia_memt, memh, ia->ia_iomem[0].ir_size);
    384   1.2        pk 		return;
    385   1.2        pk 	}
    386   1.2        pk 
    387   1.2        pk 	val = bus_space_read_1(asc->sc_regt, asc->sc_regh, AI_REVISION);
    388   1.2        pk 	asc->card_rev = SL_REV(val);
    389   1.2        pk 	asc->card_type = SL_BOARD(val) - 1;
    390  1.18    itojun 	snprintf(name, sizeof(name), "%s, rev. %d",
    391  1.18    itojun 	    ai_names[asc->card_type], asc->card_rev);
    392   1.2        pk 
    393   1.5        pk 	i82586_attach(sc, name, ethaddr, NULL, 0, 0);
    394   1.2        pk 
    395  1.14   thorpej 	asc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    396  1.14   thorpej 	    IST_EDGE, IPL_NET, i82586_intr, sc);
    397   1.2        pk 	if (asc->sc_ih == NULL) {
    398   1.2        pk 		DPRINTF(("\n%s: can't establish interrupt\n",
    399  1.33   tsutsui 			device_xname(self)));
    400   1.2        pk 	}
    401   1.1        pk }
    402   1.1        pk 
    403   1.1        pk /*
    404   1.1        pk  * Divine the memory size of this board.
    405   1.1        pk  * Better hope there's nothing important hiding just below the card...
    406   1.1        pk  */
    407   1.1        pk static int
    408  1.29       dsl ai_find_mem_size(struct ai_softc* asc, bus_space_tag_t memt, bus_size_t maddr)
    409   1.1        pk {
    410   1.1        pk 	int size;
    411   1.1        pk 	bus_space_handle_t memh;
    412  1.34   msaitoh 	struct ie_softc *sc = &asc->sc_ie;
    413   1.1        pk 
    414   1.1        pk 	for (size = 65536; size >= 16384; size -= 16384) {
    415   1.2        pk 		if (bus_space_map(memt, maddr, size, 0, &memh) == 0) {
    416   1.2        pk 			size = check_ie_present(sc, memt, maddr, size);
    417   1.2        pk 			bus_space_unmap(memt, memh, size);
    418   1.2        pk 
    419   1.2        pk 			if (size != 0)
    420   1.2        pk 				return size;
    421   1.2        pk 		}
    422   1.1        pk 	}
    423   1.1        pk 
    424  1.34   msaitoh 	return 0;
    425   1.1        pk }
    426   1.1        pk 
    427   1.1        pk /*
    428   1.1        pk  * Check to see if there's an 82586 out there.
    429   1.1        pk  */
    430   1.1        pk static int
    431  1.34   msaitoh check_ie_present(struct ie_softc* sc, bus_space_tag_t memt,
    432  1.34   msaitoh     bus_space_handle_t memh, bus_size_t size)
    433   1.1        pk {
    434  1.34   msaitoh 
    435   1.2        pk 	sc->hwreset = ai_reset;
    436   1.2        pk 	sc->chan_attn = ai_atten;
    437   1.2        pk 	sc->ie_bus_read16 = ai_read_16;
    438   1.2        pk 	sc->ie_bus_write16 = ai_write_16;
    439   1.2        pk 
    440   1.2        pk 	sc->bt = memt;
    441   1.2        pk 	sc->bh = memh;
    442   1.7  augustss 	sc->sc_iobase = (char *)memh + size - (1 << 24);
    443   1.2        pk 
    444   1.2        pk 	sc->scp = size + IE_SCP_ADDR - (1 << 24);
    445  1.34   msaitoh 	bus_space_set_region_1(memt, memh, (u_long)sc->scp, 0, IE_SCP_SZ);
    446   1.2        pk 
    447   1.2        pk 	sc->iscp = 0;
    448  1.34   msaitoh 	bus_space_set_region_1(memt, memh, (u_long)sc->iscp, 0, IE_ISCP_SZ);
    449   1.2        pk 
    450   1.2        pk 	sc->scb = IE_ISCP_SZ;
    451   1.2        pk 	bus_space_set_region_1(memt, memh, sc->scb, 0, IE_SCB_SZ);
    452   1.2        pk 
    453  1.34   msaitoh 	/* Set card to 16-bit bus mode */
    454  1.13  fredette 	bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp),
    455  1.34   msaitoh 	    IE_SYSBUS_16BIT);
    456   1.2        pk 
    457  1.34   msaitoh 	/* Set up pointers to key structures */
    458  1.34   msaitoh 	ai_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long)sc->iscp);
    459  1.34   msaitoh 	ai_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long)sc->scb);
    460  1.34   msaitoh 	ai_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long)sc->iscp);
    461   1.2        pk 
    462  1.34   msaitoh 	/* Flush setup of pointers, check if chip answers */
    463   1.2        pk 	if (!i82586_proberam(sc))
    464  1.34   msaitoh 		return 0;
    465   1.1        pk 
    466  1.34   msaitoh 	return size;
    467   1.1        pk }
    468   1.1        pk 
    469  1.33   tsutsui CFATTACH_DECL_NEW(ai, sizeof(struct ai_softc),
    470  1.17   thorpej     ai_match, ai_attach, NULL, NULL);
    471