Home | History | Annotate | Line # | Download | only in pci
pci_kn8ae.c revision 1.19
      1  1.19   thorpej /* $NetBSD: pci_kn8ae.c,v 1.19 2001/07/27 00:25:20 thorpej Exp $ */
      2   1.1       cgd 
      3   1.1       cgd /*
      4   1.2       cgd  * Copyright (c) 1997 by Matthew Jacob
      5   1.1       cgd  * NASA AMES Research Center.
      6   1.1       cgd  * All rights reserved.
      7   1.1       cgd  *
      8   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      9   1.1       cgd  * modification, are permitted provided that the following conditions
     10   1.1       cgd  * are met:
     11   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     12   1.1       cgd  *    notice immediately at the beginning of the file, without modification,
     13   1.1       cgd  *    this list of conditions, and the following disclaimer.
     14   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     16   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     17   1.1       cgd  * 3. The name of the author may not be used to endorse or promote products
     18   1.1       cgd  *    derived from this software without specific prior written permission.
     19   1.1       cgd  *
     20   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     21   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23   1.1       cgd  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     24   1.1       cgd  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30   1.1       cgd  * SUCH DAMAGE.
     31   1.1       cgd  */
     32   1.3       cgd 
     33   1.4       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     34   1.4       cgd 
     35  1.19   thorpej __KERNEL_RCSID(0, "$NetBSD: pci_kn8ae.c,v 1.19 2001/07/27 00:25:20 thorpej Exp $");
     36   1.1       cgd 
     37   1.1       cgd #include <sys/types.h>
     38   1.1       cgd #include <sys/param.h>
     39   1.1       cgd #include <sys/time.h>
     40   1.1       cgd #include <sys/systm.h>
     41   1.1       cgd #include <sys/errno.h>
     42   1.1       cgd #include <sys/malloc.h>
     43   1.1       cgd #include <sys/device.h>
     44   1.1       cgd #include <sys/syslog.h>
     45   1.1       cgd 
     46  1.17       mrg #include <uvm/uvm_extern.h>
     47   1.1       cgd 
     48   1.1       cgd #include <machine/autoconf.h>
     49   1.1       cgd 
     50   1.1       cgd #include <dev/pci/pcireg.h>
     51   1.1       cgd #include <dev/pci/pcivar.h>
     52   1.1       cgd 
     53   1.1       cgd #include <alpha/pci/dwlpxreg.h>
     54   1.1       cgd #include <alpha/pci/dwlpxvar.h>
     55   1.1       cgd #include <alpha/pci/pci_kn8ae.h>
     56   1.1       cgd 
     57  1.18  sommerfe int	dec_kn8ae_intr_map __P((struct pci_attach_args *,
     58   1.1       cgd 	    pci_intr_handle_t *));
     59   1.1       cgd const char *dec_kn8ae_intr_string __P((void *, pci_intr_handle_t));
     60  1.15       cgd const struct evcnt *dec_kn8ae_intr_evcnt __P((void *, pci_intr_handle_t));
     61   1.1       cgd void	*dec_kn8ae_intr_establish __P((void *, pci_intr_handle_t,
     62   1.1       cgd 	    int, int (*func)(void *), void *));
     63   1.1       cgd void	dec_kn8ae_intr_disestablish __P((void *, void *));
     64   1.1       cgd 
     65   1.8    mjacob static u_int32_t imaskcache[DWLPX_NIONODE][DWLPX_NHOSE][NHPC];
     66   1.1       cgd 
     67  1.19   thorpej void	kn8ae_spurious __P((void *, u_long));
     68  1.19   thorpej void	kn8ae_enadis_intr __P((struct dwlpx_config *, pci_intr_handle_t, int));
     69   1.1       cgd 
     70   1.1       cgd void
     71   1.1       cgd pci_kn8ae_pickintr(ccp, first)
     72   1.1       cgd 	struct dwlpx_config *ccp;
     73   1.1       cgd 	int first;
     74   1.1       cgd {
     75   1.1       cgd 	int io, hose, dev;
     76   1.1       cgd 	pci_chipset_tag_t pc = &ccp->cc_pc;
     77   1.1       cgd 
     78   1.1       cgd         pc->pc_intr_v = ccp;
     79   1.1       cgd         pc->pc_intr_map = dec_kn8ae_intr_map;
     80   1.1       cgd         pc->pc_intr_string = dec_kn8ae_intr_string;
     81  1.15       cgd 	pc->pc_intr_evcnt = dec_kn8ae_intr_evcnt;
     82   1.1       cgd         pc->pc_intr_establish = dec_kn8ae_intr_establish;
     83   1.1       cgd         pc->pc_intr_disestablish = dec_kn8ae_intr_disestablish;
     84  1.11   thorpej 
     85  1.12    mjacob 	/* Not supported on KN8AE. */
     86  1.11   thorpej 	pc->pc_pciide_compat_intr_establish = NULL;
     87   1.1       cgd 
     88   1.1       cgd 	if (!first) {
     89   1.1       cgd 		return;
     90   1.1       cgd 	}
     91   1.1       cgd 
     92   1.8    mjacob 	for (io = 0; io < DWLPX_NIONODE; io++) {
     93   1.8    mjacob 		for (hose = 0; hose < DWLPX_NHOSE; hose++) {
     94   1.1       cgd 			for (dev = 0; dev < NHPC; dev++) {
     95   1.1       cgd 				imaskcache[io][hose][dev] = DWLPX_IMASK_DFLT;
     96   1.1       cgd 			}
     97   1.1       cgd 		}
     98   1.1       cgd 	}
     99   1.1       cgd }
    100   1.1       cgd 
    101  1.19   thorpej #define	IH_MAKE(vec, dev, pin)						\
    102  1.19   thorpej 	((vec) | ((dev) << 16) | ((pin) << 24))
    103  1.19   thorpej 
    104  1.19   thorpej #define	IH_VEC(ih)	((ih) & 0xffff)
    105  1.19   thorpej #define	IH_DEV(ih)	(((ih) >> 16) & 0xff)
    106  1.19   thorpej #define	IH_PIN(ih)	(((ih) >> 24) & 0xff)
    107  1.19   thorpej 
    108   1.1       cgd int
    109  1.18  sommerfe dec_kn8ae_intr_map(pa, ihp)
    110  1.18  sommerfe 	struct pci_attach_args *pa;
    111   1.1       cgd         pci_intr_handle_t *ihp;
    112   1.1       cgd {
    113  1.18  sommerfe 	pcitag_t bustag = pa->pa_intrtag;
    114  1.18  sommerfe 	int buspin = pa->pa_intrpin;
    115  1.18  sommerfe 	pci_chipset_tag_t pc = pa->pa_pc;
    116  1.19   thorpej 	int device;
    117  1.19   thorpej 	u_long vec;
    118   1.1       cgd 
    119  1.13   thorpej 	if (buspin == 0) {
    120  1.13   thorpej 		/* No IRQ used. */
    121  1.13   thorpej 		return 1;
    122  1.13   thorpej 	}
    123  1.13   thorpej 	if (buspin > 4) {
    124  1.13   thorpej 		printf("dec_kn8ae_intr_map: bad interrupt pin %d\n", buspin);
    125  1.13   thorpej 		return 1;
    126  1.13   thorpej 	}
    127   1.6       cgd 	alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    128   1.1       cgd 
    129  1.19   thorpej 	vec = scb_alloc(kn8ae_spurious, NULL);
    130  1.19   thorpej 	if (vec == SCB_ALLOC_FAILED) {
    131  1.19   thorpej 		printf("dec_kn8ae_intr_map: no vector available for "
    132  1.19   thorpej 		    "device %d pin %d\n", device, buspin);
    133  1.19   thorpej 		return 1;
    134  1.19   thorpej 	}
    135  1.19   thorpej 
    136  1.19   thorpej 	*ihp = IH_MAKE(vec, device, buspin);
    137  1.19   thorpej 
    138   1.1       cgd 	return (0);
    139   1.1       cgd }
    140   1.1       cgd 
    141   1.1       cgd const char *
    142   1.1       cgd dec_kn8ae_intr_string(ccv, ih)
    143   1.1       cgd 	void *ccv;
    144   1.1       cgd 	pci_intr_handle_t ih;
    145   1.1       cgd {
    146   1.1       cgd 	static char irqstr[64];
    147  1.19   thorpej 
    148  1.19   thorpej 	sprintf(irqstr, "vector 0x%lx", IH_VEC(ih));
    149  1.19   thorpej 
    150   1.1       cgd         return (irqstr);
    151  1.15       cgd }
    152  1.15       cgd 
    153  1.15       cgd const struct evcnt *
    154  1.15       cgd dec_kn8ae_intr_evcnt(ccv, ih)
    155  1.15       cgd 	void *ccv;
    156  1.15       cgd 	pci_intr_handle_t ih;
    157  1.15       cgd {
    158  1.15       cgd 
    159  1.15       cgd 	/* XXX for now, no evcnt parent reported */
    160  1.15       cgd 	return (NULL);
    161   1.1       cgd }
    162   1.1       cgd 
    163   1.1       cgd void *
    164   1.1       cgd dec_kn8ae_intr_establish(ccv, ih, level, func, arg)
    165   1.1       cgd         void *ccv;
    166   1.1       cgd         pci_intr_handle_t ih;
    167   1.1       cgd         int level;
    168   1.1       cgd         int (*func) __P((void *));
    169   1.1       cgd 	void *arg;
    170   1.1       cgd {
    171   1.1       cgd 	struct dwlpx_config *ccp = ccv;
    172  1.19   thorpej 	void *cookie;
    173  1.19   thorpej 	struct scbvec *scb;
    174  1.19   thorpej 	u_long vec;
    175  1.19   thorpej 	int pin, device, hpc;
    176  1.19   thorpej 
    177  1.19   thorpej 	device = IH_DEV(ih);
    178  1.19   thorpej 	pin = IH_PIN(ih);
    179  1.19   thorpej 	vec = IH_VEC(ih);
    180  1.19   thorpej 
    181  1.19   thorpej 	scb = &scb_iovectab[SCB_VECTOIDX(vec) - SCB_IOVECBASE];
    182  1.19   thorpej 
    183  1.19   thorpej 	if (scb->scb_func != kn8ae_spurious) {
    184  1.19   thorpej 		printf("dec_kn8ae_intr_establish: vector 0x%lx not mapped\n",
    185  1.19   thorpej 		    vec);
    186  1.19   thorpej 		return (NULL);
    187  1.19   thorpej 	}
    188   1.1       cgd 
    189  1.19   thorpej 	/*
    190  1.19   thorpej 	 * NOTE: The PCIA hardware doesn't support interrupt sharing,
    191  1.19   thorpej 	 * so we don't have to worry about it (in theory, at least).
    192  1.19   thorpej 	 */
    193  1.19   thorpej 
    194  1.19   thorpej 	scb->scb_arg = arg;
    195  1.19   thorpej 	alpha_mb();
    196  1.19   thorpej 	scb->scb_func = (void (*)(void *, u_long))func;
    197  1.19   thorpej 	alpha_mb();
    198  1.19   thorpej 
    199  1.19   thorpej 	if (device < 4) {
    200  1.19   thorpej 		hpc = 0;
    201  1.19   thorpej 	} else if (device < 8) {
    202  1.19   thorpej 		device -= 4;
    203  1.19   thorpej 		hpc = 1;
    204  1.19   thorpej 	} else {
    205  1.19   thorpej 		device -= 8;
    206  1.19   thorpej 		hpc = 2;
    207   1.1       cgd 	}
    208  1.19   thorpej 	REGVAL(PCIA_DEVVEC(hpc, device, pin) + ccp->cc_sysbase) = vec;
    209  1.19   thorpej 
    210  1.19   thorpej 	kn8ae_enadis_intr(ccp, ih, 1);
    211   1.1       cgd 
    212  1.19   thorpej 	cookie = (void *) ih;
    213   1.1       cgd 
    214   1.1       cgd 	return (cookie);
    215   1.1       cgd }
    216   1.1       cgd 
    217   1.1       cgd void
    218   1.1       cgd dec_kn8ae_intr_disestablish(ccv, cookie)
    219   1.1       cgd         void *ccv, *cookie;
    220   1.1       cgd {
    221  1.19   thorpej 	struct dwlpx_config *ccp = ccv;
    222  1.19   thorpej 	pci_intr_handle_t ih = (u_long) cookie;
    223  1.19   thorpej 	struct scbvec *scb;
    224  1.19   thorpej 	u_long vec;
    225  1.19   thorpej 
    226  1.19   thorpej 	vec = IH_VEC(ih);
    227  1.19   thorpej 
    228  1.19   thorpej 	scb = &scb_iovectab[SCB_VECTOIDX(vec) - SCB_IOVECBASE];
    229   1.1       cgd 
    230  1.19   thorpej 	kn8ae_enadis_intr(ccp, ih, 0);
    231   1.1       cgd 
    232  1.19   thorpej 	scb_free(vec);
    233   1.9    mjacob }
    234   1.9    mjacob 
    235   1.1       cgd void
    236  1.19   thorpej kn8ae_spurious(void *arg, u_long vec)
    237   1.1       cgd {
    238  1.19   thorpej 
    239  1.19   thorpej 	printf("Spurious interrupt on temporary interrupt vector 0x%lx\n",
    240  1.19   thorpej 	    vec);
    241   1.1       cgd }
    242   1.1       cgd 
    243   1.1       cgd void
    244  1.19   thorpej kn8ae_enadis_intr(ccp, irq, onoff)
    245  1.19   thorpej 	struct dwlpx_config *ccp;
    246   1.1       cgd 	pci_intr_handle_t irq;
    247   1.1       cgd 	int onoff;
    248   1.1       cgd {
    249  1.19   thorpej 	struct dwlpx_softc *sc = ccp->cc_sc;
    250   1.1       cgd 	unsigned long paddr;
    251   1.1       cgd 	u_int32_t val;
    252   1.1       cgd 	int ionode, hose, device, hpc, busp, s;
    253   1.1       cgd 
    254  1.19   thorpej 	ionode = sc->dwlpx_node - 4;
    255  1.19   thorpej 	hose = sc->dwlpx_hosenum;
    256  1.19   thorpej 
    257  1.19   thorpej 	device = IH_DEV(irq);
    258  1.19   thorpej 	busp = (1 << (IH_PIN(irq) - 1));
    259  1.19   thorpej 
    260   1.1       cgd 	paddr = (1LL << 39);
    261   1.1       cgd 	paddr |= (unsigned long) ionode << 36;
    262   1.1       cgd 	paddr |= (unsigned long) hose << 34;
    263  1.19   thorpej 
    264   1.1       cgd 	if (device < 4) {
    265   1.1       cgd 		hpc = 0;
    266   1.1       cgd 	} else if (device < 8) {
    267   1.1       cgd 		hpc = 1;
    268   1.1       cgd 		device -= 4;
    269   1.1       cgd 	} else {
    270   1.1       cgd 		hpc = 2;
    271   1.1       cgd 		device -= 8;
    272   1.1       cgd 	}
    273   1.1       cgd 	busp <<= (device << 2);
    274   1.1       cgd 	val = imaskcache[ionode][hose][hpc];
    275   1.1       cgd 	if (onoff)
    276   1.1       cgd 		val |= busp;
    277   1.1       cgd 	else
    278   1.1       cgd 		val &= ~busp;
    279   1.1       cgd 	imaskcache[ionode][hose][hpc] = val;
    280   1.1       cgd #if	0
    281   1.1       cgd 	printf("kn8ae_%s_intr: irq %lx imsk 0x%x hpc %d TLSB node %d hose %d\n",
    282   1.1       cgd 	    onoff? "enable" : "disable", irq, val, hpc, ionode + 4, hose);
    283   1.1       cgd #endif
    284   1.1       cgd 	s = splhigh();
    285   1.1       cgd 	REGVAL(PCIA_IMASK(hpc) + paddr) = val;
    286   1.1       cgd 	alpha_mb();
    287   1.1       cgd 	(void) splx(s);
    288   1.1       cgd }
    289