Home | History | Annotate | Line # | Download | only in ixm1200
nappi_nppb.c revision 1.6
      1 /*	$NetBSD: nappi_nppb.c,v 1.6 2003/03/25 06:53:16 igy Exp $ */
      2 /*
      3  * Copyright (c) 2002, 2003
      4  *	Ichiro FUKUHARA <ichiro (at) ichiro.org>.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Ichiro FUKUHARA.
     18  * 4. The name of the company nor the name of the author may be used to
     19  *    endorse or promote products derived from this software without specific
     20  *    prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
     26  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: nappi_nppb.c,v 1.6 2003/03/25 06:53:16 igy Exp $");
     37 
     38 #include "pci.h"
     39 #include "opt_pci.h"
     40 
     41 #include <sys/types.h>
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/device.h>
     45 #include <sys/extent.h>
     46 #include <sys/malloc.h>
     47 
     48 #include <machine/bus.h>
     49 
     50 #include <dev/pci/pcivar.h>
     51 #include <dev/pci/pcireg.h>
     52 #include <dev/pci/pcidevs.h>
     53 #include <dev/pci/pciconf.h>
     54 
     55 static int	nppbmatch(struct device *, struct cfdata *, void *);
     56 static void	nppbattach(struct device *, struct device *, void *);
     57 
     58 int	nppb_intr(void *); /* XXX into i21555var.h */
     59 
     60 CFATTACH_DECL(nppb, sizeof(struct device),
     61     nppbmatch, nppbattach, NULL, NULL);
     62 
     63 #define NPPB_MMBA	0x10
     64 #define NPPB_IOBA	0x14
     65 
     66 #define CSR_READ_1(sc, reg)	\
     67 	bus_space_read_1(sc->sc_st, sc->sc_sh, reg)
     68 #define CSR_READ_2(sc, reg)	\
     69 	bus_space_read_2(sc->sc_st, sc->sc_sh, reg)
     70 #define CSR_READ_4(sc, reg)	\
     71 	bus_space_read_4(sc->sc_st, sc->sc_sh, reg)
     72 
     73 #define CSR_WRITE_1(sc, reg, val)	\
     74 	bus_space_write_1(sc->sc_st, sc->sc_sh, reg, val)
     75 #define CSR_WRITE_2(sc, reg, val)	\
     76 	bus_space_write_2(sc->sc_st, sc->sc_sh, reg, val)
     77 #define CSR_WRITE_4(sc, reg, val)	\
     78 	bus_space_write_4(sc->sc_st, sc->sc_sh, reg, val)
     79 
     80 struct nppb_softc {  /* XXX into i21555var.h */
     81 	struct device sc_dev;		/* generic device information */
     82 	bus_space_tag_t sc_st;		/* bus space tag */
     83 	bus_space_handle_t sc_sh;	/* bus space handle */
     84 
     85 	void *sc_ih;			/* interrupt handler cookie */
     86 };
     87 
     88 struct nppb_pci_softc {
     89 	struct nppb_softc psc_nppb;
     90 
     91 	pci_chipset_tag_t psc_pc;	/* pci chipset tag */
     92 	pcitag_t psc_tag;		/* pci register tag */
     93 };
     94 
     95 static int
     96 nppbmatch(struct device *parent, struct cfdata *cf, void *aux)
     97 {
     98 	struct pci_attach_args *pa = aux;
     99 	u_int32_t class, id;
    100 
    101 	class = pa->pa_class;
    102 	id = pa->pa_id;
    103 
    104 	if (PCI_CLASS(class) == PCI_CLASS_BRIDGE &&
    105 	    PCI_SUBCLASS(class) == PCI_SUBCLASS_BRIDGE_MISC) {
    106 		switch (PCI_VENDOR(id)) {
    107 		case PCI_VENDOR_INTEL:
    108 			switch (PCI_PRODUCT(id)) {
    109 			case PCI_PRODUCT_INTEL_21555:
    110 			    return(1);
    111 			}
    112 			break;
    113 		}
    114 	}
    115 	return(0);
    116 }
    117 
    118 static void
    119 nppbattach(struct device *parent, struct device *self, void *aux)
    120 {
    121 	struct nppb_pci_softc *psc = (struct nppb_pci_softc *)self;
    122 	struct nppb_softc *sc = (struct nppb_softc *)self;
    123 	struct pci_attach_args *pa = aux;
    124 	pci_chipset_tag_t pc = pa->pa_pc;
    125 	pci_intr_handle_t ih;
    126 	const char *intrstr = NULL;
    127 	char devinfo[256];
    128 
    129 	bus_space_tag_t iot, memt;
    130 	bus_space_handle_t ioh, memh;
    131 	int ioh_valid, memh_valid;
    132 
    133 	psc->psc_pc = pc;
    134 	psc->psc_tag = pa->pa_tag;
    135 
    136 	sprintf(devinfo, "21555 Non-Transparent PCI-PCI Bridge");
    137 	aprint_normal(": %s, rev %d\n", devinfo, PCI_REVISION(pa->pa_class));
    138 
    139 	/* Make sure bus-mastering is enabled. */
    140 	pci_conf_write(psc->psc_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    141 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    142 	    PCI_COMMAND_MASTER_ENABLE);
    143 
    144 	/* Chip Reset */
    145 	pci_conf_write(psc->psc_pc, pa->pa_tag, 0xD8, 0x03);
    146 
    147 	/* Map control/status registers */
    148 	ioh_valid = (pci_mapreg_map(pa, NPPB_IOBA,
    149 			PCI_MAPREG_TYPE_IO, 0,
    150 			&iot, &ioh, NULL, NULL) == 0);
    151 	memh_valid = (pci_mapreg_map(pa, NPPB_MMBA,
    152 			PCI_MAPREG_TYPE_MEM |
    153 			PCI_MAPREG_MEM_TYPE_32BIT,
    154 			0, &memt, &memh, NULL, NULL) == 0);
    155 
    156 	if (memh_valid) {
    157 	    sc->sc_st = memt;
    158             sc->sc_sh = memh;
    159 	} else if (ioh_valid) {
    160 	    sc->sc_st = iot;
    161 	    sc->sc_sh = ioh;
    162 	} else {
    163 	    printf(": unable to map device registers\n");
    164 	    return;
    165 	}
    166 
    167 	/* Map and establish our interrupt */
    168 	if (pci_intr_map(pa, &ih)) {
    169 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    170 		return;
    171 	}
    172 	intrstr = pci_intr_string(pc, ih);
    173 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, nppb_intr, sc);
    174 	if (sc->sc_ih == NULL) {
    175 		printf("%s: couldn't establish interrupt",
    176 		    sc->sc_dev.dv_xname);
    177 		if (intrstr != NULL)
    178 			printf(" at %s", intrstr);
    179 		printf("\n");
    180 		return;
    181 	}
    182 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    183 
    184 }
    185 
    186 /* XXX */
    187 int
    188 nppb_intr(void *arg)
    189 {
    190 #if 0
    191 	struct nppb_softc *sc = arg;
    192 #endif
    193 #ifdef PCI_DEBUG
    194 	printf("nppb_intr assert\n");
    195 #endif
    196 	return(0);
    197 }
    198