Home | History | Annotate | Line # | Download | only in pci
i82365_pci.c revision 1.8
      1 /*	$NetBSD: i82365_pci.c,v 1.8 2000/02/01 22:39:53 chopps Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Marc Horowitz.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * XXX this driver frontend is *very* i386 dependent and should be relocated
     34  */
     35 
     36 #include <sys/types.h>
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/device.h>
     40 
     41 #include <dev/ic/i82365reg.h>
     42 #include <dev/ic/i82365var.h>
     43 
     44 #include <dev/pci/pcivar.h>
     45 #include <dev/pci/pcireg.h>
     46 #include <dev/pci/pcidevs.h>
     47 #include <dev/pci/i82365_pcivar.h>
     48 #include <dev/isa/i82365_isavar.h>
     49 
     50 /*
     51  * PCI constants.
     52  * XXX These should be in a common file!
     53  */
     54 #define	PCI_CBIO		0x10	/* Configuration Base IO Address */
     55 
     56 int	pcic_pci_match __P((struct device *, struct cfdata *, void *));
     57 void	pcic_pci_attach __P((struct device *, struct device *, void *));
     58 
     59 struct cfattach pcic_pci_ca = {
     60 	sizeof(struct pcic_softc), pcic_pci_match, pcic_pci_attach
     61 };
     62 
     63 static struct pcmcia_chip_functions pcic_pci_functions = {
     64 	pcic_chip_mem_alloc,
     65 	pcic_chip_mem_free,
     66 	pcic_chip_mem_map,
     67 	pcic_chip_mem_unmap,
     68 
     69 	pcic_chip_io_alloc,
     70 	pcic_chip_io_free,
     71 	pcic_chip_io_map,
     72 	pcic_chip_io_unmap,
     73 
     74 	/* XXX */
     75 	pcic_isa_chip_intr_establish,
     76 	pcic_isa_chip_intr_disestablish,
     77 
     78 	pcic_chip_socket_enable,
     79 	pcic_chip_socket_disable,
     80 };
     81 
     82 static void pcic_pci_callback(struct device *);
     83 
     84 int
     85 pcic_pci_match(parent, match, aux)
     86 	struct device *parent;
     87 	struct cfdata  *match;
     88 	void *aux;
     89 {
     90 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
     91 
     92 	switch (PCI_VENDOR(pa->pa_id)) {
     93 	case PCI_VENDOR_CIRRUS:
     94 		switch(PCI_PRODUCT(pa->pa_id)) {
     95 		case PCI_PRODUCT_CIRRUS_CL_PD6729:
     96 			break;
     97 		default:
     98 			return (0);
     99 		}
    100 		break;
    101 	default:
    102 		return (0);
    103 	}
    104 	return (1);
    105 }
    106 
    107 void pcic_isa_config_interrupts __P((struct device *));
    108 
    109 void
    110 pcic_pci_attach(parent, self, aux)
    111 	struct device *parent, *self;
    112 	void *aux;
    113 {
    114 	struct pcic_softc *sc = (void *) self;
    115 	struct pci_attach_args *pa = aux;
    116 	pci_chipset_tag_t pc = pa->pa_pc;
    117 	bus_space_tag_t memt = pa->pa_memt;
    118 	bus_space_handle_t memh;
    119 	char *model;
    120 
    121 	if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
    122 	    &sc->iot, &sc->ioh, NULL, NULL)) {
    123 		printf(": can't map i/o space\n");
    124 		return;
    125 	}
    126 
    127 	/*
    128 	 * XXX need some memory for mapping pcmcia cards into. Ideally, this
    129 	 * would be completely dynamic.  Practically this doesn't work,
    130 	 * because the extent mapper doesn't know about all the devices all
    131 	 * the time.  With ISA we could finesse the issue by specifying the
    132 	 * memory region in the config line.  We can't do that here, so we
    133 	 * cheat for now. Jason Thorpe, you are my Savior, come up with a fix
    134 	 * :-)
    135 	 */
    136 
    137 	/* Map mem space. */
    138 	if (bus_space_map(memt, 0xd0000, 0x4000, 0, &memh))
    139 		panic("pcic_pci_attach: can't map mem space");
    140 
    141 	sc->membase = 0xd0000;
    142 	sc->subregionmask = (1 << (0x4000 / PCIC_MEM_PAGESIZE)) - 1;
    143 
    144 	/* same deal for io allocation */
    145 
    146 	sc->iobase = 0x400;
    147 	sc->iosize = 0xbff;
    148 
    149 	/* end XXX */
    150 
    151 	sc->pct = (pcmcia_chipset_tag_t) & pcic_pci_functions;
    152 
    153 	sc->memt = memt;
    154 	sc->memh = memh;
    155 
    156 	switch (PCI_PRODUCT(pa->pa_id)) {
    157 	case PCI_PRODUCT_CIRRUS_CL_PD6729:
    158 		model = "Cirrus Logic PD6729 PCMCIA controller";
    159 		break;
    160 	default:
    161 		model = "Model unknown";
    162 		break;
    163 	}
    164 
    165 	printf(": %s\n", model);
    166 
    167 	/* Enable the card. */
    168 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    169 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    170 	    PCI_COMMAND_MASTER_ENABLE);
    171 
    172 	pcic_attach(sc);
    173 
    174 	/*
    175 	 * Check to see if we're using PCI or ISA interrupts. I don't
    176 	 * know of any i386 systems that use the 6729 in PCI interrupt
    177 	 * mode, but maybe when the PCMCIA code runs on other platforms
    178 	 * we'll need to fix this.
    179 	 */
    180 	pcic_write(&sc->handle[0], PCIC_CIRRUS_EXTENDED_INDEX,
    181 		   PCIC_CIRRUS_EXT_CONTROL_1);
    182 	if ((pcic_read(&sc->handle[0], PCIC_CIRRUS_EXTENDED_DATA) &
    183 	    PCIC_CIRRUS_EXT_CONTROL_1_PCI_INTR_MASK)) {
    184 		printf("%s: PCI interrupts not supported\n",
    185 		       sc->dev.dv_xname);
    186 		return;
    187 	}
    188 
    189 	sc->intr_est = pcic_pci_machdep_intr_est(pc);
    190 	sc->irq = -1;
    191 
    192 #if 0
    193 	/* Map and establish the interrupt. */
    194 	sc->ih = pcic_pci_machdep_pcic_intr_establish(sc, pcic_intr);
    195 	if (sc->ih == NULL) {
    196 		printf("%s: couldn't map interrupt\n", sc->dev.dv_xname);
    197 		return;
    198 	}
    199 #endif
    200 
    201 	printf("\n");
    202 
    203 	/*
    204 	 * Defer configuration of children until ISA has had its chance
    205 	 * to use up whatever IO space and IRQs it wants. XXX This will
    206 	 * only work if ISA is attached to a pcib, AND the PCI probe finds
    207 	 * and defers the ISA attachment before this one.
    208 	 */
    209 	config_defer(self, pcic_pci_callback);
    210 	config_interrupts(self, pcic_isa_config_interrupts);
    211 }
    212 
    213 static void
    214 pcic_pci_callback(self)
    215 	struct device *self;
    216 {
    217 	struct pcic_softc *sc = (void *) self;
    218 
    219 	pcic_attach_sockets(sc);
    220 }
    221