Home | History | Annotate | Line # | Download | only in pci
pci_eb64plus.c revision 1.16.14.1
      1  1.16.14.1       jym /* $NetBSD: pci_eb64plus.c,v 1.16.14.1 2009/05/13 17:16:06 jym 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.1   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9        1.1   thorpej  * NASA Ames Research Center.
     10        1.1   thorpej  *
     11        1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     12        1.1   thorpej  * modification, are permitted provided that the following conditions
     13        1.1   thorpej  * are met:
     14        1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     15        1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     16        1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17        1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18        1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     19        1.1   thorpej  *
     20        1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21        1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22        1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23        1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24        1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25        1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26        1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27        1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28        1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29        1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30        1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     31        1.1   thorpej  */
     32        1.1   thorpej 
     33        1.1   thorpej /*
     34        1.1   thorpej  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     35        1.1   thorpej  * All rights reserved.
     36        1.1   thorpej  *
     37        1.1   thorpej  * Author: Chris G. Demetriou
     38        1.1   thorpej  *
     39        1.1   thorpej  * Permission to use, copy, modify and distribute this software and
     40        1.1   thorpej  * its documentation is hereby granted, provided that both the copyright
     41        1.1   thorpej  * notice and this permission notice appear in all copies of the
     42        1.1   thorpej  * software, derivative works or modified versions, and any portions
     43        1.1   thorpej  * thereof, and that both notices appear in supporting documentation.
     44        1.1   thorpej  *
     45        1.1   thorpej  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     46        1.1   thorpej  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     47        1.1   thorpej  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     48        1.1   thorpej  *
     49        1.1   thorpej  * Carnegie Mellon requests users of this software to return to
     50        1.1   thorpej  *
     51        1.1   thorpej  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     52        1.1   thorpej  *  School of Computer Science
     53        1.1   thorpej  *  Carnegie Mellon University
     54        1.1   thorpej  *  Pittsburgh PA 15213-3890
     55        1.1   thorpej  *
     56        1.1   thorpej  * any improvements or extensions that they make and grant Carnegie the
     57        1.1   thorpej  * rights to redistribute these changes.
     58        1.1   thorpej  */
     59        1.1   thorpej 
     60        1.1   thorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     61        1.1   thorpej 
     62  1.16.14.1       jym __KERNEL_RCSID(0, "$NetBSD: pci_eb64plus.c,v 1.16.14.1 2009/05/13 17:16:06 jym Exp $");
     63        1.1   thorpej 
     64        1.1   thorpej #include <sys/types.h>
     65        1.1   thorpej #include <sys/param.h>
     66        1.1   thorpej #include <sys/time.h>
     67        1.1   thorpej #include <sys/systm.h>
     68        1.1   thorpej #include <sys/errno.h>
     69        1.1   thorpej #include <sys/malloc.h>
     70        1.1   thorpej #include <sys/device.h>
     71        1.1   thorpej #include <sys/syslog.h>
     72        1.1   thorpej 
     73        1.8       mrg #include <uvm/uvm_extern.h>
     74        1.1   thorpej 
     75        1.1   thorpej #include <machine/autoconf.h>
     76        1.1   thorpej 
     77        1.1   thorpej #include <dev/pci/pcireg.h>
     78        1.1   thorpej #include <dev/pci/pcivar.h>
     79        1.1   thorpej 
     80        1.1   thorpej #include <alpha/pci/apecsreg.h>
     81        1.1   thorpej #include <alpha/pci/apecsvar.h>
     82        1.1   thorpej 
     83        1.1   thorpej #include <alpha/pci/pci_eb64plus.h>
     84        1.1   thorpej 
     85        1.1   thorpej #include "sio.h"
     86        1.1   thorpej #if NSIO
     87        1.1   thorpej #include <alpha/pci/siovar.h>
     88        1.1   thorpej #endif
     89        1.1   thorpej 
     90  1.16.14.1       jym int	dec_eb64plus_intr_map(struct pci_attach_args *,
     91  1.16.14.1       jym 	    pci_intr_handle_t *);
     92  1.16.14.1       jym const char *dec_eb64plus_intr_string(void *, pci_intr_handle_t);
     93  1.16.14.1       jym const struct evcnt *dec_eb64plus_intr_evcnt(void *, pci_intr_handle_t);
     94  1.16.14.1       jym void	*dec_eb64plus_intr_establish(void *, pci_intr_handle_t,
     95  1.16.14.1       jym 	    int, int (*func)(void *), void *);
     96  1.16.14.1       jym void	dec_eb64plus_intr_disestablish(void *, void *);
     97        1.1   thorpej 
     98        1.1   thorpej #define	EB64PLUS_MAX_IRQ	32
     99        1.1   thorpej #define	PCI_STRAY_MAX		5
    100        1.1   thorpej 
    101        1.1   thorpej struct alpha_shared_intr *eb64plus_pci_intr;
    102        1.1   thorpej 
    103        1.1   thorpej bus_space_tag_t eb64plus_intrgate_iot;
    104        1.1   thorpej bus_space_handle_t eb64plus_intrgate_ioh;
    105        1.1   thorpej 
    106  1.16.14.1       jym void	eb64plus_iointr(void *arg, unsigned long vec);
    107  1.16.14.1       jym extern void	eb64plus_intr_enable(int irq);  /* pci_eb64plus_intr.S */
    108  1.16.14.1       jym extern void	eb64plus_intr_disable(int irq); /* pci_eb64plus_intr.S */
    109        1.1   thorpej 
    110        1.1   thorpej void
    111  1.16.14.1       jym pci_eb64plus_pickintr(struct apecs_config *acp)
    112        1.1   thorpej {
    113        1.1   thorpej 	bus_space_tag_t iot = &acp->ac_iot;
    114        1.1   thorpej 	pci_chipset_tag_t pc = &acp->ac_pc;
    115        1.7   thorpej 	char *cp;
    116        1.1   thorpej 	int i;
    117        1.1   thorpej 
    118        1.1   thorpej         pc->pc_intr_v = acp;
    119        1.1   thorpej         pc->pc_intr_map = dec_eb64plus_intr_map;
    120        1.1   thorpej         pc->pc_intr_string = dec_eb64plus_intr_string;
    121        1.6       cgd 	pc->pc_intr_evcnt = dec_eb64plus_intr_evcnt;
    122        1.1   thorpej         pc->pc_intr_establish = dec_eb64plus_intr_establish;
    123        1.1   thorpej         pc->pc_intr_disestablish = dec_eb64plus_intr_disestablish;
    124        1.1   thorpej 
    125        1.1   thorpej 	/* Not supported on the EB64+. */
    126        1.1   thorpej 	pc->pc_pciide_compat_intr_establish = NULL;
    127        1.1   thorpej 
    128        1.1   thorpej 	eb64plus_intrgate_iot = iot;
    129        1.1   thorpej 	if (bus_space_map(eb64plus_intrgate_iot, 0x804, 3, 0,
    130        1.1   thorpej 	    &eb64plus_intrgate_ioh) != 0)
    131        1.1   thorpej 		panic("pci_eb64plus_pickintr: couldn't map interrupt PLD");
    132        1.1   thorpej 	for (i = 0; i < EB64PLUS_MAX_IRQ; i++)
    133        1.1   thorpej 		eb64plus_intr_disable(i);
    134        1.1   thorpej 
    135        1.7   thorpej 	eb64plus_pci_intr = alpha_shared_intr_alloc(EB64PLUS_MAX_IRQ, 8);
    136        1.7   thorpej 	for (i = 0; i < EB64PLUS_MAX_IRQ; i++) {
    137        1.1   thorpej 		alpha_shared_intr_set_maxstrays(eb64plus_pci_intr, i,
    138        1.1   thorpej 			PCI_STRAY_MAX);
    139        1.7   thorpej 
    140        1.7   thorpej 		cp = alpha_shared_intr_string(eb64plus_pci_intr, i);
    141        1.7   thorpej 		sprintf(cp, "irq %d", i);
    142        1.7   thorpej 		evcnt_attach_dynamic(alpha_shared_intr_evcnt(
    143        1.7   thorpej 		    eb64plus_pci_intr, i), EVCNT_TYPE_INTR, NULL,
    144        1.7   thorpej 		    "eb64+", cp);
    145        1.7   thorpej 	}
    146        1.1   thorpej 
    147        1.1   thorpej #if NSIO
    148        1.1   thorpej 	sio_intr_setup(pc, iot);
    149        1.1   thorpej #endif
    150        1.1   thorpej }
    151        1.1   thorpej 
    152        1.1   thorpej int
    153  1.16.14.1       jym dec_eb64plus_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    154        1.1   thorpej {
    155        1.9  sommerfe 	pcitag_t bustag = pa->pa_intrtag;
    156        1.9  sommerfe 	int buspin = pa->pa_intrpin, line = pa->pa_intrline;
    157        1.9  sommerfe 	pci_chipset_tag_t pc = pa->pa_pc;
    158        1.1   thorpej 	int bus, device, function;
    159        1.1   thorpej 
    160        1.1   thorpej 	if (buspin == 0) {
    161        1.1   thorpej 		/* No IRQ used. */
    162        1.1   thorpej 		return 1;
    163        1.1   thorpej 	}
    164        1.1   thorpej 	if (buspin > 4) {
    165        1.1   thorpej 		printf("dec_eb64plus_intr_map: bad interrupt pin %d\n", buspin);
    166        1.1   thorpej 		return 1;
    167        1.1   thorpej 	}
    168        1.1   thorpej 
    169       1.11   thorpej 	pci_decompose_tag(pc, bustag, &bus, &device, &function);
    170        1.1   thorpej 
    171        1.1   thorpej 	/*
    172        1.1   thorpej 	 * The console places the interrupt mapping in the "line" value.
    173        1.1   thorpej 	 * A value of (char)-1 indicates there is no mapping.
    174        1.1   thorpej 	 */
    175        1.1   thorpej 	if (line == 0xff) {
    176        1.1   thorpej 		printf("dec_eb64plus_intr_map: no mapping for %d/%d/%d\n",
    177        1.1   thorpej 		    bus, device, function);
    178        1.1   thorpej 		return (1);
    179        1.1   thorpej 	}
    180        1.1   thorpej 
    181        1.1   thorpej 	if (line >= EB64PLUS_MAX_IRQ)
    182       1.12    provos 		panic("dec_eb64plus_intr_map: eb64+ irq too large (%d)",
    183        1.1   thorpej 		    line);
    184        1.1   thorpej 
    185        1.1   thorpej 	*ihp = line;
    186        1.1   thorpej 	return (0);
    187        1.1   thorpej }
    188        1.1   thorpej 
    189        1.1   thorpej const char *
    190  1.16.14.1       jym dec_eb64plus_intr_string(void *acv, pci_intr_handle_t ih)
    191        1.1   thorpej {
    192        1.1   thorpej         static char irqstr[15];          /* 11 + 2 + NULL + sanity */
    193        1.1   thorpej 
    194        1.1   thorpej         if (ih > EB64PLUS_MAX_IRQ)
    195       1.12    provos                 panic("dec_eb64plus_intr_string: bogus eb64+ IRQ 0x%lx", ih);
    196        1.5   thorpej         sprintf(irqstr, "eb64+ irq %ld", ih);
    197        1.1   thorpej         return (irqstr);
    198        1.6       cgd }
    199        1.6       cgd 
    200        1.6       cgd const struct evcnt *
    201  1.16.14.1       jym dec_eb64plus_intr_evcnt(void *acv, pci_intr_handle_t ih)
    202        1.6       cgd {
    203        1.6       cgd 
    204        1.7   thorpej 	if (ih > EB64PLUS_MAX_IRQ)
    205       1.12    provos 		panic("dec_eb64plus_intr_string: bogus eb64+ IRQ 0x%lx", ih);
    206        1.7   thorpej 	return (alpha_shared_intr_evcnt(eb64plus_pci_intr, ih));
    207        1.1   thorpej }
    208        1.1   thorpej 
    209        1.1   thorpej void *
    210  1.16.14.1       jym dec_eb64plus_intr_establish(void *acv, pci_intr_handle_t ih, int level, int (*func)(void *), void *arg)
    211        1.1   thorpej {
    212        1.1   thorpej 	void *cookie;
    213        1.1   thorpej 
    214        1.1   thorpej 	if (ih > EB64PLUS_MAX_IRQ)
    215       1.12    provos 		panic("dec_eb64plus_intr_establish: bogus eb64+ IRQ 0x%lx",
    216        1.5   thorpej 		    ih);
    217        1.1   thorpej 
    218        1.1   thorpej 	cookie = alpha_shared_intr_establish(eb64plus_pci_intr, ih, IST_LEVEL,
    219        1.1   thorpej 	    level, func, arg, "eb64+ irq");
    220        1.1   thorpej 
    221       1.10   thorpej 	if (cookie != NULL &&
    222       1.10   thorpej 	    alpha_shared_intr_firstactive(eb64plus_pci_intr, ih)) {
    223       1.15        ad 		scb_set(0x900 + SCB_IDXTOVEC(ih), eb64plus_iointr, NULL,
    224       1.15        ad 		    level);
    225        1.1   thorpej 		eb64plus_intr_enable(ih);
    226       1.10   thorpej 	}
    227        1.1   thorpej 	return (cookie);
    228        1.1   thorpej }
    229        1.1   thorpej 
    230        1.1   thorpej void
    231  1.16.14.1       jym dec_eb64plus_intr_disestablish(void *acv, void *cookie)
    232        1.1   thorpej {
    233        1.4   thorpej 	struct alpha_shared_intrhand *ih = cookie;
    234        1.4   thorpej 	unsigned int irq = ih->ih_num;
    235        1.4   thorpej 	int s;
    236        1.4   thorpej 
    237        1.4   thorpej 	s = splhigh();
    238        1.4   thorpej 
    239        1.4   thorpej 	alpha_shared_intr_disestablish(eb64plus_pci_intr, cookie,
    240        1.4   thorpej 	    "eb64+ irq");
    241        1.4   thorpej 	if (alpha_shared_intr_isactive(eb64plus_pci_intr, irq) == 0) {
    242        1.4   thorpej 		eb64plus_intr_disable(irq);
    243        1.4   thorpej 		alpha_shared_intr_set_dfltsharetype(eb64plus_pci_intr, irq,
    244        1.4   thorpej 		    IST_NONE);
    245       1.10   thorpej 		scb_free(0x900 + SCB_IDXTOVEC(irq));
    246        1.4   thorpej 	}
    247        1.4   thorpej 
    248        1.4   thorpej 	splx(s);
    249        1.1   thorpej }
    250        1.1   thorpej 
    251        1.1   thorpej void
    252  1.16.14.1       jym eb64plus_iointr(void *arg, unsigned long vec)
    253        1.1   thorpej {
    254        1.1   thorpej 	int irq;
    255        1.1   thorpej 
    256       1.10   thorpej 	irq = SCB_VECTOIDX(vec - 0x900);
    257       1.10   thorpej 
    258       1.10   thorpej 	if (!alpha_shared_intr_dispatch(eb64plus_pci_intr, irq)) {
    259       1.10   thorpej 		alpha_shared_intr_stray(eb64plus_pci_intr, irq,
    260       1.10   thorpej 		    "eb64+ irq");
    261       1.10   thorpej 		if (ALPHA_SHARED_INTR_DISABLE(eb64plus_pci_intr, irq))
    262       1.10   thorpej 			eb64plus_intr_disable(irq);
    263       1.13   thorpej 	} else
    264       1.13   thorpej 		alpha_shared_intr_reset_strays(eb64plus_pci_intr, irq);
    265        1.1   thorpej }
    266        1.1   thorpej 
    267        1.1   thorpej #if 0		/* THIS DOES NOT WORK!  see pci_eb64plus_intr.S. */
    268        1.1   thorpej u_int8_t eb64plus_intr_mask[3] = { 0xff, 0xff, 0xff };
    269        1.1   thorpej 
    270        1.1   thorpej void
    271  1.16.14.1       jym eb64plus_intr_enable(int irq)
    272        1.1   thorpej {
    273        1.1   thorpej 	int byte = (irq / 8), bit = (irq % 8);
    274        1.1   thorpej 
    275        1.1   thorpej #if 1
    276        1.1   thorpej 	printf("eb64plus_intr_enable: enabling %d (%d:%d)\n", irq, byte, bit);
    277        1.1   thorpej #endif
    278        1.1   thorpej 	eb64plus_intr_mask[byte] &= ~(1 << bit);
    279        1.1   thorpej 
    280        1.1   thorpej 	bus_space_write_1(eb64plus_intrgate_iot, eb64plus_intrgate_ioh, byte,
    281        1.1   thorpej 	    eb64plus_intr_mask[byte]);
    282        1.1   thorpej }
    283        1.1   thorpej 
    284        1.1   thorpej void
    285  1.16.14.1       jym eb64plus_intr_disable(int irq)
    286        1.1   thorpej {
    287        1.1   thorpej 	int byte = (irq / 8), bit = (irq % 8);
    288        1.1   thorpej 
    289        1.1   thorpej #if 1
    290        1.1   thorpej 	printf("eb64plus_intr_disable: disabling %d (%d:%d)\n", irq, byte, bit);
    291        1.1   thorpej #endif
    292        1.1   thorpej 	eb64plus_intr_mask[byte] |= (1 << bit);
    293        1.1   thorpej 
    294        1.1   thorpej 	bus_space_write_1(eb64plus_intrgate_iot, eb64plus_intrgate_ioh, byte,
    295        1.1   thorpej 	    eb64plus_intr_mask[byte]);
    296        1.1   thorpej }
    297        1.1   thorpej #endif
    298