Home | History | Annotate | Line # | Download | only in pci
i82365_pci.c revision 1.22
      1  1.22  christos /*	$NetBSD: i82365_pci.c,v 1.22 2006/08/30 15:14:11 christos 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.2   thorpej 
     32   1.8    chopps /*
     33   1.8    chopps  * XXX this driver frontend is *very* i386 dependent and should be relocated
     34   1.8    chopps  */
     35  1.12     lukem 
     36  1.12     lukem #include <sys/cdefs.h>
     37  1.22  christos __KERNEL_RCSID(0, "$NetBSD: i82365_pci.c,v 1.22 2006/08/30 15:14:11 christos Exp $");
     38   1.8    chopps 
     39   1.2   thorpej #include <sys/param.h>
     40   1.2   thorpej #include <sys/systm.h>
     41   1.2   thorpej #include <sys/device.h>
     42   1.2   thorpej 
     43   1.2   thorpej #include <dev/ic/i82365reg.h>
     44   1.2   thorpej #include <dev/ic/i82365var.h>
     45   1.2   thorpej 
     46   1.2   thorpej #include <dev/pci/pcivar.h>
     47   1.2   thorpej #include <dev/pci/pcireg.h>
     48   1.2   thorpej #include <dev/pci/pcidevs.h>
     49   1.7   nathanw #include <dev/pci/i82365_pcivar.h>
     50  1.10     enami 
     51  1.10     enami #include <dev/isa/isavar.h>
     52   1.8    chopps #include <dev/isa/i82365_isavar.h>
     53   1.2   thorpej 
     54   1.2   thorpej /*
     55   1.2   thorpej  * PCI constants.
     56   1.2   thorpej  * XXX These should be in a common file!
     57   1.2   thorpej  */
     58   1.2   thorpej #define	PCI_CBIO		0x10	/* Configuration Base IO Address */
     59   1.2   thorpej 
     60  1.19     perry int	pcic_pci_match(struct device *, struct cfdata *, void *);
     61  1.19     perry void	pcic_pci_attach(struct device *, struct device *, void *);
     62   1.2   thorpej 
     63  1.15   thorpej CFATTACH_DECL(pcic_pci, sizeof(struct pcic_pci_softc),
     64  1.16   thorpej     pcic_pci_match, pcic_pci_attach, NULL, NULL);
     65   1.2   thorpej 
     66   1.2   thorpej static struct pcmcia_chip_functions pcic_pci_functions = {
     67   1.2   thorpej 	pcic_chip_mem_alloc,
     68   1.2   thorpej 	pcic_chip_mem_free,
     69   1.2   thorpej 	pcic_chip_mem_map,
     70   1.2   thorpej 	pcic_chip_mem_unmap,
     71   1.2   thorpej 
     72   1.2   thorpej 	pcic_chip_io_alloc,
     73   1.2   thorpej 	pcic_chip_io_free,
     74   1.2   thorpej 	pcic_chip_io_map,
     75   1.2   thorpej 	pcic_chip_io_unmap,
     76   1.2   thorpej 
     77   1.8    chopps 	/* XXX */
     78   1.8    chopps 	pcic_isa_chip_intr_establish,
     79   1.8    chopps 	pcic_isa_chip_intr_disestablish,
     80   1.2   thorpej 
     81   1.2   thorpej 	pcic_chip_socket_enable,
     82   1.2   thorpej 	pcic_chip_socket_disable,
     83  1.18   mycroft 	pcic_chip_socket_settype,
     84  1.22  christos 
     85  1.22  christos 	NULL,				/* card_detect */
     86   1.2   thorpej };
     87   1.2   thorpej 
     88   1.7   nathanw static void pcic_pci_callback(struct device *);
     89   1.7   nathanw 
     90   1.2   thorpej int
     91   1.2   thorpej pcic_pci_match(parent, match, aux)
     92   1.2   thorpej 	struct device *parent;
     93   1.2   thorpej 	struct cfdata  *match;
     94   1.2   thorpej 	void *aux;
     95   1.2   thorpej {
     96   1.2   thorpej 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
     97   1.2   thorpej 
     98   1.7   nathanw 	switch (PCI_VENDOR(pa->pa_id)) {
     99   1.7   nathanw 	case PCI_VENDOR_CIRRUS:
    100   1.7   nathanw 		switch(PCI_PRODUCT(pa->pa_id)) {
    101   1.7   nathanw 		case PCI_PRODUCT_CIRRUS_CL_PD6729:
    102   1.7   nathanw 			break;
    103   1.7   nathanw 		default:
    104   1.7   nathanw 			return (0);
    105   1.7   nathanw 		}
    106   1.2   thorpej 		break;
    107   1.2   thorpej 	default:
    108   1.2   thorpej 		return (0);
    109   1.2   thorpej 	}
    110   1.2   thorpej 	return (1);
    111   1.2   thorpej }
    112   1.2   thorpej 
    113  1.19     perry void pcic_isa_config_interrupts(struct device *);
    114   1.8    chopps 
    115   1.2   thorpej void
    116   1.2   thorpej pcic_pci_attach(parent, self, aux)
    117   1.2   thorpej 	struct device *parent, *self;
    118   1.2   thorpej 	void *aux;
    119   1.2   thorpej {
    120   1.2   thorpej 	struct pcic_softc *sc = (void *) self;
    121   1.9   thorpej 	struct pcic_pci_softc *psc = (void *) self;
    122   1.2   thorpej 	struct pci_attach_args *pa = aux;
    123   1.2   thorpej 	pci_chipset_tag_t pc = pa->pa_pc;
    124   1.2   thorpej 	bus_space_tag_t memt = pa->pa_memt;
    125   1.2   thorpej 	bus_space_handle_t memh;
    126  1.20  christos 	const char *model;
    127   1.2   thorpej 
    128  1.17   thorpej 	aprint_naive(": PCMCIA controller\n");
    129  1.17   thorpej 
    130   1.2   thorpej 	if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
    131   1.2   thorpej 	    &sc->iot, &sc->ioh, NULL, NULL)) {
    132  1.17   thorpej 		aprint_error(": can't map i/o space\n");
    133   1.2   thorpej 		return;
    134   1.2   thorpej 	}
    135   1.2   thorpej 
    136   1.2   thorpej 	/*
    137   1.2   thorpej 	 * XXX need some memory for mapping pcmcia cards into. Ideally, this
    138   1.2   thorpej 	 * would be completely dynamic.  Practically this doesn't work,
    139   1.2   thorpej 	 * because the extent mapper doesn't know about all the devices all
    140   1.2   thorpej 	 * the time.  With ISA we could finesse the issue by specifying the
    141   1.2   thorpej 	 * memory region in the config line.  We can't do that here, so we
    142   1.2   thorpej 	 * cheat for now. Jason Thorpe, you are my Savior, come up with a fix
    143   1.2   thorpej 	 * :-)
    144   1.2   thorpej 	 */
    145   1.2   thorpej 
    146   1.2   thorpej 	/* Map mem space. */
    147   1.2   thorpej 	if (bus_space_map(memt, 0xd0000, 0x4000, 0, &memh))
    148   1.6   msaitoh 		panic("pcic_pci_attach: can't map mem space");
    149   1.2   thorpej 
    150   1.2   thorpej 	sc->membase = 0xd0000;
    151   1.2   thorpej 	sc->subregionmask = (1 << (0x4000 / PCIC_MEM_PAGESIZE)) - 1;
    152   1.2   thorpej 
    153   1.2   thorpej 	/* same deal for io allocation */
    154   1.2   thorpej 
    155   1.2   thorpej 	sc->iobase = 0x400;
    156   1.2   thorpej 	sc->iosize = 0xbff;
    157   1.2   thorpej 
    158   1.2   thorpej 	/* end XXX */
    159   1.2   thorpej 
    160   1.2   thorpej 	sc->pct = (pcmcia_chipset_tag_t) & pcic_pci_functions;
    161   1.2   thorpej 
    162   1.2   thorpej 	sc->memt = memt;
    163   1.2   thorpej 	sc->memh = memh;
    164   1.2   thorpej 
    165   1.2   thorpej 	switch (PCI_PRODUCT(pa->pa_id)) {
    166   1.5       jtk 	case PCI_PRODUCT_CIRRUS_CL_PD6729:
    167   1.5       jtk 		model = "Cirrus Logic PD6729 PCMCIA controller";
    168   1.2   thorpej 		break;
    169   1.2   thorpej 	default:
    170   1.2   thorpej 		model = "Model unknown";
    171   1.2   thorpej 		break;
    172   1.2   thorpej 	}
    173   1.2   thorpej 
    174  1.17   thorpej 	aprint_normal(": %s\n", model);
    175   1.2   thorpej 
    176   1.2   thorpej 	/* Enable the card. */
    177   1.2   thorpej 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    178   1.2   thorpej 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    179   1.2   thorpej 	    PCI_COMMAND_MASTER_ENABLE);
    180   1.2   thorpej 
    181   1.2   thorpej 	pcic_attach(sc);
    182   1.2   thorpej 
    183   1.7   nathanw 	/*
    184   1.7   nathanw 	 * Check to see if we're using PCI or ISA interrupts. I don't
    185   1.7   nathanw 	 * know of any i386 systems that use the 6729 in PCI interrupt
    186   1.7   nathanw 	 * mode, but maybe when the PCMCIA code runs on other platforms
    187   1.7   nathanw 	 * we'll need to fix this.
    188   1.7   nathanw 	 */
    189   1.7   nathanw 	pcic_write(&sc->handle[0], PCIC_CIRRUS_EXTENDED_INDEX,
    190   1.7   nathanw 		   PCIC_CIRRUS_EXT_CONTROL_1);
    191   1.8    chopps 	if ((pcic_read(&sc->handle[0], PCIC_CIRRUS_EXTENDED_DATA) &
    192   1.8    chopps 	    PCIC_CIRRUS_EXT_CONTROL_1_PCI_INTR_MASK)) {
    193  1.17   thorpej 		aprint_error("%s: PCI interrupts not supported\n",
    194   1.7   nathanw 		       sc->dev.dv_xname);
    195   1.2   thorpej 		return;
    196   1.2   thorpej 	}
    197   1.7   nathanw 
    198   1.9   thorpej 	psc->intr_est = pcic_pci_machdep_intr_est(pc);
    199   1.8    chopps 	sc->irq = -1;
    200   1.7   nathanw 
    201   1.8    chopps #if 0
    202   1.7   nathanw 	/* Map and establish the interrupt. */
    203   1.7   nathanw 	sc->ih = pcic_pci_machdep_pcic_intr_establish(sc, pcic_intr);
    204   1.2   thorpej 	if (sc->ih == NULL) {
    205  1.17   thorpej 		aprint_error("%s: couldn't map interrupt\n", sc->dev.dv_xname);
    206   1.2   thorpej 		return;
    207   1.2   thorpej 	}
    208   1.8    chopps #endif
    209   1.2   thorpej 
    210   1.2   thorpej 	/*
    211   1.7   nathanw 	 * Defer configuration of children until ISA has had its chance
    212   1.7   nathanw 	 * to use up whatever IO space and IRQs it wants. XXX This will
    213   1.7   nathanw 	 * only work if ISA is attached to a pcib, AND the PCI probe finds
    214   1.7   nathanw 	 * and defers the ISA attachment before this one.
    215   1.2   thorpej 	 */
    216   1.7   nathanw 	config_defer(self, pcic_pci_callback);
    217   1.8    chopps 	config_interrupts(self, pcic_isa_config_interrupts);
    218   1.2   thorpej }
    219   1.2   thorpej 
    220   1.7   nathanw static void
    221   1.7   nathanw pcic_pci_callback(self)
    222   1.7   nathanw 	struct device *self;
    223   1.2   thorpej {
    224   1.7   nathanw 	struct pcic_softc *sc = (void *) self;
    225   1.2   thorpej 
    226   1.7   nathanw 	pcic_attach_sockets(sc);
    227   1.2   thorpej }
    228