Home | History | Annotate | Line # | Download | only in pci
pci_eb66.c revision 1.6
      1 /* $NetBSD: pci_eb66.c,v 1.6 2000/06/04 19:14:24 cgd 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_eb66.c,v 1.6 2000/06/04 19:14:24 cgd 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 
     84 #include <dev/pci/pcireg.h>
     85 #include <dev/pci/pcivar.h>
     86 
     87 #include <alpha/pci/lcareg.h>
     88 #include <alpha/pci/lcavar.h>
     89 
     90 #include <alpha/pci/pci_eb66.h>
     91 
     92 #include <machine/intrcnt.h>
     93 
     94 #include "sio.h"
     95 #if NSIO
     96 #include <alpha/pci/siovar.h>
     97 #endif
     98 
     99 int	dec_eb66_intr_map __P((void *, pcitag_t, int, int,
    100 	    pci_intr_handle_t *));
    101 const char *dec_eb66_intr_string __P((void *, pci_intr_handle_t));
    102 const struct evcnt *dec_eb66_intr_evcnt __P((void *, pci_intr_handle_t));
    103 void	*dec_eb66_intr_establish __P((void *, pci_intr_handle_t,
    104 	    int, int (*func)(void *), void *));
    105 void	dec_eb66_intr_disestablish __P((void *, void *));
    106 
    107 #define	EB66_MAX_IRQ		32
    108 #define	PCI_STRAY_MAX		5
    109 
    110 struct alpha_shared_intr *eb66_pci_intr;
    111 
    112 bus_space_tag_t eb66_intrgate_iot;
    113 bus_space_handle_t eb66_intrgate_ioh;
    114 
    115 void	eb66_iointr __P((void *framep, unsigned long vec));
    116 extern void	eb66_intr_enable __P((int irq));  /* pci_eb66_intr.S */
    117 extern void	eb66_intr_disable __P((int irq)); /* pci_eb66_intr.S */
    118 
    119 void
    120 pci_eb66_pickintr(lcp)
    121 	struct lca_config *lcp;
    122 {
    123 	bus_space_tag_t iot = &lcp->lc_iot;
    124 	pci_chipset_tag_t pc = &lcp->lc_pc;
    125 	int i;
    126 
    127         pc->pc_intr_v = lcp;
    128         pc->pc_intr_map = dec_eb66_intr_map;
    129         pc->pc_intr_string = dec_eb66_intr_string;
    130 	pc->pc_intr_evcnt = dec_eb66_intr_evcnt;
    131         pc->pc_intr_establish = dec_eb66_intr_establish;
    132         pc->pc_intr_disestablish = dec_eb66_intr_disestablish;
    133 
    134 	/* Not supported on the EB66. */
    135 	pc->pc_pciide_compat_intr_establish = NULL;
    136 
    137 	eb66_intrgate_iot = iot;
    138 	if (bus_space_map(eb66_intrgate_iot, 0x804, 3, 0,
    139 	    &eb66_intrgate_ioh) != 0)
    140 		panic("pci_eb66_pickintr: couldn't map interrupt PLD");
    141 	for (i = 0; i < EB66_MAX_IRQ; i++)
    142 		eb66_intr_disable(i);
    143 
    144 	eb66_pci_intr = alpha_shared_intr_alloc(EB66_MAX_IRQ);
    145 	for (i = 0; i < EB66_MAX_IRQ; i++)
    146 		alpha_shared_intr_set_maxstrays(eb66_pci_intr, i,
    147 			PCI_STRAY_MAX);
    148 
    149 #if NSIO
    150 	sio_intr_setup(pc, iot);
    151 #endif
    152 
    153 	set_iointr(eb66_iointr);
    154 }
    155 
    156 int
    157 dec_eb66_intr_map(lcv, bustag, buspin, line, ihp)
    158         void *lcv;
    159         pcitag_t bustag;
    160         int buspin, line;
    161         pci_intr_handle_t *ihp;
    162 {
    163 	struct lca_config *lcp = lcv;
    164 	pci_chipset_tag_t pc = &lcp->lc_pc;
    165 	int bus, device, function;
    166 
    167 	if (buspin == 0) {
    168 		/* No IRQ used. */
    169 		return 1;
    170 	}
    171 	if (buspin > 4) {
    172 		printf("dec_eb66_intr_map: bad interrupt pin %d\n", buspin);
    173 		return 1;
    174 	}
    175 
    176 	alpha_pci_decompose_tag(pc, bustag, &bus, &device, &function);
    177 
    178 	/*
    179 	 * The console places the interrupt mapping in the "line" value.
    180 	 * A value of (char)-1 indicates there is no mapping.
    181 	 */
    182 	if (line == 0xff) {
    183 		printf("dec_eb66_intr_map: no mapping for %d/%d/%d\n",
    184 		    bus, device, function);
    185 		return (1);
    186 	}
    187 
    188 	if (line >= EB66_MAX_IRQ)
    189 		panic("dec_eb66_intr_map: eb66 irq too large (%d)\n",
    190 		    line);
    191 
    192 	*ihp = line;
    193 	return (0);
    194 }
    195 
    196 const char *
    197 dec_eb66_intr_string(lcv, ih)
    198 	void *lcv;
    199 	pci_intr_handle_t ih;
    200 {
    201         static char irqstr[15];          /* 11 + 2 + NULL + sanity */
    202 
    203 	if (ih >= EB66_MAX_IRQ)
    204 		panic("dec_eb66_intr_string: bogus eb66 IRQ 0x%lx\n", ih);
    205 	sprintf(irqstr, "eb66 irq %ld", ih);
    206 	return (irqstr);
    207 }
    208 
    209 const struct evcnt *
    210 dec_eb66_intr_evcnt(lcv, ih)
    211 	void *lcv;
    212 	pci_intr_handle_t ih;
    213 {
    214 
    215 	/* XXX for now, no evcnt parent reported */
    216 	return (NULL);
    217 }
    218 
    219 void *
    220 dec_eb66_intr_establish(lcv, ih, level, func, arg)
    221         void *lcv, *arg;
    222         pci_intr_handle_t ih;
    223         int level;
    224         int (*func) __P((void *));
    225 {
    226 	void *cookie;
    227 
    228 	if (ih >= EB66_MAX_IRQ)
    229 		panic("dec_eb66_intr_establish: bogus eb66 IRQ 0x%lx\n", ih);
    230 
    231 	cookie = alpha_shared_intr_establish(eb66_pci_intr, ih, IST_LEVEL,
    232 	    level, func, arg, "eb66 irq");
    233 
    234 	if (cookie != NULL && alpha_shared_intr_isactive(eb66_pci_intr, ih))
    235 		eb66_intr_enable(ih);
    236 	return (cookie);
    237 }
    238 
    239 void
    240 dec_eb66_intr_disestablish(lcv, cookie)
    241         void *lcv, *cookie;
    242 {
    243 	struct alpha_shared_intrhand *ih = cookie;
    244 	unsigned int irq = ih->ih_num;
    245 	int s;
    246 
    247 	s = splhigh();
    248 
    249 	alpha_shared_intr_disestablish(eb66_pci_intr, cookie,
    250 	    "eb66 irq");
    251 	if (alpha_shared_intr_isactive(eb66_pci_intr, irq) == 0) {
    252 		eb66_intr_disable(irq);
    253 		alpha_shared_intr_set_dfltsharetype(eb66_pci_intr, irq,
    254 		    IST_NONE);
    255 	}
    256 
    257 	splx(s);
    258 }
    259 
    260 void
    261 eb66_iointr(framep, vec)
    262 	void *framep;
    263 	unsigned long vec;
    264 {
    265 	int irq;
    266 
    267 	if (vec >= 0x900) {
    268 		if (vec >= 0x900 + (EB66_MAX_IRQ << 4))
    269 			panic("eb66_iointr: vec 0x%lx out of range\n", vec);
    270 		irq = (vec - 0x900) >> 4;
    271 
    272 		if (EB66_MAX_IRQ != INTRCNT_EB66_IRQ_LEN)
    273 			panic("eb66 interrupt counter sizes inconsistent");
    274 		intrcnt[INTRCNT_EB66_IRQ + irq]++;
    275 
    276 		if (!alpha_shared_intr_dispatch(eb66_pci_intr, irq)) {
    277 			alpha_shared_intr_stray(eb66_pci_intr, irq,
    278 			    "eb66 irq");
    279 			if (ALPHA_SHARED_INTR_DISABLE(eb66_pci_intr, irq))
    280 				eb66_intr_disable(irq);
    281 		}
    282 		return;
    283 	}
    284 #if NSIO
    285 	if (vec >= 0x800) {
    286 		sio_iointr(framep, vec);
    287 		return;
    288 	}
    289 #endif
    290 	panic("eb66_iointr: weird vec 0x%lx\n", vec);
    291 }
    292 
    293 #if 0		/* THIS DOES NOT WORK!  see pci_eb66_intr.S. */
    294 u_int8_t eb66_intr_mask[3] = { 0xff, 0xff, 0xff };
    295 
    296 void
    297 eb66_intr_enable(irq)
    298 	int irq;
    299 {
    300 	int byte = (irq / 8), bit = (irq % 8);
    301 
    302 #if 1
    303 	printf("eb66_intr_enable: enabling %d (%d:%d)\n", irq, byte, bit);
    304 #endif
    305 	eb66_intr_mask[byte] &= ~(1 << bit);
    306 
    307 	bus_space_write_1(eb66_intrgate_iot, eb66_intrgate_ioh, byte,
    308 	    eb66_intr_mask[byte]);
    309 }
    310 
    311 void
    312 eb66_intr_disable(irq)
    313 	int irq;
    314 {
    315 	int byte = (irq / 8), bit = (irq % 8);
    316 
    317 #if 1
    318 	printf("eb66_intr_disable: disabling %d (%d:%d)\n", irq, byte, bit);
    319 #endif
    320 	eb66_intr_mask[byte] |= (1 << bit);
    321 
    322 	bus_space_write_1(eb66_intrgate_iot, eb66_intrgate_ioh, byte,
    323 	    eb66_intr_mask[byte]);
    324 }
    325 #endif
    326