Home | History | Annotate | Line # | Download | only in pci
pci_kn20aa.c revision 1.58
      1  1.58   thorpej /* $NetBSD: pci_kn20aa.c,v 1.58 2021/07/04 22:36:43 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.58   thorpej __KERNEL_RCSID(0, "$NetBSD: pci_kn20aa.c,v 1.58 2021/07/04 22:36:43 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.1       cgd 
     73  1.56   thorpej 	pc->pc_intr_v = core;
     74  1.53      matt 	pc->pc_intr_map = dec_kn20aa_intr_map;
     75  1.55   thorpej 	pc->pc_intr_string = alpha_pci_generic_intr_string;
     76  1.55   thorpej 	pc->pc_intr_evcnt = alpha_pci_generic_intr_evcnt;
     77  1.55   thorpej 	pc->pc_intr_establish = alpha_pci_generic_intr_establish;
     78  1.55   thorpej 	pc->pc_intr_disestablish = alpha_pci_generic_intr_disestablish;
     79  1.29   thorpej 
     80  1.30    mjacob 	/* Not supported on KN20AA. */
     81  1.29   thorpej 	pc->pc_pciide_compat_intr_establish = NULL;
     82   1.1       cgd 
     83  1.57   thorpej 	pc->pc_intr_desc = "kn20aa";
     84  1.55   thorpej 	pc->pc_vecbase = 0x900;
     85  1.55   thorpej 	pc->pc_nirq = KN20AA_MAX_IRQ;
     86  1.55   thorpej 
     87  1.55   thorpej 	pc->pc_intr_enable = kn20aa_enable_intr;
     88  1.55   thorpej 	pc->pc_intr_disable = kn20aa_disable_intr;
     89  1.55   thorpej 
     90  1.39   thorpej 	for (i = 0; i < KN20AA_MAX_IRQ; i++) {
     91  1.58   thorpej 		kn20aa_disable_intr(pc, i);
     92  1.58   thorpej 	}
     93  1.21       cgd 
     94  1.58   thorpej 	alpha_pci_intr_alloc(pc, PCI_STRAY_MAX);
     95  1.39   thorpej 
     96  1.37   thorpej #if NSIO > 0 || NPCEB > 0
     97  1.27   thorpej 	sio_intr_setup(pc, iot);
     98  1.55   thorpej 	kn20aa_enable_intr(pc, KN20AA_PCEB_IRQ);
     99   1.1       cgd #endif
    100   1.1       cgd }
    101  1.56   thorpej ALPHA_PCI_INTR_INIT(ST_DEC_KN20AA, pci_kn20aa_pickintr)
    102   1.1       cgd 
    103  1.55   thorpej static int
    104  1.52    dyoung dec_kn20aa_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    105   1.1       cgd {
    106  1.41  sommerfe 	pcitag_t bustag = pa->pa_intrtag;
    107  1.41  sommerfe 	int buspin = pa->pa_intrpin;
    108  1.41  sommerfe 	pci_chipset_tag_t pc = pa->pa_pc;
    109   1.1       cgd 	int device;
    110   1.9       cgd 	int kn20aa_irq;
    111   1.1       cgd 
    112  1.31   thorpej 	if (buspin == 0) {
    113  1.31   thorpej 		/* No IRQ used. */
    114  1.31   thorpej 		return 1;
    115  1.31   thorpej 	}
    116  1.55   thorpej 	if (buspin < 0 || buspin > 4) {
    117  1.31   thorpej 		printf("dec_kn20aa_intr_map: bad interrupt pin %d\n", buspin);
    118  1.31   thorpej 		return 1;
    119  1.31   thorpej 	}
    120   1.1       cgd 
    121   1.1       cgd 	/*
    122   1.1       cgd 	 * Slot->interrupt translation.  Appears to work, though it
    123   1.1       cgd 	 * may not hold up forever.
    124   1.1       cgd 	 *
    125   1.1       cgd 	 * The DEC engineers who did this hardware obviously engaged
    126   1.1       cgd 	 * in random drug testing.
    127   1.1       cgd 	 */
    128  1.43   thorpej 	pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    129   1.3       cgd 	switch (device) {
    130   1.1       cgd 	case 11:
    131   1.1       cgd 	case 12:
    132   1.9       cgd 		kn20aa_irq = ((device - 11) + 0) * 4;
    133   1.1       cgd 		break;
    134   1.1       cgd 
    135   1.1       cgd 	case 7:
    136   1.9       cgd 		kn20aa_irq = 8;
    137   1.1       cgd 		break;
    138   1.1       cgd 
    139  1.10       cgd 	case 9:
    140  1.10       cgd 		kn20aa_irq = 12;
    141  1.14       cgd 		break;
    142  1.14       cgd 
    143  1.15       cgd 	case 6:					/* 21040 on AlphaStation 500 */
    144  1.14       cgd 		kn20aa_irq = 13;
    145  1.10       cgd 		break;
    146  1.10       cgd 
    147   1.1       cgd 	case 8:
    148   1.9       cgd 		kn20aa_irq = 16;
    149   1.1       cgd 		break;
    150   1.1       cgd 
    151   1.1       cgd 	default:
    152  1.53      matt 	        printf("dec_kn20aa_intr_map: weird device number %d\n",
    153   1.1       cgd 		    device);
    154  1.53      matt 	        return 1;
    155   1.1       cgd 	}
    156   1.1       cgd 
    157   1.9       cgd 	kn20aa_irq += buspin - 1;
    158   1.1       cgd 	if (kn20aa_irq > KN20AA_MAX_IRQ)
    159  1.44    provos 		panic("dec_kn20aa_intr_map: kn20aa_irq too large (%d)",
    160   1.1       cgd 		    kn20aa_irq);
    161   1.1       cgd 
    162  1.55   thorpej 	alpha_pci_intr_handle_init(ihp, kn20aa_irq, 0);
    163   1.9       cgd 	return (0);
    164   1.3       cgd }
    165   1.3       cgd 
    166  1.55   thorpej static void
    167  1.55   thorpej kn20aa_enable_intr(pci_chipset_tag_t pc __unused, int irq)
    168   1.1       cgd {
    169   1.1       cgd 
    170   1.1       cgd 	/*
    171   1.8       cgd 	 * From disassembling small bits of the OSF/1 kernel:
    172   1.1       cgd 	 * the following appears to enable a given interrupt request.
    173   1.1       cgd 	 * "blech."  I'd give valuable body parts for better docs or
    174   1.1       cgd 	 * for a good decompiler.
    175   1.1       cgd 	 */
    176   1.6       cgd 	alpha_mb();
    177   1.1       cgd 	REGVAL(0x8780000000L + 0x40L) |= (1 << irq);	/* XXX */
    178   1.8       cgd 	alpha_mb();
    179   1.8       cgd }
    180   1.8       cgd 
    181  1.55   thorpej static void
    182  1.55   thorpej kn20aa_disable_intr(pci_chipset_tag_t pc __unused, int irq)
    183   1.8       cgd {
    184   1.8       cgd 
    185   1.8       cgd 	alpha_mb();
    186   1.8       cgd 	REGVAL(0x8780000000L + 0x40L) &= ~(1 << irq);	/* XXX */
    187   1.6       cgd 	alpha_mb();
    188   1.1       cgd }
    189