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