Home | History | Annotate | Line # | Download | only in isapnp
i82365_isapnp.c revision 1.31.18.2
      1  1.31.18.2  jdolecek /*	$NetBSD: i82365_isapnp.c,v 1.31.18.2 2017/12/03 11:37:05 jdolecek Exp $	*/
      2        1.1  sommerfe 
      3        1.1  sommerfe /*
      4        1.1  sommerfe  * Copyright (c) 1998 Bill Sommerfeld.  All rights reserved.
      5        1.1  sommerfe  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      6        1.1  sommerfe  *
      7        1.1  sommerfe  * Redistribution and use in source and binary forms, with or without
      8        1.1  sommerfe  * modification, are permitted provided that the following conditions
      9        1.1  sommerfe  * are met:
     10        1.1  sommerfe  * 1. Redistributions of source code must retain the above copyright
     11        1.1  sommerfe  *    notice, this list of conditions and the following disclaimer.
     12        1.1  sommerfe  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1  sommerfe  *    notice, this list of conditions and the following disclaimer in the
     14        1.1  sommerfe  *    documentation and/or other materials provided with the distribution.
     15        1.1  sommerfe  * 3. All advertising materials mentioning features or use of this software
     16        1.1  sommerfe  *    must display the following acknowledgement:
     17        1.1  sommerfe  *	This product includes software developed by Marc Horowitz.
     18        1.1  sommerfe  * 4. The name of the author may not be used to endorse or promote products
     19        1.1  sommerfe  *    derived from this software without specific prior written permission.
     20        1.1  sommerfe  *
     21        1.1  sommerfe  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22        1.1  sommerfe  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23        1.1  sommerfe  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24        1.1  sommerfe  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25        1.1  sommerfe  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26        1.1  sommerfe  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27        1.1  sommerfe  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28        1.1  sommerfe  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29        1.1  sommerfe  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30        1.1  sommerfe  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31        1.1  sommerfe  */
     32        1.1  sommerfe 
     33       1.11     lukem #include <sys/cdefs.h>
     34  1.31.18.2  jdolecek __KERNEL_RCSID(0, "$NetBSD: i82365_isapnp.c,v 1.31.18.2 2017/12/03 11:37:05 jdolecek Exp $");
     35        1.1  sommerfe 
     36        1.1  sommerfe #include <sys/param.h>
     37        1.1  sommerfe #include <sys/systm.h>
     38        1.1  sommerfe #include <sys/device.h>
     39        1.1  sommerfe #include <sys/extent.h>
     40        1.1  sommerfe #include <sys/malloc.h>
     41        1.1  sommerfe 
     42       1.24        ad #include <sys/bus.h>
     43       1.24        ad #include <sys/intr.h>
     44        1.1  sommerfe 
     45        1.1  sommerfe #include <dev/isa/isareg.h>
     46        1.1  sommerfe #include <dev/isa/isavar.h>
     47        1.1  sommerfe 
     48        1.1  sommerfe #include <dev/isapnp/isapnpreg.h>
     49        1.1  sommerfe #include <dev/isapnp/isapnpvar.h>
     50        1.4  christos #include <dev/isapnp/isapnpdevs.h>
     51        1.1  sommerfe 
     52        1.1  sommerfe #include <dev/pcmcia/pcmciareg.h>
     53        1.1  sommerfe #include <dev/pcmcia/pcmciavar.h>
     54        1.1  sommerfe #include <dev/pcmcia/pcmciachip.h>
     55        1.1  sommerfe 
     56        1.1  sommerfe #include <dev/ic/i82365reg.h>
     57        1.1  sommerfe #include <dev/ic/i82365var.h>
     58        1.1  sommerfe #include <dev/isa/i82365_isavar.h>
     59        1.1  sommerfe 
     60        1.1  sommerfe #undef DPRINTF
     61        1.1  sommerfe #ifdef PCICISADEBUG
     62        1.1  sommerfe int	pcicisapnp_debug = 0 /* XXX */ ;
     63        1.1  sommerfe #define	DPRINTF(arg) if (pcicisapnp_debug) printf arg;
     64        1.1  sommerfe #else
     65        1.1  sommerfe #define	DPRINTF(arg)
     66        1.1  sommerfe #endif
     67        1.1  sommerfe 
     68       1.28    cegger int pcic_isapnp_match(device_t, cfdata_t, void *);
     69       1.30   tsutsui void pcic_isapnp_attach(device_t, device_t, void *);
     70        1.1  sommerfe 
     71  1.31.18.1       tls CFATTACH_DECL_NEW(pcic_isapnp, sizeof(struct pcic_isa_softc),
     72       1.15   thorpej     pcic_isapnp_match, pcic_isapnp_attach, NULL, NULL);
     73        1.1  sommerfe 
     74       1.26  drochner static const struct pcmcia_chip_functions pcic_isa_functions = {
     75        1.1  sommerfe 	pcic_chip_mem_alloc,
     76        1.1  sommerfe 	pcic_chip_mem_free,
     77        1.1  sommerfe 	pcic_chip_mem_map,
     78        1.1  sommerfe 	pcic_chip_mem_unmap,
     79        1.1  sommerfe 
     80        1.1  sommerfe 	pcic_chip_io_alloc,
     81        1.1  sommerfe 	pcic_chip_io_free,
     82        1.1  sommerfe 	pcic_chip_io_map,
     83        1.1  sommerfe 	pcic_chip_io_unmap,
     84        1.1  sommerfe 
     85        1.1  sommerfe 	pcic_isa_chip_intr_establish,
     86        1.1  sommerfe 	pcic_isa_chip_intr_disestablish,
     87        1.1  sommerfe 
     88        1.1  sommerfe 	pcic_chip_socket_enable,
     89        1.1  sommerfe 	pcic_chip_socket_disable,
     90       1.16   mycroft 	pcic_chip_socket_settype,
     91       1.21  christos 	NULL,
     92        1.1  sommerfe };
     93        1.1  sommerfe 
     94        1.1  sommerfe int
     95       1.28    cegger pcic_isapnp_match(device_t parent, cfdata_t match, void *aux)
     96        1.1  sommerfe {
     97        1.6   mycroft 	int pri, variant;
     98        1.5   mycroft 
     99        1.6   mycroft 	pri = isapnp_devmatch(aux, &isapnp_pcic_devinfo, &variant);
    100        1.6   mycroft 	if (pri && variant > 0)
    101        1.6   mycroft 		pri = 0;
    102       1.30   tsutsui 	return pri;
    103        1.1  sommerfe }
    104        1.1  sommerfe 
    105        1.1  sommerfe void
    106       1.28    cegger pcic_isapnp_attach(device_t parent, device_t self, void *aux)
    107        1.1  sommerfe {
    108       1.20   thorpej 	struct pcic_isa_softc *isc = device_private(self);
    109       1.29   tsutsui 	struct pcic_softc *sc = &isc->sc_pcic;
    110        1.1  sommerfe 	struct isapnp_attach_args *ipa = aux;
    111        1.1  sommerfe 	isa_chipset_tag_t ic = ipa->ipa_ic;
    112        1.1  sommerfe 	bus_space_tag_t iot = ipa->ipa_iot;
    113        1.1  sommerfe 	bus_space_tag_t memt = ipa->ipa_memt;
    114        1.1  sommerfe 	bus_space_handle_t ioh;
    115        1.1  sommerfe 	bus_space_handle_t memh;
    116        1.1  sommerfe 	bus_addr_t maddr;
    117        1.1  sommerfe 	int msize;
    118        1.1  sommerfe 	int tmp1;
    119        1.1  sommerfe 
    120  1.31.18.1       tls 	sc->dev = self;
    121  1.31.18.1       tls 
    122  1.31.18.2  jdolecek 	aprint_naive("\n");
    123  1.31.18.2  jdolecek 	aprint_normal("\n");
    124        1.1  sommerfe 
    125        1.1  sommerfe 	if (isapnp_config(iot, memt, ipa)) {
    126       1.29   tsutsui 		aprint_error_dev(self, "error in region allocation\n");
    127        1.1  sommerfe 		return;
    128        1.1  sommerfe 	}
    129        1.1  sommerfe 
    130  1.31.18.2  jdolecek 	aprint_normal_dev(self, "%s %s", ipa->ipa_devident, ipa->ipa_devclass);
    131        1.1  sommerfe 
    132        1.1  sommerfe 	/* sanity check that we get at least one hunk of IO space.. */
    133        1.1  sommerfe 	if (ipa->ipa_nio < 1) {
    134       1.29   tsutsui 		aprint_error_dev(self,
    135       1.29   tsutsui 		    "failed to get one chunk of i/o space\n");
    136        1.1  sommerfe 		return;
    137        1.1  sommerfe 	}
    138        1.1  sommerfe 
    139        1.1  sommerfe 	/* Find i/o space. */
    140        1.1  sommerfe 	ioh = ipa->ipa_io[0].h;
    141        1.1  sommerfe 
    142        1.1  sommerfe 	/* sanity check to make sure we have a real PCIC there.. */
    143        1.1  sommerfe 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SA + PCIC_IDENT);
    144        1.1  sommerfe 	tmp1 = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    145  1.31.18.2  jdolecek 	aprint_normal("(ident 0x%x", tmp1);
    146        1.1  sommerfe 	if (pcic_ident_ok(tmp1)) {
    147  1.31.18.2  jdolecek 	  	aprint_normal(" OK)");
    148        1.1  sommerfe 	} else {
    149  1.31.18.2  jdolecek 	        aprint_error(" Not OK)\n");
    150        1.1  sommerfe 		return;
    151        1.1  sommerfe 	}
    152        1.1  sommerfe 
    153        1.1  sommerfe 	msize =  0x4000;
    154       1.30   tsutsui 	if (isa_mem_alloc(memt, msize, msize, 0, 0, &maddr, &memh)) {
    155  1.31.18.2  jdolecek 		aprint_error(": can't alloc mem space\n");
    156        1.1  sommerfe 		return;
    157        1.1  sommerfe 	}
    158  1.31.18.2  jdolecek 	aprint_normal(": using iomem %#" PRIxPADDR " iosiz %#x", maddr, msize);
    159        1.1  sommerfe 	sc->membase = maddr;
    160        1.1  sommerfe 	sc->subregionmask = (1 << (msize / PCIC_MEM_PAGESIZE)) - 1;
    161        1.1  sommerfe 
    162        1.8     soren 	isc->sc_ic = ic;
    163       1.30   tsutsui 	sc->pct = &pcic_isa_functions;
    164        1.1  sommerfe 
    165        1.1  sommerfe 	sc->iot = iot;
    166        1.1  sommerfe 	sc->ioh = ioh;
    167        1.1  sommerfe 	sc->memt = memt;
    168        1.1  sommerfe 	sc->memh = memh;
    169        1.1  sommerfe 
    170        1.1  sommerfe 	/*
    171        1.1  sommerfe 	 * allocate an irq.  it will be used by both controllers.  I could
    172        1.1  sommerfe 	 * use two different interrupts, but interrupts are relatively
    173        1.1  sommerfe 	 * scarce, shareable, and for PCIC controllers, very infrequent.
    174        1.1  sommerfe 	 */
    175        1.1  sommerfe 
    176        1.7    chopps 	if (ipa->ipa_nirq > 0)
    177        1.1  sommerfe 		sc->irq = ipa->ipa_irq[0].num;
    178        1.7    chopps 	else
    179       1.17  drochner 		sc->irq = -1;
    180        1.7    chopps 
    181  1.31.18.2  jdolecek 	aprint_normal("\n");
    182        1.1  sommerfe 
    183        1.1  sommerfe 	pcic_attach(sc);
    184        1.7    chopps 	pcic_isa_bus_width_probe(sc, iot, ioh, ipa->ipa_io[0].base,
    185        1.7    chopps 	    ipa->ipa_io[0].length);
    186        1.1  sommerfe 	pcic_attach_sockets(sc);
    187        1.7    chopps 	config_interrupts(self, pcic_isa_config_interrupts);
    188        1.1  sommerfe }
    189