Home | History | Annotate | Line # | Download | only in isa
i82365_isa.c revision 1.28.20.4
      1  1.28.20.4      yamt /*	$NetBSD: i82365_isa.c,v 1.28.20.4 2010/03/11 15:03:37 yamt Exp $	*/
      2        1.2   thorpej 
      3        1.2   thorpej /*
      4        1.2   thorpej  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      5        1.2   thorpej  *
      6        1.2   thorpej  * Redistribution and use in source and binary forms, with or without
      7        1.2   thorpej  * modification, are permitted provided that the following conditions
      8        1.2   thorpej  * are met:
      9        1.2   thorpej  * 1. Redistributions of source code must retain the above copyright
     10        1.2   thorpej  *    notice, this list of conditions and the following disclaimer.
     11        1.2   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.2   thorpej  *    notice, this list of conditions and the following disclaimer in the
     13        1.2   thorpej  *    documentation and/or other materials provided with the distribution.
     14        1.2   thorpej  * 3. All advertising materials mentioning features or use of this software
     15        1.2   thorpej  *    must display the following acknowledgement:
     16        1.2   thorpej  *	This product includes software developed by Marc Horowitz.
     17        1.2   thorpej  * 4. The name of the author may not be used to endorse or promote products
     18        1.2   thorpej  *    derived from this software without specific prior written permission.
     19        1.2   thorpej  *
     20        1.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21        1.2   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22        1.2   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23        1.2   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24        1.2   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25        1.2   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26        1.2   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27        1.2   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28        1.2   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29        1.2   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30        1.2   thorpej  */
     31       1.15     lukem 
     32       1.15     lukem #include <sys/cdefs.h>
     33  1.28.20.4      yamt __KERNEL_RCSID(0, "$NetBSD: i82365_isa.c,v 1.28.20.4 2010/03/11 15:03:37 yamt Exp $");
     34       1.15     lukem 
     35       1.15     lukem #define	PCICISADEBUG
     36        1.2   thorpej 
     37        1.2   thorpej #include <sys/param.h>
     38        1.2   thorpej #include <sys/systm.h>
     39        1.2   thorpej #include <sys/device.h>
     40        1.2   thorpej #include <sys/extent.h>
     41        1.2   thorpej #include <sys/malloc.h>
     42        1.2   thorpej 
     43       1.28        ad #include <sys/bus.h>
     44       1.28        ad #include <sys/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.12    chopps int	pcicisa_debug = 0;
     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.28.20.2      yamt int	pcic_isa_probe(device_t, cfdata_t, void *);
     65  1.28.20.2      yamt void	pcic_isa_attach(device_t, device_t, void *);
     66        1.2   thorpej 
     67       1.19   thorpej CFATTACH_DECL(pcic_isa, sizeof(struct pcic_isa_softc),
     68       1.20   thorpej     pcic_isa_probe, pcic_isa_attach, NULL, NULL);
     69        1.2   thorpej 
     70  1.28.20.1      yamt static const struct pcmcia_chip_functions pcic_isa_functions = {
     71        1.2   thorpej 	pcic_chip_mem_alloc,
     72        1.2   thorpej 	pcic_chip_mem_free,
     73        1.2   thorpej 	pcic_chip_mem_map,
     74        1.2   thorpej 	pcic_chip_mem_unmap,
     75        1.2   thorpej 
     76        1.2   thorpej 	pcic_chip_io_alloc,
     77        1.2   thorpej 	pcic_chip_io_free,
     78        1.2   thorpej 	pcic_chip_io_map,
     79        1.2   thorpej 	pcic_chip_io_unmap,
     80        1.2   thorpej 
     81        1.2   thorpej 	pcic_isa_chip_intr_establish,
     82        1.2   thorpej 	pcic_isa_chip_intr_disestablish,
     83        1.2   thorpej 
     84        1.2   thorpej 	pcic_chip_socket_enable,
     85        1.2   thorpej 	pcic_chip_socket_disable,
     86       1.21   mycroft 	pcic_chip_socket_settype,
     87       1.25  christos 	NULL,
     88        1.2   thorpej };
     89        1.2   thorpej 
     90        1.2   thorpej int
     91  1.28.20.2      yamt pcic_isa_probe(device_t parent, cfdata_t match, void *aux)
     92        1.2   thorpej {
     93        1.2   thorpej 	struct isa_attach_args *ia = aux;
     94        1.2   thorpej 	bus_space_tag_t iot = ia->ia_iot;
     95        1.2   thorpej 	bus_space_handle_t ioh, memh;
     96       1.17   thorpej 	int val, found, msize;
     97       1.17   thorpej 
     98       1.17   thorpej 	if (ia->ia_nio < 1)
     99  1.28.20.4      yamt 		return 0;
    100       1.17   thorpej 	if (ia->ia_niomem < 1)
    101  1.28.20.4      yamt 		return 0;
    102       1.17   thorpej 
    103       1.17   thorpej 	if (ISA_DIRECT_CONFIG(ia))
    104  1.28.20.4      yamt 		return 0;
    105        1.3   thorpej 
    106        1.3   thorpej 	/* Disallow wildcarded i/o address. */
    107       1.22  drochner 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
    108  1.28.20.4      yamt 		return 0;
    109       1.22  drochner 	if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM)
    110  1.28.20.4      yamt 		return 0;
    111        1.2   thorpej 
    112       1.17   thorpej 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, PCIC_IOSIZE, 0, &ioh))
    113  1.28.20.4      yamt 		return 0;
    114        1.2   thorpej 
    115       1.22  drochner 	if (ia->ia_iomem[0].ir_size == ISA_UNKNOWN_IOSIZ)
    116       1.17   thorpej 		msize = PCIC_MEMSIZE;
    117       1.17   thorpej 	else
    118       1.17   thorpej 		msize = ia->ia_iomem[0].ir_size;
    119       1.17   thorpej 
    120       1.17   thorpej 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr,
    121       1.17   thorpej 	    msize, 0, &memh)) {
    122       1.17   thorpej 		bus_space_unmap(iot, ioh, PCIC_IOSIZE);
    123  1.28.20.4      yamt 		return 0;
    124       1.17   thorpej 	}
    125        1.2   thorpej 
    126        1.2   thorpej 	found = 0;
    127        1.2   thorpej 
    128        1.2   thorpej 	/*
    129        1.2   thorpej 	 * this could be done with a loop, but it would violate the
    130        1.2   thorpej 	 * abstraction
    131        1.2   thorpej 	 */
    132        1.2   thorpej 
    133        1.2   thorpej 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SA + PCIC_IDENT);
    134        1.2   thorpej 
    135        1.2   thorpej 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    136        1.2   thorpej 
    137        1.2   thorpej 	if (pcic_ident_ok(val))
    138        1.2   thorpej 		found++;
    139        1.2   thorpej 
    140        1.2   thorpej 
    141        1.2   thorpej 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SB + PCIC_IDENT);
    142        1.2   thorpej 
    143        1.2   thorpej 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    144        1.2   thorpej 
    145        1.2   thorpej 	if (pcic_ident_ok(val))
    146        1.2   thorpej 		found++;
    147        1.2   thorpej 
    148        1.2   thorpej 
    149        1.2   thorpej 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SA + PCIC_IDENT);
    150        1.2   thorpej 
    151        1.2   thorpej 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    152        1.2   thorpej 
    153        1.2   thorpej 	if (pcic_ident_ok(val))
    154        1.2   thorpej 		found++;
    155        1.2   thorpej 
    156        1.2   thorpej 
    157        1.2   thorpej 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SB + PCIC_IDENT);
    158        1.2   thorpej 
    159        1.2   thorpej 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    160        1.2   thorpej 
    161        1.2   thorpej 	if (pcic_ident_ok(val))
    162        1.2   thorpej 		found++;
    163        1.2   thorpej 
    164        1.2   thorpej 
    165        1.2   thorpej 	bus_space_unmap(iot, ioh, PCIC_IOSIZE);
    166       1.17   thorpej 	bus_space_unmap(ia->ia_memt, memh, msize);
    167        1.2   thorpej 
    168        1.2   thorpej 	if (!found)
    169  1.28.20.4      yamt 		return 0;
    170        1.2   thorpej 
    171       1.17   thorpej 	ia->ia_nio = 1;
    172       1.17   thorpej 	ia->ia_io[0].ir_size = PCIC_IOSIZE;
    173       1.17   thorpej 
    174       1.17   thorpej 	ia->ia_niomem = 1;
    175       1.17   thorpej 	ia->ia_iomem[0].ir_size = msize;
    176       1.17   thorpej 
    177       1.17   thorpej 	/* IRQ is special. */
    178       1.17   thorpej 
    179       1.17   thorpej 	ia->ia_ndrq = 0;
    180        1.2   thorpej 
    181  1.28.20.4      yamt 	return 1;
    182        1.2   thorpej }
    183        1.2   thorpej 
    184        1.2   thorpej void
    185  1.28.20.2      yamt pcic_isa_attach(device_t parent, device_t self, void *aux)
    186        1.2   thorpej {
    187  1.28.20.3      yamt 	struct pcic_isa_softc *isc = device_private(self);
    188  1.28.20.3      yamt 	struct pcic_softc *sc = &isc->sc_pcic;
    189        1.2   thorpej 	struct isa_attach_args *ia = aux;
    190        1.2   thorpej 	isa_chipset_tag_t ic = ia->ia_ic;
    191        1.2   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    192        1.2   thorpej 	bus_space_tag_t memt = ia->ia_memt;
    193        1.2   thorpej 	bus_space_handle_t ioh;
    194        1.2   thorpej 	bus_space_handle_t memh;
    195        1.2   thorpej 
    196        1.2   thorpej 	/* Map i/o space. */
    197       1.17   thorpej 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, PCIC_IOSIZE, 0, &ioh)) {
    198        1.4   thorpej 		printf(": can't map i/o space\n");
    199        1.4   thorpej 		return;
    200        1.4   thorpej 	}
    201        1.2   thorpej 
    202        1.2   thorpej 	/* Map mem space. */
    203       1.17   thorpej 	if (bus_space_map(memt, ia->ia_iomem[0].ir_addr,
    204       1.17   thorpej 	    ia->ia_iomem[0].ir_size, 0, &memh)) {
    205        1.4   thorpej 		printf(": can't map mem space\n");
    206        1.4   thorpej 		return;
    207        1.4   thorpej 	}
    208        1.2   thorpej 
    209       1.17   thorpej 	sc->membase = ia->ia_iomem[0].ir_addr;
    210       1.17   thorpej 	sc->subregionmask =
    211       1.17   thorpej 	    (1 << (ia->ia_iomem[0].ir_size / PCIC_MEM_PAGESIZE)) - 1;
    212        1.2   thorpej 
    213       1.13   thorpej 	isc->sc_ic = ic;
    214  1.28.20.4      yamt 	sc->pct = &pcic_isa_functions;
    215        1.2   thorpej 
    216        1.2   thorpej 	sc->iot = iot;
    217        1.2   thorpej 	sc->ioh = ioh;
    218        1.2   thorpej 	sc->memt = memt;
    219        1.2   thorpej 	sc->memh = memh;
    220       1.17   thorpej 	if (ia->ia_nirq > 0)
    221       1.17   thorpej 		sc->irq = ia->ia_irq[0].ir_irq;
    222       1.17   thorpej 	else
    223       1.22  drochner 		sc->irq = ISA_UNKNOWN_IRQ;
    224        1.2   thorpej 
    225        1.2   thorpej 	printf("\n");
    226        1.2   thorpej 
    227        1.2   thorpej 	pcic_attach(sc);
    228       1.17   thorpej 	pcic_isa_bus_width_probe(sc, iot, ioh, ia->ia_io[0].ir_addr,
    229       1.17   thorpej 	    PCIC_IOSIZE);
    230       1.12    chopps 	pcic_attach_sockets(sc);
    231        1.2   thorpej 
    232       1.12    chopps 	config_interrupts(self, pcic_isa_config_interrupts);
    233        1.2   thorpej }
    234