Home | History | Annotate | Line # | Download | only in pci
pci_kn20aa.c revision 1.56
      1  1.56   thorpej /* $NetBSD: pci_kn20aa.c,v 1.56 2021/06/19 16:59:07 thorpej Exp $ */
      2   1.1       cgd 
      3   1.1       cgd /*
      4   1.5       cgd  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5   1.1       cgd  * All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Author: Chris G. Demetriou
      8  1.53      matt  *
      9   1.1       cgd  * Permission to use, copy, modify and distribute this software and
     10   1.1       cgd  * its documentation is hereby granted, provided that both the copyright
     11   1.1       cgd  * notice and this permission notice appear in all copies of the
     12   1.1       cgd  * software, derivative works or modified versions, and any portions
     13   1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     14  1.53      matt  *
     15  1.53      matt  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  1.53      matt  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17   1.1       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  1.53      matt  *
     19   1.1       cgd  * Carnegie Mellon requests users of this software to return to
     20   1.1       cgd  *
     21   1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22   1.1       cgd  *  School of Computer Science
     23   1.1       cgd  *  Carnegie Mellon University
     24   1.1       cgd  *  Pittsburgh PA 15213-3890
     25   1.1       cgd  *
     26   1.1       cgd  * any improvements or extensions that they make and grant Carnegie the
     27   1.1       cgd  * rights to redistribute these changes.
     28   1.1       cgd  */
     29  1.22       cgd 
     30  1.23       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31  1.23       cgd 
     32  1.56   thorpej __KERNEL_RCSID(0, "$NetBSD: pci_kn20aa.c,v 1.56 2021/06/19 16:59:07 thorpej Exp $");
     33   1.1       cgd 
     34   1.1       cgd #include <sys/types.h>
     35   1.1       cgd #include <sys/param.h>
     36   1.1       cgd #include <sys/time.h>
     37   1.1       cgd #include <sys/systm.h>
     38   1.1       cgd #include <sys/errno.h>
     39   1.1       cgd #include <sys/malloc.h>
     40   1.1       cgd #include <sys/device.h>
     41   1.1       cgd #include <sys/syslog.h>
     42   1.1       cgd 
     43   1.7       cgd #include <machine/autoconf.h>
     44  1.56   thorpej #include <machine/rpb.h>
     45   1.7       cgd 
     46   1.1       cgd #include <dev/pci/pcireg.h>
     47   1.1       cgd #include <dev/pci/pcivar.h>
     48   1.1       cgd 
     49   1.1       cgd #include <alpha/pci/ciareg.h>
     50   1.1       cgd #include <alpha/pci/ciavar.h>
     51   1.1       cgd 
     52   1.1       cgd #include "sio.h"
     53  1.37   thorpej #if NSIO > 0 || NPCEB > 0
     54   1.1       cgd #include <alpha/pci/siovar.h>
     55   1.1       cgd #endif
     56   1.1       cgd 
     57  1.55   thorpej static int	dec_kn20aa_intr_map(const struct pci_attach_args *,
     58  1.55   thorpej 		    pci_intr_handle_t *);
     59   1.1       cgd 
     60   1.1       cgd #define	KN20AA_PCEB_IRQ	31
     61   1.1       cgd #define	KN20AA_MAX_IRQ	32
     62   1.1       cgd #define	PCI_STRAY_MAX	5
     63   1.1       cgd 
     64  1.55   thorpej static void	kn20aa_enable_intr(pci_chipset_tag_t pc, int irq);
     65  1.55   thorpej static void	kn20aa_disable_intr(pci_chipset_tag_t pc, int irq);
     66   1.1       cgd 
     67  1.56   thorpej static void
     68  1.56   thorpej pci_kn20aa_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
     69  1.56   thorpej     pci_chipset_tag_t pc)
     70   1.1       cgd {
     71   1.1       cgd 	int i;
     72  1.39   thorpej 	char *cp;
     73   1.1       cgd 
     74  1.56   thorpej 	pc->pc_intr_v = core;
     75  1.53      matt 	pc->pc_intr_map = dec_kn20aa_intr_map;
     76  1.55   thorpej 	pc->pc_intr_string = alpha_pci_generic_intr_string;
     77  1.55   thorpej 	pc->pc_intr_evcnt = alpha_pci_generic_intr_evcnt;
     78  1.55   thorpej 	pc->pc_intr_establish = alpha_pci_generic_intr_establish;
     79  1.55   thorpej 	pc->pc_intr_disestablish = alpha_pci_generic_intr_disestablish;
     80  1.29   thorpej 
     81  1.30    mjacob 	/* Not supported on KN20AA. */
     82  1.29   thorpej 	pc->pc_pciide_compat_intr_establish = NULL;
     83   1.1       cgd 
     84  1.54  christos #define PCI_KN20AA_IRQ_STR	8
     85  1.55   thorpej 	pc->pc_shared_intrs = alpha_shared_intr_alloc(KN20AA_MAX_IRQ,
     86  1.54  christos 	    PCI_KN20AA_IRQ_STR);
     87  1.55   thorpej 	pc->pc_intr_desc = "kn20aa irq";
     88  1.55   thorpej 	pc->pc_vecbase = 0x900;
     89  1.55   thorpej 	pc->pc_nirq = KN20AA_MAX_IRQ;
     90  1.55   thorpej 
     91  1.55   thorpej 	pc->pc_intr_enable = kn20aa_enable_intr;
     92  1.55   thorpej 	pc->pc_intr_disable = kn20aa_disable_intr;
     93  1.55   thorpej 
     94  1.39   thorpej 	for (i = 0; i < KN20AA_MAX_IRQ; i++) {
     95  1.55   thorpej 		alpha_shared_intr_set_maxstrays(pc->pc_shared_intrs, i,
     96  1.21       cgd 		    PCI_STRAY_MAX);
     97  1.21       cgd 
     98  1.55   thorpej 		cp = alpha_shared_intr_string(pc->pc_shared_intrs, i);
     99  1.54  christos 		snprintf(cp, PCI_KN20AA_IRQ_STR, "irq %d", i);
    100  1.39   thorpej 		evcnt_attach_dynamic(alpha_shared_intr_evcnt(
    101  1.55   thorpej 		    pc->pc_shared_intrs, i), EVCNT_TYPE_INTR, NULL,
    102  1.39   thorpej 		    "kn20aa", cp);
    103  1.39   thorpej 	}
    104  1.39   thorpej 
    105  1.37   thorpej #if NSIO > 0 || NPCEB > 0
    106  1.27   thorpej 	sio_intr_setup(pc, iot);
    107  1.55   thorpej 	kn20aa_enable_intr(pc, KN20AA_PCEB_IRQ);
    108   1.1       cgd #endif
    109   1.1       cgd }
    110  1.56   thorpej ALPHA_PCI_INTR_INIT(ST_DEC_KN20AA, pci_kn20aa_pickintr)
    111   1.1       cgd 
    112  1.55   thorpej static int
    113  1.52    dyoung dec_kn20aa_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    114   1.1       cgd {
    115  1.41  sommerfe 	pcitag_t bustag = pa->pa_intrtag;
    116  1.41  sommerfe 	int buspin = pa->pa_intrpin;
    117  1.41  sommerfe 	pci_chipset_tag_t pc = pa->pa_pc;
    118   1.1       cgd 	int device;
    119   1.9       cgd 	int kn20aa_irq;
    120   1.1       cgd 
    121  1.31   thorpej 	if (buspin == 0) {
    122  1.31   thorpej 		/* No IRQ used. */
    123  1.31   thorpej 		return 1;
    124  1.31   thorpej 	}
    125  1.55   thorpej 	if (buspin < 0 || buspin > 4) {
    126  1.31   thorpej 		printf("dec_kn20aa_intr_map: bad interrupt pin %d\n", buspin);
    127  1.31   thorpej 		return 1;
    128  1.31   thorpej 	}
    129   1.1       cgd 
    130   1.1       cgd 	/*
    131   1.1       cgd 	 * Slot->interrupt translation.  Appears to work, though it
    132   1.1       cgd 	 * may not hold up forever.
    133   1.1       cgd 	 *
    134   1.1       cgd 	 * The DEC engineers who did this hardware obviously engaged
    135   1.1       cgd 	 * in random drug testing.
    136   1.1       cgd 	 */
    137  1.43   thorpej 	pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    138   1.3       cgd 	switch (device) {
    139   1.1       cgd 	case 11:
    140   1.1       cgd 	case 12:
    141   1.9       cgd 		kn20aa_irq = ((device - 11) + 0) * 4;
    142   1.1       cgd 		break;
    143   1.1       cgd 
    144   1.1       cgd 	case 7:
    145   1.9       cgd 		kn20aa_irq = 8;
    146   1.1       cgd 		break;
    147   1.1       cgd 
    148  1.10       cgd 	case 9:
    149  1.10       cgd 		kn20aa_irq = 12;
    150  1.14       cgd 		break;
    151  1.14       cgd 
    152  1.15       cgd 	case 6:					/* 21040 on AlphaStation 500 */
    153  1.14       cgd 		kn20aa_irq = 13;
    154  1.10       cgd 		break;
    155  1.10       cgd 
    156   1.1       cgd 	case 8:
    157   1.9       cgd 		kn20aa_irq = 16;
    158   1.1       cgd 		break;
    159   1.1       cgd 
    160   1.1       cgd 	default:
    161  1.53      matt 	        printf("dec_kn20aa_intr_map: weird device number %d\n",
    162   1.1       cgd 		    device);
    163  1.53      matt 	        return 1;
    164   1.1       cgd 	}
    165   1.1       cgd 
    166   1.9       cgd 	kn20aa_irq += buspin - 1;
    167   1.1       cgd 	if (kn20aa_irq > KN20AA_MAX_IRQ)
    168  1.44    provos 		panic("dec_kn20aa_intr_map: kn20aa_irq too large (%d)",
    169   1.1       cgd 		    kn20aa_irq);
    170   1.1       cgd 
    171  1.55   thorpej 	alpha_pci_intr_handle_init(ihp, kn20aa_irq, 0);
    172   1.9       cgd 	return (0);
    173   1.3       cgd }
    174   1.3       cgd 
    175  1.55   thorpej static void
    176  1.55   thorpej kn20aa_enable_intr(pci_chipset_tag_t pc __unused, int irq)
    177   1.1       cgd {
    178   1.1       cgd 
    179   1.1       cgd 	/*
    180   1.8       cgd 	 * From disassembling small bits of the OSF/1 kernel:
    181   1.1       cgd 	 * the following appears to enable a given interrupt request.
    182   1.1       cgd 	 * "blech."  I'd give valuable body parts for better docs or
    183   1.1       cgd 	 * for a good decompiler.
    184   1.1       cgd 	 */
    185   1.6       cgd 	alpha_mb();
    186   1.1       cgd 	REGVAL(0x8780000000L + 0x40L) |= (1 << irq);	/* XXX */
    187   1.8       cgd 	alpha_mb();
    188   1.8       cgd }
    189   1.8       cgd 
    190  1.55   thorpej static void
    191  1.55   thorpej kn20aa_disable_intr(pci_chipset_tag_t pc __unused, int irq)
    192   1.8       cgd {
    193   1.8       cgd 
    194   1.8       cgd 	alpha_mb();
    195   1.8       cgd 	REGVAL(0x8780000000L + 0x40L) &= ~(1 << irq);	/* XXX */
    196   1.6       cgd 	alpha_mb();
    197   1.1       cgd }
    198