Home | History | Annotate | Line # | Download | only in pci
pci_axppci_33.c revision 1.14
      1 /* $NetBSD: pci_axppci_33.c,v 1.14 1997/07/19 09:49:53 cgd Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Authors: Jeffrey Hsu and Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <machine/options.h>		/* Config options headers */
     31 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     32 
     33 __KERNEL_RCSID(0, "$NetBSD: pci_axppci_33.c,v 1.14 1997/07/19 09:49:53 cgd Exp $");
     34 
     35 #include <sys/types.h>
     36 #include <sys/param.h>
     37 #include <sys/time.h>
     38 #include <sys/systm.h>
     39 #include <sys/errno.h>
     40 #include <sys/device.h>
     41 #include <vm/vm.h>
     42 
     43 #include <machine/autoconf.h>
     44 #include <machine/bus.h>
     45 #include <machine/intr.h>
     46 
     47 #include <dev/isa/isavar.h>
     48 #include <dev/pci/pcireg.h>
     49 #include <dev/pci/pcivar.h>
     50 
     51 #include <alpha/pci/lcavar.h>
     52 
     53 #include <alpha/pci/pci_axppci_33.h>
     54 #include <alpha/pci/siovar.h>
     55 #include <alpha/pci/sioreg.h>
     56 
     57 #include "sio.h"
     58 
     59 int     dec_axppci_33_intr_map __P((void *, pcitag_t, int, int,
     60 	    pci_intr_handle_t *));
     61 const char *dec_axppci_33_intr_string __P((void *, pci_intr_handle_t));
     62 void    *dec_axppci_33_intr_establish __P((void *, pci_intr_handle_t,
     63 	    int, int (*func)(void *), void *));
     64 void    dec_axppci_33_intr_disestablish __P((void *, void *));
     65 
     66 #define	LCA_SIO_DEVICE	7	/* XXX */
     67 
     68 void
     69 pci_axppci_33_pickintr(lcp)
     70 	struct lca_config *lcp;
     71 {
     72 	bus_space_tag_t iot = lcp->lc_iot;
     73 	pci_chipset_tag_t pc = &lcp->lc_pc;
     74 	pcireg_t sioclass;
     75 	int sioII;
     76 
     77 	/* XXX MAGIC NUMBER */
     78 	sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0),
     79 	    PCI_CLASS_REG);
     80         sioII = (sioclass & 0xff) >= 3;
     81 
     82 	if (!sioII)
     83 		printf("WARNING: SIO NOT SIO II... NO BETS...\n");
     84 
     85 	pc->pc_intr_v = lcp;
     86 	pc->pc_intr_map = dec_axppci_33_intr_map;
     87 	pc->pc_intr_string = dec_axppci_33_intr_string;
     88 	pc->pc_intr_establish = dec_axppci_33_intr_establish;
     89 	pc->pc_intr_disestablish = dec_axppci_33_intr_disestablish;
     90 
     91 #if NSIO
     92 	sio_intr_setup(iot);
     93 	set_iointr(&sio_iointr);
     94 #else
     95 	panic("pci_axppci_33_pickintr: no I/O interrupt handler (no sio)");
     96 #endif
     97 }
     98 
     99 int
    100 dec_axppci_33_intr_map(lcv, bustag, buspin, line, ihp)
    101 	void *lcv;
    102 	pcitag_t bustag;
    103 	int buspin, line;
    104 	pci_intr_handle_t *ihp;
    105 {
    106 	struct lca_config *lcp = lcv;
    107 	pci_chipset_tag_t pc = &lcp->lc_pc;
    108 	int device, pirq;
    109 	pcireg_t pirqreg;
    110 	u_int8_t pirqline;
    111 
    112 #ifndef DIAGNOSTIC
    113 	pirq = 0;				/* XXX gcc -Wuninitialized */
    114 #endif
    115 
    116         if (buspin == 0) {
    117                 /* No IRQ used. */
    118                 return 1;
    119         }
    120         if (buspin > 4) {
    121                 printf("pci_map_int: bad interrupt pin %d\n", buspin);
    122                 return 1;
    123         }
    124 
    125 	alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    126 
    127 	switch (device) {
    128 	case 6:					/* NCR SCSI */
    129 		pirq = 3;
    130 		break;
    131 
    132 	case 11:				/* slot 1 */
    133 		switch (buspin) {
    134 		case PCI_INTERRUPT_PIN_A:
    135 		case PCI_INTERRUPT_PIN_D:
    136 			pirq = 0;
    137 			break;
    138 		case PCI_INTERRUPT_PIN_B:
    139 			pirq = 2;
    140 			break;
    141 		case PCI_INTERRUPT_PIN_C:
    142 			pirq = 1;
    143 			break;
    144 #ifdef DIAGNOSTIC
    145 		default:			/* XXX gcc -Wuninitialized */
    146 			panic("dec_axppci_33_intr_map bogus PCI pin %d\n",
    147 			    buspin);
    148 #endif
    149 		};
    150 		break;
    151 
    152 	case 12:				/* slot 2 */
    153 		switch (buspin) {
    154 		case PCI_INTERRUPT_PIN_A:
    155 		case PCI_INTERRUPT_PIN_D:
    156 			pirq = 1;
    157 			break;
    158 		case PCI_INTERRUPT_PIN_B:
    159 			pirq = 0;
    160 			break;
    161 		case PCI_INTERRUPT_PIN_C:
    162 			pirq = 2;
    163 			break;
    164 #ifdef DIAGNOSTIC
    165 		default:			/* XXX gcc -Wuninitialized */
    166 			panic("dec_axppci_33_intr_map bogus PCI pin %d\n",
    167 			    buspin);
    168 #endif
    169 		};
    170 		break;
    171 
    172 	case 8:				/* slot 3 */
    173 		switch (buspin) {
    174 		case PCI_INTERRUPT_PIN_A:
    175 		case PCI_INTERRUPT_PIN_D:
    176 			pirq = 2;
    177 			break;
    178 		case PCI_INTERRUPT_PIN_B:
    179 			pirq = 1;
    180 			break;
    181 		case PCI_INTERRUPT_PIN_C:
    182 			pirq = 0;
    183 			break;
    184 #ifdef DIAGNOSTIC
    185 		default:			/* XXX gcc -Wuninitialized */
    186 			panic("dec_axppci_33_intr_map bogus PCI pin %d\n",
    187 			    buspin);
    188 #endif
    189 		};
    190 		break;
    191 
    192 	default:
    193                 printf("dec_axppci_33_intr_map: weird device number %d\n",
    194 		    device);
    195                 return 1;
    196 	}
    197 
    198 	pirqreg = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0),
    199 	    SIO_PCIREG_PIRQ_RTCTRL);
    200 #if 0
    201 	printf("pci_axppci_33_map_int: device %d pin %c: pirq %d, reg = %x\n",
    202 		device, '@' + buspin, pirq, pirqreg);
    203 #endif
    204 	pirqline = (pirqreg >> (pirq * 8)) & 0xff;
    205 	if ((pirqline & 0x80) != 0)
    206 		return 1;			/* not routed? */
    207 	pirqline &= 0xf;
    208 
    209 #if 0
    210 	printf("pci_axppci_33_map_int: device %d pin %c: mapped to line %d\n",
    211 	    device, '@' + buspin, pirqline);
    212 #endif
    213 
    214 	*ihp = pirqline;
    215 	return (0);
    216 }
    217 
    218 const char *
    219 dec_axppci_33_intr_string(lcv, ih)
    220 	void *lcv;
    221 	pci_intr_handle_t ih;
    222 {
    223 #if 0
    224 	struct lca_config *lcp = lcv;
    225 #endif
    226 
    227 	return sio_intr_string(NULL /*XXX*/, ih);
    228 }
    229 
    230 void *
    231 dec_axppci_33_intr_establish(lcv, ih, level, func, arg)
    232 	void *lcv, *arg;
    233 	pci_intr_handle_t ih;
    234 	int level;
    235 	int (*func) __P((void *));
    236 {
    237 #if 0
    238 	struct lca_config *lcp = lcv;
    239 #endif
    240 
    241 	return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
    242 	    arg);
    243 }
    244 
    245 void
    246 dec_axppci_33_intr_disestablish(lcv, cookie)
    247 	void *lcv, *cookie;
    248 {
    249 #if 0
    250 	struct lca_config *lcp = lcv;
    251 #endif
    252 
    253 	sio_intr_disestablish(NULL /*XXX*/, cookie);
    254 }
    255