Home | History | Annotate | Line # | Download | only in isa
i82365_isa.c revision 1.10
      1  1.10  sommerfe /*	$NetBSD: i82365_isa.c,v 1.10 1998/06/07 18:28:31 sommerfe Exp $	*/
      2   1.2   thorpej 
      3   1.2   thorpej #define	PCICISADEBUG
      4   1.2   thorpej 
      5   1.2   thorpej /*
      6   1.2   thorpej  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      7   1.2   thorpej  *
      8   1.2   thorpej  * Redistribution and use in source and binary forms, with or without
      9   1.2   thorpej  * modification, are permitted provided that the following conditions
     10   1.2   thorpej  * are met:
     11   1.2   thorpej  * 1. Redistributions of source code must retain the above copyright
     12   1.2   thorpej  *    notice, this list of conditions and the following disclaimer.
     13   1.2   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.2   thorpej  *    notice, this list of conditions and the following disclaimer in the
     15   1.2   thorpej  *    documentation and/or other materials provided with the distribution.
     16   1.2   thorpej  * 3. All advertising materials mentioning features or use of this software
     17   1.2   thorpej  *    must display the following acknowledgement:
     18   1.2   thorpej  *	This product includes software developed by Marc Horowitz.
     19   1.2   thorpej  * 4. The name of the author may not be used to endorse or promote products
     20   1.2   thorpej  *    derived from this software without specific prior written permission.
     21   1.2   thorpej  *
     22   1.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23   1.2   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24   1.2   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25   1.2   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26   1.2   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27   1.2   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28   1.2   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29   1.2   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30   1.2   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31   1.2   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32   1.2   thorpej  */
     33   1.2   thorpej 
     34   1.2   thorpej #include <sys/types.h>
     35   1.2   thorpej #include <sys/param.h>
     36   1.2   thorpej #include <sys/systm.h>
     37   1.2   thorpej #include <sys/device.h>
     38   1.2   thorpej #include <sys/extent.h>
     39   1.2   thorpej #include <sys/malloc.h>
     40   1.2   thorpej 
     41   1.2   thorpej #include <vm/vm.h>
     42   1.2   thorpej 
     43   1.2   thorpej #include <machine/bus.h>
     44   1.2   thorpej #include <machine/intr.h>
     45   1.2   thorpej 
     46   1.2   thorpej #include <dev/isa/isareg.h>
     47   1.2   thorpej #include <dev/isa/isavar.h>
     48   1.2   thorpej 
     49   1.2   thorpej #include <dev/pcmcia/pcmciareg.h>
     50   1.2   thorpej #include <dev/pcmcia/pcmciavar.h>
     51   1.2   thorpej #include <dev/pcmcia/pcmciachip.h>
     52   1.2   thorpej 
     53   1.2   thorpej #include <dev/ic/i82365reg.h>
     54   1.2   thorpej #include <dev/ic/i82365var.h>
     55  1.10  sommerfe #include <dev/isa/i82365_isavar.h>
     56   1.6   thorpej 
     57   1.2   thorpej #ifdef PCICISADEBUG
     58   1.2   thorpej int	pcicisa_debug = 0 /* XXX */ ;
     59   1.2   thorpej #define	DPRINTF(arg) if (pcicisa_debug) printf arg;
     60   1.2   thorpej #else
     61   1.2   thorpej #define	DPRINTF(arg)
     62   1.2   thorpej #endif
     63   1.2   thorpej 
     64   1.8  drochner #ifdef __BROKEN_INDIRECT_CONFIG
     65   1.2   thorpej int	pcic_isa_probe __P((struct device *, void *, void *));
     66   1.8  drochner #else
     67   1.8  drochner int	pcic_isa_probe __P((struct device *, struct cfdata *, void *));
     68   1.8  drochner #endif
     69   1.2   thorpej void	pcic_isa_attach __P((struct device *, struct device *, void *));
     70   1.2   thorpej 
     71   1.2   thorpej void	*pcic_isa_chip_intr_establish __P((pcmcia_chipset_handle_t,
     72   1.2   thorpej 	    struct pcmcia_function *, int, int (*) (void *), void *));
     73   1.2   thorpej void	pcic_isa_chip_intr_disestablish __P((pcmcia_chipset_handle_t, void *));
     74   1.2   thorpej 
     75   1.2   thorpej struct cfattach pcic_isa_ca = {
     76   1.2   thorpej 	sizeof(struct pcic_softc), pcic_isa_probe, pcic_isa_attach
     77   1.2   thorpej };
     78   1.2   thorpej 
     79   1.2   thorpej static struct pcmcia_chip_functions pcic_isa_functions = {
     80   1.2   thorpej 	pcic_chip_mem_alloc,
     81   1.2   thorpej 	pcic_chip_mem_free,
     82   1.2   thorpej 	pcic_chip_mem_map,
     83   1.2   thorpej 	pcic_chip_mem_unmap,
     84   1.2   thorpej 
     85   1.2   thorpej 	pcic_chip_io_alloc,
     86   1.2   thorpej 	pcic_chip_io_free,
     87   1.2   thorpej 	pcic_chip_io_map,
     88   1.2   thorpej 	pcic_chip_io_unmap,
     89   1.2   thorpej 
     90   1.2   thorpej 	pcic_isa_chip_intr_establish,
     91   1.2   thorpej 	pcic_isa_chip_intr_disestablish,
     92   1.2   thorpej 
     93   1.2   thorpej 	pcic_chip_socket_enable,
     94   1.2   thorpej 	pcic_chip_socket_disable,
     95   1.2   thorpej };
     96   1.2   thorpej 
     97   1.2   thorpej int
     98   1.2   thorpej pcic_isa_probe(parent, match, aux)
     99   1.2   thorpej 	struct device *parent;
    100   1.8  drochner #ifdef __BROKEN_INDIRECT_CONFIG
    101   1.8  drochner 	void *match;
    102   1.8  drochner #else
    103   1.8  drochner 	struct cfdata *match;
    104   1.8  drochner #endif
    105   1.8  drochner 	void *aux;
    106   1.2   thorpej {
    107   1.2   thorpej 	struct isa_attach_args *ia = aux;
    108   1.2   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    109   1.2   thorpej 	bus_space_handle_t ioh, memh;
    110   1.2   thorpej 	int val, found;
    111   1.3   thorpej 
    112   1.3   thorpej 	/* Disallow wildcarded i/o address. */
    113   1.3   thorpej 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
    114   1.3   thorpej 		return (0);
    115   1.2   thorpej 
    116   1.2   thorpej 	if (bus_space_map(iot, ia->ia_iobase, PCIC_IOSIZE, 0, &ioh))
    117   1.2   thorpej 		return (0);
    118   1.2   thorpej 
    119   1.2   thorpej 	if (ia->ia_msize == -1)
    120   1.2   thorpej 		ia->ia_msize = PCIC_MEMSIZE;
    121   1.2   thorpej 
    122   1.2   thorpej 	if (bus_space_map(ia->ia_memt, ia->ia_maddr, ia->ia_msize, 0, &memh))
    123   1.2   thorpej 		return (0);
    124   1.2   thorpej 
    125   1.2   thorpej 	found = 0;
    126   1.2   thorpej 
    127   1.2   thorpej 	/*
    128   1.2   thorpej 	 * this could be done with a loop, but it would violate the
    129   1.2   thorpej 	 * abstraction
    130   1.2   thorpej 	 */
    131   1.2   thorpej 
    132   1.2   thorpej 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SA + PCIC_IDENT);
    133   1.2   thorpej 
    134   1.2   thorpej 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    135   1.2   thorpej 
    136   1.2   thorpej 	if (pcic_ident_ok(val))
    137   1.2   thorpej 		found++;
    138   1.2   thorpej 
    139   1.2   thorpej 
    140   1.2   thorpej 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SB + PCIC_IDENT);
    141   1.2   thorpej 
    142   1.2   thorpej 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    143   1.2   thorpej 
    144   1.2   thorpej 	if (pcic_ident_ok(val))
    145   1.2   thorpej 		found++;
    146   1.2   thorpej 
    147   1.2   thorpej 
    148   1.2   thorpej 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SA + PCIC_IDENT);
    149   1.2   thorpej 
    150   1.2   thorpej 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    151   1.2   thorpej 
    152   1.2   thorpej 	if (pcic_ident_ok(val))
    153   1.2   thorpej 		found++;
    154   1.2   thorpej 
    155   1.2   thorpej 
    156   1.2   thorpej 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SB + PCIC_IDENT);
    157   1.2   thorpej 
    158   1.2   thorpej 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    159   1.2   thorpej 
    160   1.2   thorpej 	if (pcic_ident_ok(val))
    161   1.2   thorpej 		found++;
    162   1.2   thorpej 
    163   1.2   thorpej 
    164   1.2   thorpej 	bus_space_unmap(iot, ioh, PCIC_IOSIZE);
    165   1.2   thorpej 	bus_space_unmap(ia->ia_memt, memh, ia->ia_msize);
    166   1.2   thorpej 
    167   1.2   thorpej 	if (!found)
    168   1.2   thorpej 		return (0);
    169   1.2   thorpej 
    170   1.2   thorpej 	ia->ia_iosize = PCIC_IOSIZE;
    171   1.2   thorpej 
    172   1.2   thorpej 	return (1);
    173   1.2   thorpej }
    174   1.2   thorpej 
    175   1.2   thorpej void
    176   1.2   thorpej pcic_isa_attach(parent, self, aux)
    177   1.2   thorpej 	struct device *parent, *self;
    178   1.2   thorpej 	void *aux;
    179   1.2   thorpej {
    180   1.2   thorpej 	struct pcic_softc *sc = (void *) self;
    181   1.2   thorpej 	struct isa_attach_args *ia = aux;
    182   1.2   thorpej 	isa_chipset_tag_t ic = ia->ia_ic;
    183   1.2   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    184   1.2   thorpej 	bus_space_tag_t memt = ia->ia_memt;
    185   1.2   thorpej 	bus_space_handle_t ioh;
    186   1.2   thorpej 	bus_space_handle_t memh;
    187   1.2   thorpej 
    188   1.2   thorpej 	/* Map i/o space. */
    189   1.4   thorpej 	if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh)) {
    190   1.4   thorpej 		printf(": can't map i/o space\n");
    191   1.4   thorpej 		return;
    192   1.4   thorpej 	}
    193   1.2   thorpej 
    194   1.2   thorpej 	/* Map mem space. */
    195   1.4   thorpej 	if (bus_space_map(memt, ia->ia_maddr, ia->ia_msize, 0, &memh)) {
    196   1.4   thorpej 		printf(": can't map mem space\n");
    197   1.4   thorpej 		return;
    198   1.4   thorpej 	}
    199   1.2   thorpej 
    200   1.2   thorpej 	sc->membase = ia->ia_maddr;
    201   1.2   thorpej 	sc->subregionmask = (1 << (ia->ia_msize / PCIC_MEM_PAGESIZE)) - 1;
    202   1.2   thorpej 
    203   1.2   thorpej 	sc->intr_est = ic;
    204   1.2   thorpej 	sc->pct = (pcmcia_chipset_tag_t) & pcic_isa_functions;
    205   1.2   thorpej 
    206   1.2   thorpej 	sc->iot = iot;
    207   1.2   thorpej 	sc->ioh = ioh;
    208   1.2   thorpej 	sc->memt = memt;
    209   1.2   thorpej 	sc->memh = memh;
    210   1.2   thorpej 
    211   1.2   thorpej 	/*
    212   1.2   thorpej 	 * allocate an irq.  it will be used by both controllers.  I could
    213   1.2   thorpej 	 * use two different interrupts, but interrupts are relatively
    214   1.2   thorpej 	 * scarce, shareable, and for PCIC controllers, very infrequent.
    215   1.2   thorpej 	 */
    216   1.2   thorpej 
    217   1.2   thorpej 	if ((sc->irq = ia->ia_irq) == IRQUNK) {
    218   1.6   thorpej 		if (isa_intr_alloc(ic,
    219   1.6   thorpej 		    PCIC_CSC_INTR_IRQ_VALIDMASK & pcic_isa_intr_alloc_mask,
    220   1.6   thorpej 		    IST_EDGE, &sc->irq)) {
    221   1.6   thorpej 			printf("\n%s: can't allocate interrupt\n",
    222   1.6   thorpej 			    sc->dev.dv_xname);
    223   1.6   thorpej 			return;
    224   1.6   thorpej 		}
    225   1.2   thorpej 		printf(": using irq %d", sc->irq);
    226   1.2   thorpej 	}
    227   1.2   thorpej 	printf("\n");
    228   1.2   thorpej 
    229   1.2   thorpej 	pcic_attach(sc);
    230   1.2   thorpej 
    231  1.10  sommerfe 	pcic_isa_bus_width_probe (sc, iot, ioh, ia->ia_iobase, ia->ia_iosize);
    232   1.2   thorpej 
    233   1.2   thorpej 	sc->ih = isa_intr_establish(ic, sc->irq, IST_EDGE, IPL_TTY,
    234   1.2   thorpej 	    pcic_intr, sc);
    235   1.6   thorpej 	if (sc->ih == NULL) {
    236   1.6   thorpej 		printf("%s: can't establish interrupt\n", sc->dev.dv_xname);
    237   1.6   thorpej 		return;
    238   1.6   thorpej 	}
    239   1.2   thorpej 
    240   1.2   thorpej 	pcic_attach_sockets(sc);
    241   1.2   thorpej }
    242