Home | History | Annotate | Line # | Download | only in pci
pci_6600.c revision 1.24.10.1
      1  1.24.10.1     rmind /* $NetBSD: pci_6600.c,v 1.24.10.1 2014/05/18 17:44:53 rmind Exp $ */
      2        1.1      ross 
      3        1.1      ross /*-
      4        1.1      ross  * Copyright (c) 1999 by Ross Harvey.  All rights reserved.
      5        1.1      ross  *
      6        1.1      ross  * Redistribution and use in source and binary forms, with or without
      7        1.1      ross  * modification, are permitted provided that the following conditions
      8        1.1      ross  * are met:
      9        1.1      ross  * 1. Redistributions of source code must retain the above copyright
     10        1.1      ross  *    notice, this list of conditions and the following disclaimer.
     11        1.1      ross  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.1      ross  *    notice, this list of conditions and the following disclaimer in the
     13        1.1      ross  *    documentation and/or other materials provided with the distribution.
     14        1.1      ross  * 3. All advertising materials mentioning features or use of this software
     15        1.1      ross  *    must display the following acknowledgement:
     16        1.1      ross  *	This product includes software developed by Ross Harvey.
     17        1.1      ross  * 4. The name of Ross Harvey may not be used to endorse or promote products
     18        1.1      ross  *    derived from this software without specific prior written permission.
     19        1.1      ross  *
     20        1.1      ross  * THIS SOFTWARE IS PROVIDED BY ROSS HARVEY ``AS IS'' AND ANY EXPRESS
     21        1.1      ross  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22        1.1      ross  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP0SE
     23        1.1      ross  * ARE DISCLAIMED.  IN NO EVENT SHALL ROSS HARVEY BE LIABLE FOR ANY
     24        1.1      ross  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25        1.1      ross  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26        1.1      ross  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27        1.1      ross  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28        1.1      ross  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29        1.1      ross  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30        1.1      ross  * SUCH DAMAGE.
     31        1.1      ross  *
     32        1.1      ross  */
     33        1.1      ross 
     34        1.1      ross #include <sys/cdefs.h>
     35        1.1      ross 
     36  1.24.10.1     rmind __KERNEL_RCSID(0, "$NetBSD: pci_6600.c,v 1.24.10.1 2014/05/18 17:44:53 rmind Exp $");
     37        1.1      ross 
     38        1.1      ross #include <sys/param.h>
     39        1.1      ross #include <sys/systm.h>
     40        1.1      ross #include <sys/kernel.h>
     41        1.1      ross #include <sys/device.h>
     42        1.1      ross #include <sys/malloc.h>
     43        1.6       mrg 
     44        1.1      ross #include <machine/autoconf.h>
     45        1.1      ross #define _ALPHA_BUS_DMA_PRIVATE
     46       1.23    dyoung #include <sys/bus.h>
     47        1.1      ross #include <machine/rpb.h>
     48        1.1      ross #include <machine/alpha.h>
     49        1.1      ross 
     50        1.1      ross #include <dev/pci/pcireg.h>
     51        1.1      ross #include <dev/pci/pcivar.h>
     52        1.1      ross #include <dev/pci/pciidereg.h>
     53        1.1      ross #include <dev/pci/pciidevar.h>
     54        1.1      ross 
     55        1.1      ross #include <alpha/pci/tsreg.h>
     56        1.1      ross #include <alpha/pci/tsvar.h>
     57        1.1      ross #include <alpha/pci/pci_6600.h>
     58        1.1      ross 
     59        1.1      ross #define pci_6600() { Generate ctags(1) key. }
     60        1.1      ross 
     61        1.1      ross #include "sio.h"
     62        1.1      ross #if NSIO
     63        1.1      ross #include <alpha/pci/siovar.h>
     64        1.1      ross #endif
     65        1.1      ross 
     66        1.4   thorpej #define	PCI_NIRQ		64
     67        1.1      ross #define	PCI_STRAY_MAX		5
     68        1.1      ross 
     69        1.2   thorpej /*
     70        1.2   thorpej  * Some Tsunami models have a PCI device (the USB controller) with interrupts
     71        1.2   thorpej  * tied to ISA IRQ lines.  The IRQ is encoded as:
     72        1.2   thorpej  *
     73        1.2   thorpej  *	line = 0xe0 | isa_irq;
     74        1.2   thorpej  */
     75        1.2   thorpej #define	DEC_6600_LINE_IS_ISA(line)	((line) >= 0xe0 && (line) <= 0xef)
     76        1.2   thorpej #define	DEC_6600_LINE_ISA_IRQ(line)	((line) & 0x0f)
     77        1.2   thorpej 
     78       1.12  drochner static const char *irqtype = "6600 irq";
     79        1.1      ross static struct tsp_config *sioprimary;
     80        1.1      ross 
     81       1.16       dsl void dec_6600_intr_disestablish(void *, void *);
     82       1.16       dsl void *dec_6600_intr_establish(
     83       1.16       dsl     void *, pci_intr_handle_t, int, int (*func)(void *), void *);
     84  1.24.10.1     rmind const char *dec_6600_intr_string(void *, pci_intr_handle_t, char *, size_t);
     85       1.16       dsl const struct evcnt *dec_6600_intr_evcnt(void *, pci_intr_handle_t);
     86       1.21    dyoung int dec_6600_intr_map(const struct pci_attach_args *, pci_intr_handle_t *);
     87       1.22      matt void *dec_6600_pciide_compat_intr_establish(void *, device_t,
     88       1.21    dyoung     const struct pci_attach_args *, int, int (*)(void *), void *);
     89        1.1      ross 
     90        1.1      ross struct alpha_shared_intr *dec_6600_pci_intr;
     91        1.1      ross 
     92       1.16       dsl void dec_6600_iointr(void *arg, unsigned long vec);
     93       1.16       dsl extern void dec_6600_intr_enable(int irq);
     94       1.16       dsl extern void dec_6600_intr_disable(int irq);
     95        1.1      ross 
     96        1.1      ross void
     97       1.17       dsl pci_6600_pickintr(struct tsp_config *pcp)
     98        1.1      ross {
     99        1.1      ross 	bus_space_tag_t iot = &pcp->pc_iot;
    100        1.1      ross 	pci_chipset_tag_t pc = &pcp->pc_pc;
    101        1.4   thorpej 	char *cp;
    102        1.1      ross 	int i;
    103        1.1      ross 
    104       1.24      matt 	pc->pc_intr_v = pcp;
    105       1.24      matt 	pc->pc_intr_map = dec_6600_intr_map;
    106       1.24      matt 	pc->pc_intr_string = dec_6600_intr_string;
    107        1.3       cgd 	pc->pc_intr_evcnt = dec_6600_intr_evcnt;
    108       1.24      matt 	pc->pc_intr_establish = dec_6600_intr_establish;
    109       1.24      matt 	pc->pc_intr_disestablish = dec_6600_intr_disestablish;
    110        1.1      ross 	pc->pc_pciide_compat_intr_establish = NULL;
    111        1.1      ross 
    112        1.1      ross 	/*
    113        1.1      ross 	 * System-wide and Pchip-0-only logic...
    114        1.1      ross 	 */
    115        1.1      ross 	if (dec_6600_pci_intr == NULL) {
    116        1.1      ross 		sioprimary = pcp;
    117        1.1      ross 		pc->pc_pciide_compat_intr_establish =
    118        1.1      ross 		    dec_6600_pciide_compat_intr_establish;
    119  1.24.10.1     rmind #define PCI_6600_IRQ_STR	8
    120  1.24.10.1     rmind 		dec_6600_pci_intr = alpha_shared_intr_alloc(PCI_NIRQ,
    121  1.24.10.1     rmind 		    PCI_6600_IRQ_STR);
    122        1.4   thorpej 		for (i = 0; i < PCI_NIRQ; i++) {
    123        1.1      ross 			alpha_shared_intr_set_maxstrays(dec_6600_pci_intr, i,
    124        1.1      ross 			    PCI_STRAY_MAX);
    125        1.2   thorpej 			alpha_shared_intr_set_private(dec_6600_pci_intr, i,
    126        1.2   thorpej 			    sioprimary);
    127        1.4   thorpej 
    128        1.4   thorpej 			cp = alpha_shared_intr_string(dec_6600_pci_intr, i);
    129  1.24.10.1     rmind 			snprintf(cp, PCI_6600_IRQ_STR, "irq %d", i);
    130        1.4   thorpej 			evcnt_attach_dynamic(alpha_shared_intr_evcnt(
    131       1.14    mhitch 			    dec_6600_pci_intr, i), EVCNT_TYPE_INTR, NULL,
    132        1.4   thorpej 			    "dec_6600", cp);
    133        1.2   thorpej 		}
    134        1.1      ross #if NSIO
    135        1.1      ross 		sio_intr_setup(pc, iot);
    136        1.1      ross 		dec_6600_intr_enable(55);	/* irq line for sio */
    137        1.1      ross #endif
    138        1.1      ross 	}
    139        1.1      ross }
    140        1.1      ross 
    141       1.24      matt int
    142       1.21    dyoung dec_6600_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    143        1.1      ross {
    144        1.7  sommerfe 	pcitag_t bustag = pa->pa_intrtag;
    145        1.7  sommerfe 	int buspin = pa->pa_intrpin, line = pa->pa_intrline;
    146        1.7  sommerfe 	pci_chipset_tag_t pc = pa->pa_pc;
    147        1.1      ross 	int bus, device, function;
    148        1.1      ross 
    149        1.1      ross 	if (buspin == 0) {
    150        1.1      ross 		/* No IRQ used. */
    151        1.1      ross 		return 1;
    152        1.1      ross 	}
    153        1.1      ross 	if (buspin > 4) {
    154        1.1      ross 		printf("intr_map: bad interrupt pin %d\n", buspin);
    155        1.1      ross 		return 1;
    156        1.1      ross 	}
    157        1.1      ross 
    158        1.9   thorpej 	pci_decompose_tag(pc, bustag, &bus, &device, &function);
    159        1.2   thorpej 
    160        1.1      ross 	/*
    161        1.1      ross 	 * The console places the interrupt mapping in the "line" value.
    162        1.1      ross 	 * A value of (char)-1 indicates there is no mapping.
    163        1.1      ross 	 */
    164        1.2   thorpej 	if (line == 0xff) {
    165        1.2   thorpej 		printf("dec_6600_intr_map: no mapping for %d/%d/%d\n",
    166        1.2   thorpej 		    bus, device, function);
    167        1.1      ross 		return (1);
    168        1.1      ross 	}
    169        1.1      ross 
    170        1.2   thorpej #if NSIO == 0
    171        1.2   thorpej 	if (DEC_6600_LINE_IS_ISA(line)) {
    172        1.2   thorpej 		printf("dec_6600_intr_map: ISA IRQ %d for %d/%d/%d\n",
    173        1.2   thorpej 		    DEC_6600_LINE_ISA_IRQ(line), bus, device, function);
    174        1.2   thorpej 		return (1);
    175        1.2   thorpej 	}
    176        1.2   thorpej #endif
    177        1.2   thorpej 
    178        1.4   thorpej 	if (DEC_6600_LINE_IS_ISA(line) == 0 && line >= PCI_NIRQ)
    179       1.10    provos 		panic("dec_6600_intr_map: dec 6600 irq too large (%d)",
    180        1.2   thorpej 		    line);
    181        1.1      ross 
    182        1.1      ross 	*ihp = line;
    183        1.1      ross 	return (0);
    184        1.1      ross }
    185        1.1      ross 
    186        1.1      ross const char *
    187  1.24.10.1     rmind dec_6600_intr_string(void *acv, pci_intr_handle_t ih, char *buf, size_t len)
    188        1.1      ross {
    189        1.1      ross 
    190        1.2   thorpej 	static const char irqfmt[] = "dec 6600 irq %ld";
    191        1.1      ross 
    192        1.2   thorpej #if NSIO
    193        1.2   thorpej 	if (DEC_6600_LINE_IS_ISA(ih))
    194        1.2   thorpej 		return (sio_intr_string(NULL /*XXX*/,
    195  1.24.10.1     rmind 		    DEC_6600_LINE_ISA_IRQ(ih), buf, len));
    196        1.2   thorpej #endif
    197        1.2   thorpej 
    198  1.24.10.1     rmind 	snprintf(buf, len, irqfmt, ih);
    199  1.24.10.1     rmind 	return buf;
    200        1.3       cgd }
    201        1.3       cgd 
    202        1.3       cgd const struct evcnt *
    203       1.17       dsl dec_6600_intr_evcnt(void *acv, pci_intr_handle_t ih)
    204        1.3       cgd {
    205        1.3       cgd 
    206        1.3       cgd #if NSIO
    207        1.3       cgd 	if (DEC_6600_LINE_IS_ISA(ih))
    208        1.3       cgd 		return (sio_intr_evcnt(NULL /*XXX*/,
    209        1.3       cgd 		    DEC_6600_LINE_ISA_IRQ(ih)));
    210        1.3       cgd #endif
    211        1.3       cgd 
    212        1.4   thorpej 	return (alpha_shared_intr_evcnt(dec_6600_pci_intr, ih));
    213        1.1      ross }
    214        1.1      ross 
    215        1.1      ross void *
    216       1.19       dsl dec_6600_intr_establish(void *acv, pci_intr_handle_t ih, int level, int (*func)(void *), void *arg)
    217        1.1      ross {
    218        1.1      ross 	void *cookie;
    219        1.1      ross 
    220        1.2   thorpej #if NSIO
    221        1.2   thorpej 	if (DEC_6600_LINE_IS_ISA(ih))
    222        1.2   thorpej 		return (sio_intr_establish(NULL /*XXX*/,
    223        1.2   thorpej 		    DEC_6600_LINE_ISA_IRQ(ih), IST_LEVEL, level, func, arg));
    224        1.2   thorpej #endif
    225        1.2   thorpej 
    226        1.4   thorpej 	if (ih >= PCI_NIRQ)
    227       1.10    provos 		panic("dec_6600_intr_establish: bogus dec 6600 IRQ 0x%lx",
    228        1.2   thorpej 		    ih);
    229        1.2   thorpej 
    230        1.1      ross 	cookie = alpha_shared_intr_establish(dec_6600_pci_intr, ih, IST_LEVEL,
    231        1.1      ross 	    level, func, arg, irqtype);
    232        1.1      ross 
    233        1.8   thorpej 	if (cookie != NULL &&
    234        1.8   thorpej 	    alpha_shared_intr_firstactive(dec_6600_pci_intr, ih)) {
    235       1.15        ad 		scb_set(0x900 + SCB_IDXTOVEC(ih), dec_6600_iointr, NULL,
    236       1.15        ad 		    level);
    237        1.1      ross 		dec_6600_intr_enable(ih);
    238        1.8   thorpej 	}
    239        1.1      ross 	return (cookie);
    240        1.1      ross }
    241        1.1      ross 
    242        1.1      ross void
    243       1.18       dsl dec_6600_intr_disestablish(void *acv, void *cookie)
    244        1.1      ross {
    245        1.1      ross 	struct alpha_shared_intrhand *ih = cookie;
    246        1.1      ross 	unsigned int irq = ih->ih_num;
    247        1.1      ross 	int s;
    248        1.2   thorpej 
    249        1.2   thorpej #if NSIO
    250        1.2   thorpej 	/*
    251        1.2   thorpej 	 * We have to determine if this is an ISA IRQ or not!  We do this
    252        1.2   thorpej 	 * by checking to see if the intrhand points back to an intrhead
    253        1.2   thorpej 	 * that points to the sioprimary TSP.  If not, it's an ISA IRQ.
    254        1.2   thorpej 	 * Pretty disgusting, eh?
    255        1.2   thorpej 	 */
    256        1.2   thorpej 	if (ih->ih_intrhead->intr_private != sioprimary) {
    257        1.2   thorpej 		sio_intr_disestablish(NULL /*XXX*/, cookie);
    258        1.2   thorpej 		return;
    259        1.2   thorpej 	}
    260        1.2   thorpej #endif
    261       1.24      matt 
    262        1.1      ross 	s = splhigh();
    263        1.1      ross 
    264        1.1      ross 	alpha_shared_intr_disestablish(dec_6600_pci_intr, cookie, irqtype);
    265        1.1      ross 	if (alpha_shared_intr_isactive(dec_6600_pci_intr, irq) == 0) {
    266        1.1      ross 		dec_6600_intr_disable(irq);
    267        1.1      ross 		alpha_shared_intr_set_dfltsharetype(dec_6600_pci_intr, irq,
    268        1.1      ross 		    IST_NONE);
    269        1.8   thorpej 		scb_free(0x900 + SCB_IDXTOVEC(irq));
    270        1.1      ross 	}
    271       1.24      matt 
    272        1.1      ross 	splx(s);
    273        1.1      ross }
    274        1.1      ross 
    275        1.1      ross void
    276       1.17       dsl dec_6600_iointr(void *arg, unsigned long vec)
    277        1.1      ross {
    278       1.24      matt 	int irq;
    279        1.1      ross 
    280        1.8   thorpej 	irq = SCB_VECTOIDX(vec - 0x900);
    281        1.1      ross 
    282        1.8   thorpej 	if (irq >= PCI_NIRQ)
    283        1.8   thorpej 		panic("iointr: irq %d is too high", irq);
    284        1.1      ross 
    285        1.8   thorpej 	if (!alpha_shared_intr_dispatch(dec_6600_pci_intr, irq)) {
    286        1.8   thorpej 		alpha_shared_intr_stray(dec_6600_pci_intr, irq,
    287        1.8   thorpej 		    irqtype);
    288        1.8   thorpej 		if (ALPHA_SHARED_INTR_DISABLE(dec_6600_pci_intr, irq))
    289        1.8   thorpej 			dec_6600_intr_disable(irq);
    290       1.11   thorpej 	} else
    291       1.11   thorpej 		alpha_shared_intr_reset_strays(dec_6600_pci_intr, irq);
    292        1.1      ross }
    293        1.1      ross 
    294        1.1      ross void
    295       1.17       dsl dec_6600_intr_enable(int irq)
    296        1.1      ross {
    297        1.1      ross 	alpha_mb();
    298        1.1      ross 	STQP(TS_C_DIM0) |= 1UL << irq;
    299        1.1      ross 	alpha_mb();
    300        1.1      ross }
    301        1.1      ross 
    302        1.1      ross void
    303       1.17       dsl dec_6600_intr_disable(int irq)
    304        1.1      ross {
    305        1.1      ross 	alpha_mb();
    306        1.1      ross 	STQP(TS_C_DIM0) &= ~(1UL << irq);
    307        1.1      ross 	alpha_mb();
    308        1.1      ross }
    309        1.1      ross 
    310        1.1      ross void *
    311       1.22      matt dec_6600_pciide_compat_intr_establish(void *v, device_t dev,
    312       1.21    dyoung     const struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
    313        1.1      ross {
    314        1.1      ross 	pci_chipset_tag_t pc = pa->pa_pc;
    315        1.1      ross 	void *cookie = NULL;
    316        1.1      ross 	int bus, irq;
    317  1.24.10.1     rmind 	char buf[64];
    318        1.1      ross 
    319        1.9   thorpej 	pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
    320        1.1      ross 
    321        1.2   thorpej 	/*
    322        1.2   thorpej 	 * If this isn't PCI bus #0 on the TSP that holds the PCI-ISA
    323        1.2   thorpej 	 * bridge, all bets are off.
    324        1.2   thorpej 	 */
    325        1.1      ross 	if (bus != 0 || pc->pc_intr_v != sioprimary)
    326        1.2   thorpej 		return (NULL);
    327        1.1      ross 
    328        1.1      ross 	irq = PCIIDE_COMPAT_IRQ(chan);
    329        1.1      ross #if NSIO
    330        1.1      ross 	cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO,
    331        1.1      ross 	    func, arg);
    332        1.5   thorpej 	if (cookie == NULL)
    333        1.5   thorpej 		return (NULL);
    334       1.22      matt 	aprint_normal_dev(dev, "%s channel interrupting at %s\n",
    335  1.24.10.1     rmind 	    PCIIDE_CHANNEL_NAME(chan), sio_intr_string(NULL /*XXX*/, irq,
    336  1.24.10.1     rmind 	    buf, sizeof(buf)));
    337        1.1      ross #endif
    338        1.1      ross 	return (cookie);
    339        1.1      ross }
    340