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