Home | History | Annotate | Line # | Download | only in pci
pci_eb164.c revision 1.19
      1 /* $NetBSD: pci_eb164.c,v 1.19 1998/07/07 21:44:58 thorpej Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     42  * All rights reserved.
     43  *
     44  * Author: Chris G. Demetriou
     45  *
     46  * Permission to use, copy, modify and distribute this software and
     47  * its documentation is hereby granted, provided that both the copyright
     48  * notice and this permission notice appear in all copies of the
     49  * software, derivative works or modified versions, and any portions
     50  * thereof, and that both notices appear in supporting documentation.
     51  *
     52  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     53  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     54  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     55  *
     56  * Carnegie Mellon requests users of this software to return to
     57  *
     58  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     59  *  School of Computer Science
     60  *  Carnegie Mellon University
     61  *  Pittsburgh PA 15213-3890
     62  *
     63  * any improvements or extensions that they make and grant Carnegie the
     64  * rights to redistribute these changes.
     65  */
     66 
     67 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     68 
     69 __KERNEL_RCSID(0, "$NetBSD: pci_eb164.c,v 1.19 1998/07/07 21:44:58 thorpej Exp $");
     70 
     71 #include <sys/types.h>
     72 #include <sys/param.h>
     73 #include <sys/time.h>
     74 #include <sys/systm.h>
     75 #include <sys/errno.h>
     76 #include <sys/malloc.h>
     77 #include <sys/device.h>
     78 #include <sys/syslog.h>
     79 
     80 #include <vm/vm.h>
     81 
     82 #include <machine/autoconf.h>
     83 #include <machine/rpb.h>
     84 
     85 #include <dev/pci/pcireg.h>
     86 #include <dev/pci/pcivar.h>
     87 #include <dev/pci/pciidereg.h>
     88 #include <dev/pci/pciidevar.h>
     89 
     90 #include <alpha/pci/ciareg.h>
     91 #include <alpha/pci/ciavar.h>
     92 
     93 #include <alpha/pci/pci_eb164.h>
     94 
     95 #ifndef EVCNT_COUNTERS
     96 #include <machine/intrcnt.h>
     97 #endif
     98 
     99 #include "sio.h"
    100 #if NSIO
    101 #include <alpha/pci/siovar.h>
    102 #endif
    103 
    104 int	dec_eb164_intr_map __P((void *, pcitag_t, int, int,
    105 	    pci_intr_handle_t *));
    106 const char *dec_eb164_intr_string __P((void *, pci_intr_handle_t));
    107 void	*dec_eb164_intr_establish __P((void *, pci_intr_handle_t,
    108 	    int, int (*func)(void *), void *));
    109 void	dec_eb164_intr_disestablish __P((void *, void *));
    110 
    111 void	*dec_eb164_pciide_compat_intr_establish __P((void *, struct device *,
    112 	    struct pci_attach_args *, int, int (*)(void *), void *));
    113 
    114 #define	EB164_SIO_IRQ	4
    115 #define	EB164_MAX_IRQ	24
    116 #define	PCI_STRAY_MAX	5
    117 
    118 struct alpha_shared_intr *eb164_pci_intr;
    119 #ifdef EVCNT_COUNTERS
    120 struct evcnt eb164_intr_evcnt;
    121 #endif
    122 
    123 bus_space_tag_t eb164_intrgate_iot;
    124 bus_space_handle_t eb164_intrgate_ioh;
    125 
    126 void	eb164_iointr __P((void *framep, unsigned long vec));
    127 extern void	eb164_intr_enable __P((int irq));	/* pci_eb164_intr.S */
    128 extern void	eb164_intr_disable __P((int irq));	/* pci_eb164_intr.S */
    129 
    130 void
    131 pci_eb164_pickintr(ccp)
    132 	struct cia_config *ccp;
    133 {
    134 	bus_space_tag_t iot = &ccp->cc_iot;
    135 	pci_chipset_tag_t pc = &ccp->cc_pc;
    136 	int i;
    137 
    138         pc->pc_intr_v = ccp;
    139         pc->pc_intr_map = dec_eb164_intr_map;
    140         pc->pc_intr_string = dec_eb164_intr_string;
    141         pc->pc_intr_establish = dec_eb164_intr_establish;
    142         pc->pc_intr_disestablish = dec_eb164_intr_disestablish;
    143 
    144 	pc->pc_pciide_compat_intr_establish =
    145 	    dec_eb164_pciide_compat_intr_establish;
    146 
    147 	eb164_intrgate_iot = iot;
    148 	if (bus_space_map(eb164_intrgate_iot, 0x804, 3, 0,
    149 	    &eb164_intrgate_ioh) != 0)
    150 		panic("pci_eb164_pickintr: couldn't map interrupt PLD");
    151 	for (i = 0; i < EB164_MAX_IRQ; i++)
    152 		eb164_intr_disable(i);
    153 
    154 	eb164_pci_intr = alpha_shared_intr_alloc(EB164_MAX_IRQ);
    155 	for (i = 0; i < EB164_MAX_IRQ; i++)
    156 		alpha_shared_intr_set_maxstrays(eb164_pci_intr, i,
    157 			PCI_STRAY_MAX);
    158 
    159 #if NSIO
    160 	sio_intr_setup(pc, iot);
    161 	eb164_intr_enable(EB164_SIO_IRQ);
    162 #endif
    163 
    164 	set_iointr(eb164_iointr);
    165 }
    166 
    167 int
    168 dec_eb164_intr_map(ccv, bustag, buspin, line, ihp)
    169         void *ccv;
    170         pcitag_t bustag;
    171         int buspin, line;
    172         pci_intr_handle_t *ihp;
    173 {
    174 	struct cia_config *ccp = ccv;
    175 	pci_chipset_tag_t pc = &ccp->cc_pc;
    176 	int bus, device, function;
    177 	u_int64_t variation;
    178 
    179 	if (buspin == 0) {
    180 		/* No IRQ used. */
    181 		return 1;
    182 	}
    183 	if (buspin > 4) {
    184 		printf("dec_eb164_intr_map: bad interrupt pin %d\n", buspin);
    185 		return 1;
    186 	}
    187 
    188 	alpha_pci_decompose_tag(pc, bustag, &bus, &device, &function);
    189 
    190 	variation = hwrpb->rpb_variation & SV_ST_MASK;
    191 
    192 	/*
    193 	 *
    194 	 * The AlphaPC 164 and AlphaPC 164LX have a CMD PCI IDE controller
    195 	 * at bus 0 device 11.  These are wired to compatibility mode,
    196 	 * so do not map their interrupts.
    197 	 *
    198 	 * The AlphaPC 164SX has PCI IDE on functions 1 and 2 of the
    199 	 * Cypress PCI-ISA bridge at bus 0 device 8.  These, too, are
    200 	 * wired to compatibility mode.
    201 	 *
    202 	 * Real EB164s have ISA IDE on the Super I/O chip.
    203 	 */
    204 	if (bus == 0) {
    205 		if (variation >= SV_ST_ALPHAPC164_366 &&
    206 		    variation <= SV_ST_ALPHAPC164LX_600) {
    207 			if (device == 8)
    208 				panic("dec_eb164_intr_map: SIO device");
    209 			if (device == 11)
    210 				return (1);
    211 		} else if (variation >= SV_ST_ALPHAPC164SX_400 &&
    212 			   variation <= SV_ST_ALPHAPC164SX_600) {
    213 			if (device == 8) {
    214 				if (function == 0)
    215 					panic("dec_eb164_intr_map: SIO device");
    216 				return (1);
    217 			}
    218 		} else {
    219 			if (device == 8)
    220 				panic("dec_eb164_intr_map: SIO device");
    221 		}
    222 	}
    223 
    224 	/*
    225 	 * The console places the interrupt mapping in the "line" value.
    226 	 * A value of (char)-1 indicates there is no mapping.
    227 	 */
    228 	if (line == 0xff) {
    229 		printf("dec_eb164_intr_map: no mapping for %d/%d/%d\n",
    230 		    bus, device, function);
    231 		return (1);
    232 	}
    233 
    234 	if (line > EB164_MAX_IRQ)
    235 		panic("dec_eb164_intr_map: eb164 irq too large (%d)\n",
    236 		    line);
    237 
    238 	*ihp = line;
    239 	return (0);
    240 }
    241 
    242 const char *
    243 dec_eb164_intr_string(ccv, ih)
    244 	void *ccv;
    245 	pci_intr_handle_t ih;
    246 {
    247 #if 0
    248 	struct cia_config *ccp = ccv;
    249 #endif
    250         static char irqstr[15];          /* 11 + 2 + NULL + sanity */
    251 
    252         if (ih > EB164_MAX_IRQ)
    253                 panic("dec_eb164_intr_string: bogus eb164 IRQ 0x%x\n", ih);
    254         sprintf(irqstr, "eb164 irq %d", ih);
    255         return (irqstr);
    256 }
    257 
    258 void *
    259 dec_eb164_intr_establish(ccv, ih, level, func, arg)
    260         void *ccv, *arg;
    261         pci_intr_handle_t ih;
    262         int level;
    263         int (*func) __P((void *));
    264 {
    265 #if 0
    266 	struct cia_config *ccp = ccv;
    267 #endif
    268 	void *cookie;
    269 
    270 	if (ih > EB164_MAX_IRQ)
    271 		panic("dec_eb164_intr_establish: bogus eb164 IRQ 0x%x\n", ih);
    272 
    273 	cookie = alpha_shared_intr_establish(eb164_pci_intr, ih, IST_LEVEL,
    274 	    level, func, arg, "eb164 irq");
    275 
    276 	if (cookie != NULL && alpha_shared_intr_isactive(eb164_pci_intr, ih))
    277 		eb164_intr_enable(ih);
    278 	return (cookie);
    279 }
    280 
    281 void
    282 dec_eb164_intr_disestablish(ccv, cookie)
    283         void *ccv, *cookie;
    284 {
    285 #if 0
    286 	struct cia_config *ccp = ccv;
    287 #endif
    288 
    289 	panic("dec_eb164_intr_disestablish not implemented"); /* XXX */
    290 }
    291 
    292 void *
    293 dec_eb164_pciide_compat_intr_establish(v, dev, pa, chan, func, arg)
    294 	void *v;
    295 	struct device *dev;
    296 	struct pci_attach_args *pa;
    297 	int chan;
    298 	int (*func) __P((void *));
    299 	void *arg;
    300 {
    301 	pci_chipset_tag_t pc = pa->pa_pc;
    302 	void *cookie = NULL;
    303 	int bus, irq;
    304 
    305 	alpha_pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
    306 
    307 	/*
    308 	 * If this isn't PCI bus #0, all bets are off.
    309 	 */
    310 	if (bus != 0)
    311 		return (NULL);
    312 
    313 	irq = PCIIDE_COMPAT_IRQ(chan);
    314 #if NSIO
    315 	cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO,
    316 	    func, arg);
    317 #endif
    318 	return (cookie);
    319 }
    320 
    321 void
    322 eb164_iointr(framep, vec)
    323 	void *framep;
    324 	unsigned long vec;
    325 {
    326 	int irq;
    327 
    328 	if (vec >= 0x900) {
    329 		if (vec >= 0x900 + (EB164_MAX_IRQ << 4))
    330 			panic("eb164_iointr: vec 0x%x out of range\n", vec);
    331 		irq = (vec - 0x900) >> 4;
    332 
    333 #ifdef EVCNT_COUNTERS
    334 		eb164_intr_evcnt.ev_count++;
    335 #else
    336 		if (EB164_MAX_IRQ != INTRCNT_EB164_IRQ_LEN)
    337 			panic("eb164 interrupt counter sizes inconsistent");
    338 		intrcnt[INTRCNT_EB164_IRQ + irq]++;
    339 #endif
    340 
    341 		if (!alpha_shared_intr_dispatch(eb164_pci_intr, irq)) {
    342 			alpha_shared_intr_stray(eb164_pci_intr, irq,
    343 			    "eb164 irq");
    344 			if (ALPHA_SHARED_INTR_DISABLE(&eb164_pci_intr[irq]))
    345 				eb164_intr_disable(irq);
    346 		}
    347 		return;
    348 	}
    349 #if NSIO
    350 	if (vec >= 0x800) {
    351 		sio_iointr(framep, vec);
    352 		return;
    353 	}
    354 #endif
    355 	panic("eb164_iointr: weird vec 0x%x\n", vec);
    356 }
    357 
    358 #if 0		/* THIS DOES NOT WORK!  see pci_eb164_intr.S. */
    359 u_int8_t eb164_intr_mask[3] = { 0xff, 0xff, 0xff };
    360 
    361 void
    362 eb164_intr_enable(irq)
    363 	int irq;
    364 {
    365 	int byte = (irq / 8), bit = (irq % 8);
    366 
    367 #if 1
    368 	printf("eb164_intr_enable: enabling %d (%d:%d)\n", irq, byte, bit);
    369 #endif
    370 	eb164_intr_mask[byte] &= ~(1 << bit);
    371 
    372 	bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
    373 	    eb164_intr_mask[byte]);
    374 }
    375 
    376 void
    377 eb164_intr_disable(irq)
    378 	int irq;
    379 {
    380 	int byte = (irq / 8), bit = (irq % 8);
    381 
    382 #if 1
    383 	printf("eb164_intr_disable: disabling %d (%d:%d)\n", irq, byte, bit);
    384 #endif
    385 	eb164_intr_mask[byte] |= (1 << bit);
    386 
    387 	bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
    388 	    eb164_intr_mask[byte]);
    389 }
    390 #endif
    391