Home | History | Annotate | Line # | Download | only in pci
pci_eb164.c revision 1.13
      1  1.13  thorpej /* $NetBSD: pci_eb164.c,v 1.13 1998/04/16 19:50:55 thorpej Exp $ */
      2   1.1      cgd 
      3   1.1      cgd /*
      4   1.1      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.1      cgd  *
      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.1      cgd  *
     15   1.1      cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16   1.1      cgd  * 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.1      cgd  *
     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.5      cgd 
     30   1.6      cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31   1.6      cgd 
     32  1.13  thorpej __KERNEL_RCSID(0, "$NetBSD: pci_eb164.c,v 1.13 1998/04/16 19:50:55 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.1      cgd #include <vm/vm.h>
     44   1.1      cgd 
     45   1.1      cgd #include <machine/autoconf.h>
     46   1.1      cgd 
     47   1.1      cgd #include <dev/pci/pcireg.h>
     48   1.1      cgd #include <dev/pci/pcivar.h>
     49   1.1      cgd 
     50   1.1      cgd #include <alpha/pci/ciareg.h>
     51   1.1      cgd #include <alpha/pci/ciavar.h>
     52   1.1      cgd 
     53   1.1      cgd #include <alpha/pci/pci_eb164.h>
     54   1.1      cgd 
     55   1.1      cgd #ifndef EVCNT_COUNTERS
     56   1.1      cgd #include <machine/intrcnt.h>
     57   1.1      cgd #endif
     58   1.1      cgd 
     59   1.1      cgd #include "sio.h"
     60   1.1      cgd #if NSIO
     61   1.1      cgd #include <alpha/pci/siovar.h>
     62   1.1      cgd #endif
     63   1.1      cgd 
     64   1.1      cgd int	dec_eb164_intr_map __P((void *, pcitag_t, int, int,
     65   1.1      cgd 	    pci_intr_handle_t *));
     66   1.1      cgd const char *dec_eb164_intr_string __P((void *, pci_intr_handle_t));
     67   1.1      cgd void	*dec_eb164_intr_establish __P((void *, pci_intr_handle_t,
     68   1.1      cgd 	    int, int (*func)(void *), void *));
     69   1.1      cgd void	dec_eb164_intr_disestablish __P((void *, void *));
     70   1.1      cgd 
     71   1.3      cgd #define	EB164_SIO_IRQ	4
     72   1.3      cgd #define	EB164_MAX_IRQ	24
     73   1.3      cgd #define	PCI_STRAY_MAX	5
     74   1.3      cgd 
     75   1.3      cgd struct alpha_shared_intr *eb164_pci_intr;
     76   1.3      cgd #ifdef EVCNT_COUNTERS
     77   1.3      cgd struct evcnt eb164_intr_evcnt;
     78   1.3      cgd #endif
     79   1.3      cgd 
     80   1.3      cgd bus_space_tag_t eb164_intrgate_iot;
     81   1.3      cgd bus_space_handle_t eb164_intrgate_ioh;
     82   1.3      cgd 
     83   1.1      cgd void	eb164_iointr __P((void *framep, unsigned long vec));
     84   1.4      cgd extern void	eb164_intr_enable __P((int irq));	/* pci_eb164_intr.S */
     85   1.4      cgd extern void	eb164_intr_disable __P((int irq));	/* pci_eb164_intr.S */
     86   1.1      cgd 
     87   1.1      cgd void
     88   1.1      cgd pci_eb164_pickintr(ccp)
     89   1.1      cgd 	struct cia_config *ccp;
     90   1.1      cgd {
     91  1.10  thorpej 	bus_space_tag_t iot = &ccp->cc_iot;
     92   1.1      cgd 	pci_chipset_tag_t pc = &ccp->cc_pc;
     93   1.3      cgd 	int i;
     94   1.1      cgd 
     95   1.1      cgd         pc->pc_intr_v = ccp;
     96   1.1      cgd         pc->pc_intr_map = dec_eb164_intr_map;
     97   1.1      cgd         pc->pc_intr_string = dec_eb164_intr_string;
     98   1.1      cgd         pc->pc_intr_establish = dec_eb164_intr_establish;
     99   1.1      cgd         pc->pc_intr_disestablish = dec_eb164_intr_disestablish;
    100   1.1      cgd 
    101   1.3      cgd 	eb164_intrgate_iot = iot;
    102   1.3      cgd 	if (bus_space_map(eb164_intrgate_iot, 0x804, 3, 0,
    103   1.3      cgd 	    &eb164_intrgate_ioh) != 0)
    104   1.3      cgd 		panic("pci_eb164_pickintr: couldn't map interrupt PLD");
    105   1.3      cgd 	for (i = 0; i < EB164_MAX_IRQ; i++)
    106   1.4      cgd 		eb164_intr_disable(i);
    107   1.3      cgd 
    108   1.3      cgd 	eb164_pci_intr = alpha_shared_intr_alloc(EB164_MAX_IRQ);
    109   1.3      cgd 	for (i = 0; i < EB164_MAX_IRQ; i++)
    110   1.3      cgd 		alpha_shared_intr_set_maxstrays(eb164_pci_intr, i,
    111   1.3      cgd 			PCI_STRAY_MAX);
    112   1.3      cgd 
    113   1.1      cgd #if NSIO
    114  1.11  thorpej 	sio_intr_setup(pc, iot);
    115   1.4      cgd 	eb164_intr_enable(EB164_SIO_IRQ);
    116   1.1      cgd #endif
    117   1.1      cgd 
    118   1.1      cgd 	set_iointr(eb164_iointr);
    119   1.1      cgd }
    120   1.1      cgd 
    121   1.1      cgd int
    122   1.1      cgd dec_eb164_intr_map(ccv, bustag, buspin, line, ihp)
    123   1.1      cgd         void *ccv;
    124   1.1      cgd         pcitag_t bustag;
    125   1.1      cgd         int buspin, line;
    126   1.1      cgd         pci_intr_handle_t *ihp;
    127   1.1      cgd {
    128   1.1      cgd 	struct cia_config *ccp = ccv;
    129   1.1      cgd 	pci_chipset_tag_t pc = &ccp->cc_pc;
    130   1.1      cgd 	int device;
    131   1.3      cgd 	int eb164_irq, pinbase, pinoff;
    132   1.7      cgd 
    133   1.7      cgd #ifndef DIAGNOSTIC
    134   1.7      cgd 	pinbase = pinoff = 0;			/* XXX gcc -Wuninitialized */
    135   1.7      cgd #endif
    136   1.1      cgd 
    137   1.1      cgd         if (buspin == 0) {
    138   1.1      cgd                 /* No IRQ used. */
    139   1.1      cgd                 return 1;
    140   1.1      cgd         }
    141   1.1      cgd         if (buspin > 4) {
    142  1.13  thorpej                 printf("dec_eb164_intr_map: bad interrupt pin %d\n", buspin);
    143   1.1      cgd                 return 1;
    144   1.1      cgd         }
    145   1.1      cgd 
    146   1.8      cgd 	alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    147   1.1      cgd 	switch (device) {
    148  1.12  thorpej 	/*
    149  1.12  thorpej 	 * There might be a PCI IDE controller on one of the SIO's
    150  1.12  thorpej 	 * functions, so go ahead and map this interrupt.
    151  1.12  thorpej 	 */
    152   1.3      cgd 	case 8: 					/* SIO */
    153   1.3      cgd 		eb164_irq = 4;
    154   1.3      cgd 		break;
    155   1.3      cgd 
    156   1.1      cgd 	case 11:
    157   1.3      cgd 		eb164_irq = 5;				/* IDE */
    158   1.1      cgd 		break;
    159   1.1      cgd 
    160   1.4      cgd 	case 5:
    161   1.3      cgd 	case 6:
    162   1.1      cgd 	case 7:
    163   1.1      cgd 	case 9:
    164   1.3      cgd 		switch (buspin) {
    165   1.3      cgd 		case 1:
    166   1.3      cgd 			pinbase = 0;
    167   1.3      cgd 			break;
    168   1.3      cgd 		case 2:
    169   1.3      cgd 		case 3:
    170   1.3      cgd 		case 4:
    171   1.3      cgd 			pinbase = (buspin * 4) - 1;
    172   1.3      cgd 			break;
    173   1.3      cgd #ifdef DIAGNOSTIC
    174   1.3      cgd 		default:
    175   1.3      cgd 			panic("dec_eb164_intr_map: slot buspin switch");
    176   1.3      cgd #endif
    177   1.3      cgd 		};
    178   1.3      cgd 		switch (device) {
    179   1.3      cgd 		case 5:
    180   1.3      cgd 			pinoff = 2;
    181   1.3      cgd 			break;
    182   1.3      cgd 
    183   1.3      cgd 		case 6:
    184   1.3      cgd 		case 7:
    185   1.3      cgd 		case 9:
    186   1.3      cgd 			pinoff = device - 6;
    187   1.3      cgd 			break;
    188   1.3      cgd #ifdef DIAGNOSTIC
    189   1.3      cgd 		default:
    190   1.3      cgd 			panic("dec_eb164_intr_map: slot device switch");
    191   1.3      cgd #endif
    192   1.3      cgd 		}
    193   1.3      cgd 		eb164_irq = pinoff + pinbase;
    194   1.1      cgd 		break;
    195   1.1      cgd 	default:
    196  1.13  thorpej 		panic("dec_eb164_intr_map: invalid device number %d\n",
    197   1.1      cgd 		    device);
    198   1.1      cgd 	}
    199   1.1      cgd 
    200   1.3      cgd 	if (eb164_irq > EB164_MAX_IRQ)
    201  1.13  thorpej 		panic("dec_eb164_intr_map: eb164_irq too large (%d)\n",
    202   1.1      cgd 		    eb164_irq);
    203   1.1      cgd 
    204   1.1      cgd 	*ihp = eb164_irq;
    205   1.1      cgd 	return (0);
    206   1.1      cgd }
    207   1.1      cgd 
    208   1.1      cgd const char *
    209   1.1      cgd dec_eb164_intr_string(ccv, ih)
    210   1.1      cgd 	void *ccv;
    211   1.1      cgd 	pci_intr_handle_t ih;
    212   1.1      cgd {
    213   1.2      cgd #if 0
    214   1.1      cgd 	struct cia_config *ccp = ccv;
    215   1.2      cgd #endif
    216   1.1      cgd         static char irqstr[15];          /* 11 + 2 + NULL + sanity */
    217   1.1      cgd 
    218   1.3      cgd         if (ih > EB164_MAX_IRQ)
    219   1.3      cgd                 panic("dec_eb164_intr_string: bogus eb164 IRQ 0x%x\n", ih);
    220   1.1      cgd         sprintf(irqstr, "eb164 irq %d", ih);
    221   1.1      cgd         return (irqstr);
    222   1.1      cgd }
    223   1.1      cgd 
    224   1.1      cgd void *
    225   1.1      cgd dec_eb164_intr_establish(ccv, ih, level, func, arg)
    226   1.1      cgd         void *ccv, *arg;
    227   1.1      cgd         pci_intr_handle_t ih;
    228   1.1      cgd         int level;
    229   1.1      cgd         int (*func) __P((void *));
    230   1.1      cgd {
    231   1.3      cgd #if 0
    232   1.3      cgd 	struct cia_config *ccp = ccv;
    233   1.3      cgd #endif
    234   1.3      cgd 	void *cookie;
    235   1.1      cgd 
    236   1.3      cgd 	if (ih > EB164_MAX_IRQ)
    237   1.3      cgd 		panic("dec_eb164_intr_establish: bogus eb164 IRQ 0x%x\n", ih);
    238   1.1      cgd 
    239   1.3      cgd 	cookie = alpha_shared_intr_establish(eb164_pci_intr, ih, IST_LEVEL,
    240   1.3      cgd 	    level, func, arg, "eb164 irq");
    241   1.1      cgd 
    242   1.3      cgd 	if (cookie != NULL && alpha_shared_intr_isactive(eb164_pci_intr, ih))
    243   1.4      cgd 		eb164_intr_enable(ih);
    244   1.1      cgd 	return (cookie);
    245   1.1      cgd }
    246   1.1      cgd 
    247   1.3      cgd void
    248   1.1      cgd dec_eb164_intr_disestablish(ccv, cookie)
    249   1.1      cgd         void *ccv, *cookie;
    250   1.1      cgd {
    251   1.3      cgd #if 0
    252   1.3      cgd 	struct cia_config *ccp = ccv;
    253   1.3      cgd #endif
    254   1.1      cgd 
    255   1.1      cgd 	panic("dec_eb164_intr_disestablish not implemented"); /* XXX */
    256   1.1      cgd }
    257   1.1      cgd 
    258   1.1      cgd void
    259   1.1      cgd eb164_iointr(framep, vec)
    260   1.1      cgd 	void *framep;
    261   1.1      cgd 	unsigned long vec;
    262   1.1      cgd {
    263   1.3      cgd 	int irq;
    264   1.3      cgd 
    265   1.3      cgd 	if (vec >= 0x900) {
    266   1.3      cgd 		if (vec >= 0x900 + (EB164_MAX_IRQ << 4))
    267   1.3      cgd 			panic("eb164_iointr: vec 0x%x out of range\n", vec);
    268   1.3      cgd 		irq = (vec - 0x900) >> 4;
    269   1.3      cgd 
    270   1.3      cgd #ifdef EVCNT_COUNTERS
    271   1.3      cgd 		eb164_intr_evcnt.ev_count++;
    272   1.3      cgd #else
    273   1.3      cgd 		if (EB164_MAX_IRQ != INTRCNT_EB164_IRQ_LEN)
    274   1.3      cgd 			panic("eb164 interrupt counter sizes inconsistent");
    275   1.3      cgd 		intrcnt[INTRCNT_EB164_IRQ + irq]++;
    276   1.3      cgd #endif
    277   1.1      cgd 
    278   1.3      cgd 		if (!alpha_shared_intr_dispatch(eb164_pci_intr, irq)) {
    279   1.3      cgd 			alpha_shared_intr_stray(eb164_pci_intr, irq,
    280   1.3      cgd 			    "eb164 irq");
    281   1.3      cgd 			if (eb164_pci_intr[irq].intr_nstrays ==
    282   1.3      cgd 			    eb164_pci_intr[irq].intr_maxstrays)
    283   1.4      cgd 				eb164_intr_disable(irq);
    284   1.3      cgd 		}
    285   1.3      cgd 		return;
    286   1.3      cgd 	}
    287   1.3      cgd #if NSIO
    288   1.3      cgd 	if (vec >= 0x800) {
    289   1.3      cgd 		sio_iointr(framep, vec);
    290   1.3      cgd 		return;
    291   1.3      cgd 	}
    292   1.3      cgd #endif
    293   1.1      cgd 	panic("eb164_iointr: weird vec 0x%x\n", vec);
    294   1.3      cgd }
    295   1.3      cgd 
    296   1.4      cgd #if 0		/* THIS DOES NOT WORK!  see pci_eb164_intr.S. */
    297   1.3      cgd u_int8_t eb164_intr_mask[3] = { 0xff, 0xff, 0xff };
    298   1.3      cgd 
    299   1.3      cgd void
    300   1.4      cgd eb164_intr_enable(irq)
    301   1.3      cgd 	int irq;
    302   1.3      cgd {
    303   1.3      cgd 	int byte = (irq / 8), bit = (irq % 8);
    304   1.3      cgd 
    305   1.3      cgd #if 1
    306   1.4      cgd 	printf("eb164_intr_enable: enabling %d (%d:%d)\n", irq, byte, bit);
    307   1.3      cgd #endif
    308   1.3      cgd 	eb164_intr_mask[byte] &= ~(1 << bit);
    309   1.3      cgd 
    310   1.3      cgd 	bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
    311   1.3      cgd 	    eb164_intr_mask[byte]);
    312   1.3      cgd }
    313   1.3      cgd 
    314   1.3      cgd void
    315   1.4      cgd eb164_intr_disable(irq)
    316   1.3      cgd 	int irq;
    317   1.3      cgd {
    318   1.3      cgd 	int byte = (irq / 8), bit = (irq % 8);
    319   1.3      cgd 
    320   1.3      cgd #if 1
    321   1.4      cgd 	printf("eb164_intr_disable: disabling %d (%d:%d)\n", irq, byte, bit);
    322   1.3      cgd #endif
    323   1.3      cgd 	eb164_intr_mask[byte] |= (1 << bit);
    324   1.3      cgd 
    325   1.3      cgd 	bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
    326   1.3      cgd 	    eb164_intr_mask[byte]);
    327   1.1      cgd }
    328   1.4      cgd #endif
    329