Home | History | Annotate | Line # | Download | only in pci
pci_kn20aa.c revision 1.55
      1  1.55   thorpej /* $NetBSD: pci_kn20aa.c,v 1.55 2020/09/22 15:24:02 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.55   thorpej __KERNEL_RCSID(0, "$NetBSD: pci_kn20aa.c,v 1.55 2020/09/22 15:24:02 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.7       cgd 
     45   1.1       cgd #include <dev/pci/pcireg.h>
     46   1.1       cgd #include <dev/pci/pcivar.h>
     47   1.1       cgd 
     48   1.1       cgd #include <alpha/pci/ciareg.h>
     49   1.1       cgd #include <alpha/pci/ciavar.h>
     50   1.1       cgd 
     51   1.1       cgd #include <alpha/pci/pci_kn20aa.h>
     52   1.1       cgd 
     53   1.1       cgd #include "sio.h"
     54  1.37   thorpej #if NSIO > 0 || NPCEB > 0
     55   1.1       cgd #include <alpha/pci/siovar.h>
     56   1.1       cgd #endif
     57   1.1       cgd 
     58  1.55   thorpej static int	dec_kn20aa_intr_map(const struct pci_attach_args *,
     59  1.55   thorpej 		    pci_intr_handle_t *);
     60   1.1       cgd 
     61   1.1       cgd #define	KN20AA_PCEB_IRQ	31
     62   1.1       cgd #define	KN20AA_MAX_IRQ	32
     63   1.1       cgd #define	PCI_STRAY_MAX	5
     64   1.1       cgd 
     65  1.55   thorpej static void	kn20aa_enable_intr(pci_chipset_tag_t pc, int irq);
     66  1.55   thorpej static void	kn20aa_disable_intr(pci_chipset_tag_t pc, int irq);
     67   1.1       cgd 
     68   1.1       cgd void
     69  1.49       dsl pci_kn20aa_pickintr(struct cia_config *ccp)
     70   1.1       cgd {
     71   1.1       cgd 	int i;
     72  1.37   thorpej #if NSIO > 0 || NPCEB > 0
     73  1.26   thorpej 	bus_space_tag_t iot = &ccp->cc_iot;
     74  1.35    mjacob #endif
     75   1.3       cgd 	pci_chipset_tag_t pc = &ccp->cc_pc;
     76  1.39   thorpej 	char *cp;
     77   1.1       cgd 
     78  1.53      matt 	pc->pc_intr_v = ccp;
     79  1.53      matt 	pc->pc_intr_map = dec_kn20aa_intr_map;
     80  1.55   thorpej 	pc->pc_intr_string = alpha_pci_generic_intr_string;
     81  1.55   thorpej 	pc->pc_intr_evcnt = alpha_pci_generic_intr_evcnt;
     82  1.55   thorpej 	pc->pc_intr_establish = alpha_pci_generic_intr_establish;
     83  1.55   thorpej 	pc->pc_intr_disestablish = alpha_pci_generic_intr_disestablish;
     84  1.29   thorpej 
     85  1.30    mjacob 	/* Not supported on KN20AA. */
     86  1.29   thorpej 	pc->pc_pciide_compat_intr_establish = NULL;
     87   1.1       cgd 
     88  1.54  christos #define PCI_KN20AA_IRQ_STR	8
     89  1.55   thorpej 	pc->pc_shared_intrs = alpha_shared_intr_alloc(KN20AA_MAX_IRQ,
     90  1.54  christos 	    PCI_KN20AA_IRQ_STR);
     91  1.55   thorpej 	pc->pc_intr_desc = "kn20aa irq";
     92  1.55   thorpej 	pc->pc_vecbase = 0x900;
     93  1.55   thorpej 	pc->pc_nirq = KN20AA_MAX_IRQ;
     94  1.55   thorpej 
     95  1.55   thorpej 	pc->pc_intr_enable = kn20aa_enable_intr;
     96  1.55   thorpej 	pc->pc_intr_disable = kn20aa_disable_intr;
     97  1.55   thorpej 
     98  1.39   thorpej 	for (i = 0; i < KN20AA_MAX_IRQ; i++) {
     99  1.55   thorpej 		alpha_shared_intr_set_maxstrays(pc->pc_shared_intrs, i,
    100  1.21       cgd 		    PCI_STRAY_MAX);
    101  1.21       cgd 
    102  1.55   thorpej 		cp = alpha_shared_intr_string(pc->pc_shared_intrs, i);
    103  1.54  christos 		snprintf(cp, PCI_KN20AA_IRQ_STR, "irq %d", i);
    104  1.39   thorpej 		evcnt_attach_dynamic(alpha_shared_intr_evcnt(
    105  1.55   thorpej 		    pc->pc_shared_intrs, i), EVCNT_TYPE_INTR, NULL,
    106  1.39   thorpej 		    "kn20aa", cp);
    107  1.39   thorpej 	}
    108  1.39   thorpej 
    109  1.37   thorpej #if NSIO > 0 || NPCEB > 0
    110  1.27   thorpej 	sio_intr_setup(pc, iot);
    111  1.55   thorpej 	kn20aa_enable_intr(pc, KN20AA_PCEB_IRQ);
    112   1.1       cgd #endif
    113   1.1       cgd }
    114   1.1       cgd 
    115  1.55   thorpej static int
    116  1.52    dyoung dec_kn20aa_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    117   1.1       cgd {
    118  1.41  sommerfe 	pcitag_t bustag = pa->pa_intrtag;
    119  1.41  sommerfe 	int buspin = pa->pa_intrpin;
    120  1.41  sommerfe 	pci_chipset_tag_t pc = pa->pa_pc;
    121   1.1       cgd 	int device;
    122   1.9       cgd 	int kn20aa_irq;
    123   1.1       cgd 
    124  1.31   thorpej 	if (buspin == 0) {
    125  1.31   thorpej 		/* No IRQ used. */
    126  1.31   thorpej 		return 1;
    127  1.31   thorpej 	}
    128  1.55   thorpej 	if (buspin < 0 || buspin > 4) {
    129  1.31   thorpej 		printf("dec_kn20aa_intr_map: bad interrupt pin %d\n", buspin);
    130  1.31   thorpej 		return 1;
    131  1.31   thorpej 	}
    132   1.1       cgd 
    133   1.1       cgd 	/*
    134   1.1       cgd 	 * Slot->interrupt translation.  Appears to work, though it
    135   1.1       cgd 	 * may not hold up forever.
    136   1.1       cgd 	 *
    137   1.1       cgd 	 * The DEC engineers who did this hardware obviously engaged
    138   1.1       cgd 	 * in random drug testing.
    139   1.1       cgd 	 */
    140  1.43   thorpej 	pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    141   1.3       cgd 	switch (device) {
    142   1.1       cgd 	case 11:
    143   1.1       cgd 	case 12:
    144   1.9       cgd 		kn20aa_irq = ((device - 11) + 0) * 4;
    145   1.1       cgd 		break;
    146   1.1       cgd 
    147   1.1       cgd 	case 7:
    148   1.9       cgd 		kn20aa_irq = 8;
    149   1.1       cgd 		break;
    150   1.1       cgd 
    151  1.10       cgd 	case 9:
    152  1.10       cgd 		kn20aa_irq = 12;
    153  1.14       cgd 		break;
    154  1.14       cgd 
    155  1.15       cgd 	case 6:					/* 21040 on AlphaStation 500 */
    156  1.14       cgd 		kn20aa_irq = 13;
    157  1.10       cgd 		break;
    158  1.10       cgd 
    159   1.1       cgd 	case 8:
    160   1.9       cgd 		kn20aa_irq = 16;
    161   1.1       cgd 		break;
    162   1.1       cgd 
    163   1.1       cgd 	default:
    164  1.53      matt 	        printf("dec_kn20aa_intr_map: weird device number %d\n",
    165   1.1       cgd 		    device);
    166  1.53      matt 	        return 1;
    167   1.1       cgd 	}
    168   1.1       cgd 
    169   1.9       cgd 	kn20aa_irq += buspin - 1;
    170   1.1       cgd 	if (kn20aa_irq > KN20AA_MAX_IRQ)
    171  1.44    provos 		panic("dec_kn20aa_intr_map: kn20aa_irq too large (%d)",
    172   1.1       cgd 		    kn20aa_irq);
    173   1.1       cgd 
    174  1.55   thorpej 	alpha_pci_intr_handle_init(ihp, kn20aa_irq, 0);
    175   1.9       cgd 	return (0);
    176   1.3       cgd }
    177   1.3       cgd 
    178  1.55   thorpej static void
    179  1.55   thorpej kn20aa_enable_intr(pci_chipset_tag_t pc __unused, int irq)
    180   1.1       cgd {
    181   1.1       cgd 
    182   1.1       cgd 	/*
    183   1.8       cgd 	 * From disassembling small bits of the OSF/1 kernel:
    184   1.1       cgd 	 * the following appears to enable a given interrupt request.
    185   1.1       cgd 	 * "blech."  I'd give valuable body parts for better docs or
    186   1.1       cgd 	 * for a good decompiler.
    187   1.1       cgd 	 */
    188   1.6       cgd 	alpha_mb();
    189   1.1       cgd 	REGVAL(0x8780000000L + 0x40L) |= (1 << irq);	/* XXX */
    190   1.8       cgd 	alpha_mb();
    191   1.8       cgd }
    192   1.8       cgd 
    193  1.55   thorpej static void
    194  1.55   thorpej kn20aa_disable_intr(pci_chipset_tag_t pc __unused, int irq)
    195   1.8       cgd {
    196   1.8       cgd 
    197   1.8       cgd 	alpha_mb();
    198   1.8       cgd 	REGVAL(0x8780000000L + 0x40L) &= ~(1 << irq);	/* XXX */
    199   1.6       cgd 	alpha_mb();
    200   1.1       cgd }
    201