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