Home | History | Annotate | Line # | Download | only in pci
dwlpx.c revision 1.15
      1 /* $NetBSD: dwlpx.c,v 1.15 1998/03/26 18:17:13 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.15 1998/03/26 18:17:13 thorpej Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/kernel.h>
     40 #include <sys/device.h>
     41 
     42 #include <vm/vm.h>
     43 
     44 #include <machine/autoconf.h>
     45 
     46 #include <dev/pci/pcireg.h>
     47 #include <dev/pci/pcivar.h>
     48 
     49 #include <alpha/tlsb/tlsbreg.h>
     50 #include <alpha/tlsb/kftxxvar.h>
     51 #include <alpha/tlsb/kftxxreg.h>
     52 #include <alpha/pci/dwlpxreg.h>
     53 #include <alpha/pci/dwlpxvar.h>
     54 #include <alpha/pci/pci_kn8ae.h>
     55 
     56 #define	KV(_addr)	((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
     57 #define	DWLPX_SYSBASE(sc)	\
     58 	    ((((unsigned long)((sc)->dwlpx_node - 4))	<< 36) |	\
     59 	     (((unsigned long) (sc)->dwlpx_hosenum)	<< 34) |	\
     60 	     (1LL					<< 39))
     61 
     62 
     63 static int	dwlpxmatch __P((struct device *, struct cfdata *, void *));
     64 static void	dwlpxattach __P((struct device *, struct device *, void *));
     65 struct cfattach dwlpx_ca = {
     66 	sizeof(struct dwlpx_softc), dwlpxmatch, dwlpxattach
     67 };
     68 
     69 extern struct cfdriver dwlpx_cd;
     70 
     71 static int	dwlpxprint __P((void *, const char *));
     72 static struct dwlpx_softc *dwlps[DWLPX_NIONODE][DWLPX_NHOSE];
     73 
     74 static int
     75 dwlpxprint(aux, pnp)
     76 	void *aux;
     77 	const char *pnp;
     78 {
     79 	register struct pcibus_attach_args *pba = aux;
     80 	/* only PCIs can attach to DWLPX's; easy. */
     81 	if (pnp)
     82 		printf("%s at %s", pba->pba_busname, pnp);
     83 	printf(" bus %d", pba->pba_bus);
     84 	return (UNCONF);
     85 }
     86 
     87 static int
     88 dwlpxmatch(parent, cf, aux)
     89 	struct device *parent;
     90 	struct cfdata *cf;
     91 	void *aux;
     92 {
     93 	struct kft_dev_attach_args *ka = aux;
     94 
     95 	if (strcmp(ka->ka_name, dwlpx_cd.cd_name) != 0)
     96 		return (0);
     97 	return (1);
     98 }
     99 
    100 static void
    101 dwlpxattach(parent, self, aux)
    102 	struct device *parent;
    103 	struct device *self;
    104 	void *aux;
    105 {
    106 	static int once = 0;
    107 	struct dwlpx_softc *sc = (struct dwlpx_softc *)self;
    108 	struct dwlpx_config *ccp = &sc->dwlpx_cc;
    109 	struct kft_dev_attach_args *ka = aux;
    110 	struct pcibus_attach_args pba;
    111 	u_int32_t pcia_present;
    112 
    113 	sc->dwlpx_node = ka->ka_node;
    114 	sc->dwlpx_dtype = ka->ka_dtype;
    115 	sc->dwlpx_hosenum = ka->ka_hosenum;
    116 	dwlps[sc->dwlpx_node - 4][sc->dwlpx_hosenum] = sc;
    117 	dwlpx_init(sc);
    118 
    119 	pcia_present = REGVAL(PCIA_PRESENT + ccp->cc_sysbase);
    120 	printf(": PCIA rev. %d, STD I/O %spresent, %s DMA maps.\n",
    121 	    (pcia_present >> PCIA_PRESENT_REVSHIFT) & PCIA_PRESENT_REVMASK,
    122 	    (pcia_present & PCIA_PRESENT_STDIO) == 0 ? "not " : "",
    123 #ifdef	MSS3_DEBUG_SG
    124 	    (sc->dwlpx_sgmapsz == DWLPX_SG128K)? "128K S/G" : "32K S/G");
    125 #else
    126 	    (physmem <= btoc(2048LL << 20LL))? "Direct" :
    127 	        (sc->dwlpx_sgmapsz == DWLPX_SG128K)? "128K S/G" : "32K S/G");
    128 #endif
    129 
    130 
    131 #if	0
    132 	{
    133 		int hpc, slot, slotval;
    134 		const char *str;
    135 		printf("%s: %sK Scatter/Gather RAM Entries Available.\n",
    136 			sc->dwlpx_dev.dv_xname,
    137 			sc->dwlpx_sgmapsz == DWLPX_SG32K?  "32" : "128");
    138 		for (hpc = 0; hpc < sc->dwlpx_nhpc; hpc++) {
    139 			for (slot = 0; slot < 4; slot++) {
    140 				slotval = (pcia_present >>
    141 				    PCIA_PRESENT_SLOTSHIFT(hpc, slot)) &
    142 				    PCIA_PRESENT_SLOT_MASK;
    143 				if (slotval == PCIA_PRESENT_SLOT_NONE)
    144 					continue;
    145 				switch (slotval) {
    146 				case PCIA_PRESENT_SLOT_25W:
    147 					str = "25";
    148 					break;
    149 				case PCIA_PRESENT_SLOT_15W:
    150 					str = "15";
    151 					break;
    152 				case PCIA_PRESENT_SLOW_7W:
    153 				default:		/* XXX gcc */
    154 					str = "7.5";
    155 					break;
    156 				}
    157 				printf("%s: hpc %d slot %d: %s watt module\n",
    158 				    sc->dwlpx_dev.dv_xname, hpc, slot, str);
    159 			}
    160 		}
    161 	}
    162 #endif
    163 
    164 	if (once == 0) {
    165 		/*
    166 		 * Set up interrupts
    167 		 */
    168 		pci_kn8ae_pickintr(&sc->dwlpx_cc, 1);
    169 #ifdef	EVCNT_COUNTERS
    170 		evcnt_attach(self, "intr", kn8ae_intr_evcnt);
    171 #endif
    172 		once++;
    173 	} else {
    174 		pci_kn8ae_pickintr(&sc->dwlpx_cc, 0);
    175 	}
    176 
    177 	/*
    178 	 * Attach PCI bus
    179 	 */
    180 	pba.pba_busname = "pci";
    181 	pba.pba_iot = &sc->dwlpx_cc.cc_iot;
    182 	pba.pba_memt = &sc->dwlpx_cc.cc_memt;
    183 	pba.pba_dmat =	/* start with direct, may change... */
    184 	    alphabus_dma_get_tag(&sc->dwlpx_cc.cc_dmat_direct, ALPHA_BUS_PCI);
    185 	pba.pba_pc = &sc->dwlpx_cc.cc_pc;
    186 	pba.pba_bus = 0;
    187 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    188 	config_found(self, &pba, dwlpxprint);
    189 }
    190 
    191 void
    192 dwlpx_init(sc)
    193 	struct dwlpx_softc *sc;
    194 {
    195 	int i;
    196 	u_int32_t ctl;
    197 	struct dwlpx_config *ccp = &sc->dwlpx_cc;
    198 	unsigned long ls = DWLPX_SYSBASE(sc);
    199 
    200 	if (ccp->cc_initted == 0) {
    201 		/*
    202 		 * On reads, you get a fault if you read a nonexisted HPC.
    203 		 * We know the internal KFTIA hose (hose 0) has only 2 HPCs,
    204 		 * but we can also actually probe for HPCs.
    205 		 * Assume at least one.
    206 		 */
    207 		for (sc->dwlpx_nhpc = 1; sc->dwlpx_nhpc < NHPC;
    208 		    sc->dwlpx_nhpc++) {
    209 			if (badaddr(KV(PCIA_CTL(sc->dwlpx_nhpc) + ls),
    210 			    sizeof (ctl)) != 0) {
    211 				break;
    212 			}
    213 		}
    214 		if (sc->dwlpx_nhpc != NHPC) {
    215 			/* clear (potential) Illegal CSR Address Error */
    216 			REGVAL(PCIA_ERR(0) + DWLPX_SYSBASE(sc)) =
    217 				PCIA_ERR_ALLERR;
    218 		}
    219 
    220 		dwlpx_bus_io_init(&ccp->cc_iot, ccp);
    221 		dwlpx_bus_mem_init(&ccp->cc_memt, ccp);
    222 	}
    223 	dwlpx_pci_init(&ccp->cc_pc, ccp);
    224 	ccp->cc_sc = sc;
    225 
    226 	/*
    227 	 * Establish a precalculated base for convenience's sake.
    228 	 */
    229 	ccp->cc_sysbase = ls;
    230 
    231 	/*
    232 	 * Set up DMA stuff for this DWLPX.
    233 	 */
    234 	dwlpx_dma_init(ccp);
    235 
    236 	/*
    237 	 * If there are only 2 HPCs, then the 'present' register is not
    238 	 * implemented, so there will only ever be 32K SG entries. Otherwise
    239 	 * any revision greater than zero will have 128K entries.
    240 	 */
    241 	ctl = REGVAL(PCIA_PRESENT + ccp->cc_sysbase);
    242 	if (sc->dwlpx_nhpc == 2) {
    243 		sc->dwlpx_sgmapsz = DWLPX_SG32K;
    244 #if	0
    245 	/*
    246 	 * As of 2/25/98- When I enable SG128K, and then have to flip
    247 	 * TBIT below, I get bad SGRAM errors. We'll fix this later
    248 	 * if this gets important.
    249 	 */
    250 	} else if ((ctl >> PCIA_PRESENT_REVSHIFT) & PCIA_PRESENT_REVMASK) {
    251 		sc->dwlpx_sgmapsz = DWLPX_SG128K;
    252 #endif
    253 	} else {
    254 		sc->dwlpx_sgmapsz = DWLPX_SG32K;
    255 	}
    256 
    257 	/*
    258 	 * Set up interrupt stuff for this DWLPX.
    259 	 *
    260 	 * Note that all PCI interrupt pins are disabled at this time.
    261 	 *
    262 	 * Do this even for all HPCs- even for the nonexistent
    263 	 * one on hose zero of a KFTIA.
    264 	 */
    265 	for (i = 0; i < NHPC; i++) {
    266 		REGVAL(PCIA_IMASK(i) + ccp->cc_sysbase) = DWLPX_IMASK_DFLT;
    267 		REGVAL(PCIA_ERRVEC(i) + ccp->cc_sysbase) =
    268 		    DWLPX_ERRVEC((sc->dwlpx_node - 4), sc->dwlpx_hosenum);
    269 	}
    270 	for (i = 0; i < DWLPX_MAXDEV; i++) {
    271 		u_int16_t vec;
    272 		int ss, hpc;
    273 
    274 		vec = DWLPX_MVEC((sc->dwlpx_node - 4), sc->dwlpx_hosenum, i);
    275 		ss = i;
    276 		if (i < 4) {
    277 			hpc = 0;
    278 		} else if (i < 8) {
    279 			ss -= 4;
    280 			hpc = 1;
    281 		} else {
    282 			ss -= 8;
    283 			hpc = 2;
    284 		}
    285 		REGVAL(PCIA_DEVVEC(hpc, ss, 1) + ccp->cc_sysbase) = vec;
    286 		REGVAL(PCIA_DEVVEC(hpc, ss, 2) + ccp->cc_sysbase) = vec;
    287 		REGVAL(PCIA_DEVVEC(hpc, ss, 3) + ccp->cc_sysbase) = vec;
    288 		REGVAL(PCIA_DEVVEC(hpc, ss, 4) + ccp->cc_sysbase) = vec;
    289 	}
    290 	/*
    291 	 * Establish HAE values, as well as make sure of sanity elsewhere.
    292 	 */
    293 	for (i = 0; i < sc->dwlpx_nhpc; i++) {
    294 		ctl = REGVAL(PCIA_CTL(i) + ccp->cc_sysbase);
    295 		ctl &= 0x0fffffff;
    296 		ctl &= ~(PCIA_CTL_MHAE(0x1f) | PCIA_CTL_IHAE(0x1f));
    297 		/*
    298 		 * I originally also had it or'ing in 3, which makes no sense.
    299 		 */
    300 
    301 		ctl |= PCIA_CTL_RMMENA | PCIA_CTL_RMMARB;
    302 
    303 		/*
    304 		 * Only valid if we're attached to a KFTIA or a KTHA.
    305 		 */
    306 		ctl |= PCIA_CTL_3UP;
    307 
    308 		ctl |= PCIA_CTL_CUTENA;
    309 
    310 		/*
    311 		 * Fit in appropriate S/G Map Ram size.
    312 		 */
    313 		if (sc->dwlpx_sgmapsz == DWLPX_SG32K)
    314 			ctl |= PCIA_CTL_SG32K;
    315 		else if (sc->dwlpx_sgmapsz == DWLPX_SG128K)
    316 			ctl |= PCIA_CTL_SG128K;
    317 		else
    318 			ctl |= PCIA_CTL_SG32K;
    319 
    320 		REGVAL(PCIA_CTL(i) + ccp->cc_sysbase) = ctl;
    321 	}
    322 	/*
    323 	 * Enable TBIT if required
    324 	 */
    325 	if (sc->dwlpx_sgmapsz == DWLPX_SG128K)
    326 		REGVAL(PCIA_TBIT + ccp->cc_sysbase) = 1;
    327 	alpha_mb();
    328 	ccp->cc_initted = 1;
    329 }
    330 
    331 void
    332 dwlpx_iointr(framep, vec)
    333 	void *framep;
    334 	unsigned long vec;
    335 {
    336 	struct dwlpx_softc *sc;
    337 	struct dwlpx_config *ccp;
    338 	int ionode, hosenum, i;
    339 	struct {
    340 		u_int32_t err;
    341 		u_int32_t addr;
    342 	} hpcs[NHPC];
    343 
    344 	ionode = (vec >> 8) & 0xf;
    345 	hosenum = (vec >> 4) & 0x7;
    346 	if (ionode >= DWLPX_NIONODE || hosenum >= DWLPX_NHOSE) {
    347 		panic("dwlpx_iointr: mangled vector %x", vec);
    348 		/* NOTREACHED */
    349 	}
    350 	sc = dwlps[ionode][hosenum];
    351 	ccp = &sc->dwlpx_cc;
    352 	for (i = 0; i < sc->dwlpx_nhpc; i++) {
    353 		hpcs[i].err = REGVAL(PCIA_ERR(i) + ccp->cc_sysbase);
    354 		hpcs[i].addr = REGVAL(PCIA_FADR(i) + ccp->cc_sysbase);
    355 	}
    356 	printf("%s: node %d hose %d error interrupt\n",
    357 		sc->dwlpx_dev.dv_xname, ionode + 4, hosenum);
    358 
    359 	for (i = 0; i < sc->dwlpx_nhpc; i++) {
    360 		if ((hpcs[i].err & PCIA_ERR_ERROR) == 0)
    361 			continue;
    362 		printf("\tHPC %d: ERR=0x%08x; DMA %s Memory, "
    363 			"Failing Address 0x%x\n",
    364 			i, hpcs[i].err, hpcs[i].addr & 0x1? "write to" :
    365 			"read from", hpcs[i].addr & ~3);
    366 		if (hpcs[i].err & PCIA_ERR_SERR_L)
    367 			printf("\t       PCI device asserted SERR_L\n");
    368 		if (hpcs[i].err & PCIA_ERR_ILAT)
    369 			printf("\t       Incremental Latency Exceeded\n");
    370 		if (hpcs[i].err & PCIA_ERR_SGPRTY)
    371 			printf("\t       CPU access of SG RAM Parity Error\n");
    372 		if (hpcs[i].err & PCIA_ERR_ILLCSR)
    373 			printf("\t       Illegal CSR Address Error\n");
    374 		if (hpcs[i].err & PCIA_ERR_PCINXM)
    375 			printf("\t       Nonexistent PCI Address Error\n");
    376 		if (hpcs[i].err & PCIA_ERR_DSCERR)
    377 			printf("\t       PCI Target Disconnect Error\n");
    378 		if (hpcs[i].err & PCIA_ERR_ABRT)
    379 			printf("\t       PCI Target Abort Error\n");
    380 		if (hpcs[i].err & PCIA_ERR_WPRTY)
    381 			printf("\t       PCI Write Parity Error\n");
    382 		if (hpcs[i].err & PCIA_ERR_DPERR)
    383 			printf("\t       PCI Data Parity Error\n");
    384 		if (hpcs[i].err & PCIA_ERR_APERR)
    385 			printf("\t       PCI Address Parity Error\n");
    386 		if (hpcs[i].err & PCIA_ERR_DFLT)
    387 			printf("\t       SG Map RAM Invalid Entry Error\n");
    388 		if (hpcs[i].err & PCIA_ERR_DPRTY)
    389 			printf("\t       DMA access of SG RAM Parity Error\n");
    390 		if (hpcs[i].err & PCIA_ERR_DRPERR)
    391 			printf("\t       DMA Read Return Parity Error\n");
    392 		if (hpcs[i].err & PCIA_ERR_MABRT)
    393 			printf("\t       PCI Master Abort Error\n");
    394 		if (hpcs[i].err & PCIA_ERR_CPRTY)
    395 			printf("\t       CSR Parity Error\n");
    396 		if (hpcs[i].err & PCIA_ERR_COVR)
    397 			printf("\t       CSR Overrun Error\n");
    398 		if (hpcs[i].err & PCIA_ERR_MBPERR)
    399 			printf("\t       Mailbox Parity Error\n");
    400 		if (hpcs[i].err & PCIA_ERR_MBILI)
    401 			printf("\t       Mailbox Illegal Length Error\n");
    402 		REGVAL(PCIA_ERR(i) + ccp->cc_sysbase) = hpcs[i].err;
    403 	}
    404 }
    405