Home | History | Annotate | Line # | Download | only in pci
dwlpx.c revision 1.13
      1 /* $NetBSD: dwlpx.c,v 1.13 1998/01/12 10:21:12 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1997 by Matthew Jacob
      5  * NASA AMES Research Center.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice immediately at the beginning of the file, without modification,
     13  *    this list of conditions, and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. 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 AND CONTRIBUTORS ``AS IS'' AND
     21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     24  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30  * SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     34 
     35 __KERNEL_RCSID(0, "$NetBSD: dwlpx.c,v 1.13 1998/01/12 10:21:12 thorpej Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/kernel.h>
     40 #include <sys/device.h>
     41 #include <vm/vm.h>
     42 
     43 #include <machine/autoconf.h>
     44 #include <dev/pci/pcireg.h>
     45 #include <dev/pci/pcivar.h>
     46 #include <alpha/tlsb/tlsbreg.h>
     47 #include <alpha/tlsb/kftxxvar.h>
     48 #include <alpha/tlsb/kftxxreg.h>
     49 #include <alpha/pci/dwlpxreg.h>
     50 #include <alpha/pci/dwlpxvar.h>
     51 #include <alpha/pci/pci_kn8ae.h>
     52 
     53 #include <alpha/include/pmap.old.h>
     54 
     55 #define	KV(_addr)	((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
     56 
     57 static int	dwlpxmatch __P((struct device *, struct cfdata *, void *));
     58 static void	dwlpxattach __P((struct device *, struct device *, void *));
     59 
     60 struct cfattach dwlpx_ca = {
     61 	sizeof(struct dwlpx_softc), dwlpxmatch, dwlpxattach
     62 };
     63 
     64 extern struct cfdriver dwlpx_cd;
     65 
     66 static int	dwlpxprint __P((void *, const char *));
     67 
     68 static int
     69 dwlpxprint(aux, pnp)
     70 	void *aux;
     71 	const char *pnp;
     72 {
     73 	register struct pcibus_attach_args *pba = aux;
     74 	/* only PCIs can attach to DWLPX's; easy. */
     75 	if (pnp)
     76 		printf("%s at %s", pba->pba_busname, pnp);
     77 	printf(" bus %d", pba->pba_bus);
     78 	return (UNCONF);
     79 }
     80 
     81 static int
     82 dwlpxmatch(parent, cf, aux)
     83 	struct device *parent;
     84 	struct cfdata *cf;
     85 	void *aux;
     86 {
     87 	struct kft_dev_attach_args *ka = aux;
     88 
     89 	if (strcmp(ka->ka_name, dwlpx_cd.cd_name) != 0)
     90 		return (0);
     91 	return (1);
     92 }
     93 
     94 static void
     95 dwlpxattach(parent, self, aux)
     96 	struct device *parent;
     97 	struct device *self;
     98 	void *aux;
     99 {
    100 	static int once = 0;
    101 	struct dwlpx_softc *sc = (struct dwlpx_softc *)self;
    102 	struct dwlpx_config *ccp = &sc->dwlpx_cc;
    103 	struct kft_dev_attach_args *ka = aux;
    104 	struct pcibus_attach_args pba;
    105 	u_int32_t pcia_present;
    106 
    107 	sc->dwlpx_node = ka->ka_node;
    108 	sc->dwlpx_dtype = ka->ka_dtype;
    109 	sc->dwlpx_hosenum = ka->ka_hosenum;
    110 	/*
    111 	 * On reads, you get a fault if you read a nonexisted HPC.
    112 	 * The internal KFTIA hose (hose 0) has only 2 HPCs.
    113 	 */
    114 	sc->dwlpx_nhpc = NHPC;
    115 	if (sc->dwlpx_hosenum == 0) {
    116 		if (TLDEV_DTYPE(sc->dwlpx_dtype) == TLDEV_DTYPE_KFTIA) {
    117 			sc->dwlpx_nhpc = NHPC - 1;
    118 		}
    119 	}
    120 
    121 	dwlpx_init(sc);
    122 
    123 	/* XXX Need to detect DWLPA vs. DWLPB here. */
    124 	pcia_present = REGVAL(PCIA_PRESENT + ccp->cc_sysbase);
    125 
    126 	printf(": PCIA rev. %d, STD I/O %spresent\n",
    127 	    (pcia_present >> PCIA_PRESENT_REVSHIFT) & PCIA_PRESENT_REVMASK,
    128 	    (pcia_present & PCIA_PRESENT_STDIO) == 0 ? "not " : "");
    129 
    130 #if 0
    131 	{
    132 		int hpc, slot, slotval;
    133 		const char *str;
    134 
    135 		for (hpc = 0; hpc < sc->dwlpx_nhpc; hpc++) {
    136 			for (slot = 0; slot < 4; slot++) {
    137 				slotval = (pcia_present >>
    138 				    PCIA_PRESENT_SLOTSHIFT(hpc, slot)) &
    139 				    PCIA_PRESENT_SLOT_MASK;
    140 				if (slotval == PCIA_PRESENT_SLOT_NONE)
    141 					continue;
    142 				switch (slotval) {
    143 				case PCIA_PRESENT_SLOT_25W:
    144 					str = "25";
    145 					break;
    146 				case PCIA_PRESENT_SLOT_15W:
    147 					str = "15";
    148 					break;
    149 				case PCIA_PRESENT_SLOW_7W:
    150 				default:		/* XXX gcc */
    151 					str = "7.5";
    152 					break;
    153 				}
    154 				printf("%s: hpc %d slot %d: %s watt module\n",
    155 				    sc->dwlpx_dev.dv_xname, hpc, slot, str);
    156 			}
    157 		}
    158 	}
    159 #endif
    160 
    161 	if (once == 0) {
    162 		/*
    163 		 * Set up interrupts
    164 		 */
    165 		pci_kn8ae_pickintr(&sc->dwlpx_cc, 1);
    166 #ifdef	EVCNT_COUNTERS
    167 		evcnt_attach(self, "intr", kn8ae_intr_evcnt);
    168 #endif
    169 		once++;
    170 	} else {
    171 		pci_kn8ae_pickintr(&sc->dwlpx_cc, 0);
    172 	}
    173 
    174 	/*
    175 	 * Attach PCI bus
    176 	 */
    177 	pba.pba_busname = "pci";
    178 	pba.pba_iot = &sc->dwlpx_cc.cc_iot;
    179 	pba.pba_memt = &sc->dwlpx_cc.cc_memt;
    180 	pba.pba_dmat =	/* start with direct, may change... */
    181 	    alphabus_dma_get_tag(&sc->dwlpx_cc.cc_dmat_direct, ALPHA_BUS_PCI);
    182 	pba.pba_pc = &sc->dwlpx_cc.cc_pc;
    183 	pba.pba_bus = 0;
    184 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    185 	config_found(self, &pba, dwlpxprint);
    186 }
    187 
    188 void
    189 dwlpx_init(sc)
    190 	struct dwlpx_softc *sc;
    191 {
    192 	int i;
    193 	struct dwlpx_config *ccp = &sc->dwlpx_cc;
    194 
    195 	if (ccp->cc_initted == 0) {
    196 		dwlpx_bus_io_init(&ccp->cc_iot, ccp);
    197 		dwlpx_bus_mem_init(&ccp->cc_memt, ccp);
    198 	}
    199 	dwlpx_pci_init(&ccp->cc_pc, ccp);
    200 	ccp->cc_sc = sc;
    201 
    202 	/*
    203 	 * Establish a precalculated base for convenience's sake.
    204 	 */
    205 	ccp->cc_sysbase =
    206 	    (((unsigned long)(sc->dwlpx_node - 4))	<< 36) |
    207 	    (((unsigned long) sc->dwlpx_hosenum)	<< 34) |
    208 	    (1LL					<< 39);
    209 
    210 	/*
    211 	 * Set up DMA stuff for this DWLPX.
    212 	 */
    213 	dwlpx_dma_init(ccp);
    214 
    215 	/*
    216 	 * Set up interrupt stuff for this DWLPX.
    217 	 *
    218 	 * Note that all PCI interrupt pins are disabled at this time.
    219 	 *
    220 	 * Do this even for all HPCs- even for the nonexistent
    221 	 * one on hose zero of a KFTIA.
    222 	 */
    223 	for (i = 0; i < NHPC; i++) {
    224 		REGVAL(PCIA_IMASK(i) + ccp->cc_sysbase) = DWLPX_IMASK_DFLT;
    225 		REGVAL(PCIA_ERRVEC(i) + ccp->cc_sysbase) =
    226 		    DWLPX_ERRVEC((sc->dwlpx_node - 4), sc->dwlpx_hosenum);
    227 	}
    228 	for (i = 0; i < DWLPX_MAXDEV; i++) {
    229 		u_int16_t vec;
    230 		int ss, hpc;
    231 
    232 		vec = DWLPX_MVEC((sc->dwlpx_node - 4), sc->dwlpx_hosenum, i);
    233 		ss = i;
    234 		if (i < 4) {
    235 			hpc = 0;
    236 		} else if (i < 8) {
    237 			ss -= 4;
    238 			hpc = 1;
    239 		} else {
    240 			ss -= 8;
    241 			hpc = 2;
    242 		}
    243 		REGVAL(PCIA_DEVVEC(hpc, ss, 1) + ccp->cc_sysbase) = vec;
    244 		REGVAL(PCIA_DEVVEC(hpc, ss, 2) + ccp->cc_sysbase) = vec;
    245 		REGVAL(PCIA_DEVVEC(hpc, ss, 3) + ccp->cc_sysbase) = vec;
    246 		REGVAL(PCIA_DEVVEC(hpc, ss, 4) + ccp->cc_sysbase) = vec;
    247 	}
    248 	/*
    249 	 * Establish HAE values, as well as make sure of sanity elsewhere.
    250 	 */
    251 	for (i = 0; i < sc->dwlpx_nhpc; i++) {
    252 		u_int32_t ctl = REGVAL(PCIA_CTL(i) + ccp->cc_sysbase);
    253 		ctl &= 0x0fffffff;
    254 		ctl &= ~(PCIA_CTL_MHAE(0x1f) | PCIA_CTL_IHAE(0x1f));
    255 		/*
    256 		 * I originally also had it or'ing in 3, which makes no sense.
    257 		 */
    258 
    259 		ctl |= PCIA_CTL_RMMENA | PCIA_CTL_RMMARB;
    260 
    261 		/*
    262 		 * Only valid if we're attached to a KFTIA or a KTHA.
    263 		 */
    264 		ctl |= PCIA_CTL_3UP;
    265 
    266 		ctl |= PCIA_CTL_CUTENA;
    267 
    268 		REGVAL(PCIA_CTL(i) + ccp->cc_sysbase) = ctl;
    269 	}
    270 	ccp->cc_initted = 1;
    271 }
    272