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