Home | History | Annotate | Line # | Download | only in pci
pci_2100_a50.c revision 1.13
      1 /* $NetBSD: pci_2100_a50.c,v 1.13 1997/04/07 02:01:20 cgd Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: 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>		/* Pull in config options headers */
     31 
     32 #include <sys/types.h>
     33 #include <sys/param.h>
     34 #include <sys/time.h>
     35 #include <sys/systm.h>
     36 #include <sys/errno.h>
     37 #include <sys/device.h>
     38 #include <vm/vm.h>
     39 
     40 #include <machine/autoconf.h>
     41 #include <machine/bus.h>
     42 #include <machine/intr.h>
     43 
     44 #include <dev/isa/isavar.h>
     45 #include <dev/pci/pcireg.h>
     46 #include <dev/pci/pcivar.h>
     47 
     48 #include <alpha/pci/apecsvar.h>
     49 
     50 #include <alpha/pci/pci_2100_a50.h>
     51 #include <alpha/pci/siovar.h>
     52 #include <alpha/pci/sioreg.h>
     53 
     54 #include "sio.h"
     55 
     56 int	dec_2100_a50_intr_map __P((void *, pcitag_t, int, int,
     57 	    pci_intr_handle_t *));
     58 const char *dec_2100_a50_intr_string __P((void *, pci_intr_handle_t));
     59 void    *dec_2100_a50_intr_establish __P((void *, pci_intr_handle_t,
     60 	    int, int (*func)(void *), void *));
     61 void    dec_2100_a50_intr_disestablish __P((void *, void *));
     62 
     63 #define	APECS_SIO_DEVICE	7	/* XXX */
     64 
     65 void
     66 pci_2100_a50_pickintr(acp)
     67 	struct apecs_config *acp;
     68 {
     69 	bus_space_tag_t iot = acp->ac_iot;
     70 	pci_chipset_tag_t pc = &acp->ac_pc;
     71 	pcireg_t sioclass;
     72 	int sioII;
     73 
     74 	/* XXX MAGIC NUMBER */
     75 	sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, 7, 0), PCI_CLASS_REG);
     76         sioII = (sioclass & 0xff) >= 3;
     77 
     78 	if (!sioII)
     79 		printf("WARNING: SIO NOT SIO II... NO BETS...\n");
     80 
     81 	pc->pc_intr_v = acp;
     82 	pc->pc_intr_map = dec_2100_a50_intr_map;
     83 	pc->pc_intr_string = dec_2100_a50_intr_string;
     84 	pc->pc_intr_establish = dec_2100_a50_intr_establish;
     85 	pc->pc_intr_disestablish = dec_2100_a50_intr_disestablish;
     86 
     87 #if NSIO
     88         sio_intr_setup(iot);
     89 	set_iointr(&sio_iointr);
     90 #else
     91 	panic("pci_2100_a50_pickintr: no I/O interrupt handler (no sio)");
     92 #endif
     93 }
     94 
     95 int
     96 dec_2100_a50_intr_map(acv, bustag, buspin, line, ihp)
     97 	void *acv;
     98         pcitag_t bustag;
     99 	int buspin, line;
    100 	pci_intr_handle_t *ihp;
    101 {
    102 	struct apecs_config *acp = acv;
    103 	pci_chipset_tag_t pc = &acp->ac_pc;
    104 	int device, pirq;
    105 	pcireg_t pirqreg;
    106 	u_int8_t pirqline;
    107 
    108         if (buspin == 0) {
    109                 /* No IRQ used. */
    110                 return 1;
    111         }
    112         if (buspin > 4) {
    113                 printf("dec_2100_a50_intr_map: bad interrupt pin %d\n",
    114 		    buspin);
    115                 return 1;
    116         }
    117 
    118 	pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    119 
    120 	switch (device) {
    121 	case 6:					/* NCR SCSI */
    122 		pirq = 3;
    123 		break;
    124 
    125 	case 11:				/* slot 1 */
    126 	case 14:				/* slot 3 */
    127 		switch (buspin) {
    128 		case PCI_INTERRUPT_PIN_A:
    129 		case PCI_INTERRUPT_PIN_D:
    130 			pirq = 0;
    131 			break;
    132 		case PCI_INTERRUPT_PIN_B:
    133 			pirq = 2;
    134 			break;
    135 		case PCI_INTERRUPT_PIN_C:
    136 			pirq = 1;
    137 			break;
    138 #ifdef DIAGNOSTIC
    139 		default:			/* XXX gcc -Wuninitialized */
    140 			panic("dec_2100_a50_intr_map bogus PCI pin %d\n",
    141 			    buspin);
    142 #endif
    143 		};
    144 		break;
    145 
    146 	case 12:				/* slot 2 */
    147 		switch (buspin) {
    148 		case PCI_INTERRUPT_PIN_A:
    149 		case PCI_INTERRUPT_PIN_D:
    150 			pirq = 1;
    151 			break;
    152 		case PCI_INTERRUPT_PIN_B:
    153 			pirq = 0;
    154 			break;
    155 		case PCI_INTERRUPT_PIN_C:
    156 			pirq = 2;
    157 			break;
    158 #ifdef DIAGNOSTIC
    159 		default:			/* XXX gcc -Wuninitialized */
    160 			panic("dec_2100_a50_intr_map bogus PCI pin %d\n",
    161 			    buspin);
    162 #endif
    163 		};
    164 		break;
    165 
    166 	case 13:				/* slot 3 */
    167 		switch (buspin) {
    168 		case PCI_INTERRUPT_PIN_A:
    169 		case PCI_INTERRUPT_PIN_D:
    170 			pirq = 2;
    171 			break;
    172 		case PCI_INTERRUPT_PIN_B:
    173 			pirq = 1;
    174 			break;
    175 		case PCI_INTERRUPT_PIN_C:
    176 			pirq = 0;
    177 			break;
    178 #ifdef DIAGNOSTIC
    179 		default:			/* XXX gcc -Wuninitialized */
    180 			panic("dec_2100_a50_intr_map bogus PCI pin %d\n",
    181 			    buspin);
    182 #endif
    183 		};
    184 		break;
    185 
    186 	default:
    187                 printf("dec_2100_a50_intr_map: weird device number %d\n",
    188 		    device);
    189                 return 1;
    190 	}
    191 
    192 	pirqreg = pci_conf_read(pc, pci_make_tag(pc, 0, APECS_SIO_DEVICE, 0),
    193 	    SIO_PCIREG_PIRQ_RTCTRL);
    194 #if 0
    195 	printf("pci_2100_a50_map_int: device %d pin %c: pirq %d, reg = %x\n",
    196 		device, '@' + buspin, pirq, pirqreg);
    197 #endif
    198 	pirqline = (pirqreg >> (pirq * 8)) & 0xff;
    199 	if ((pirqline & 0x80) != 0)
    200 		return 1;
    201 	pirqline &= 0xf;
    202 
    203 #if 0
    204 	printf("pci_2100_a50_map_int: device %d pin %c: mapped to line %d\n",
    205 	    device, '@' + buspin, pirqline);
    206 #endif
    207 
    208 	*ihp = pirqline;
    209 	return (0);
    210 }
    211 
    212 const char *
    213 dec_2100_a50_intr_string(acv, ih)
    214 	void *acv;
    215 	pci_intr_handle_t ih;
    216 {
    217 #if 0
    218 	struct apecs_config *acp = acv;
    219 #endif
    220 
    221 	return sio_intr_string(NULL /*XXX*/, ih);
    222 }
    223 
    224 void *
    225 dec_2100_a50_intr_establish(acv, ih, level, func, arg)
    226 	void *acv, *arg;
    227 	pci_intr_handle_t ih;
    228 	int level;
    229 	int (*func) __P((void *));
    230 {
    231 #if 0
    232 	struct apecs_config *acp = acv;
    233 #endif
    234 
    235 	return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
    236 	    arg);
    237 }
    238 
    239 void
    240 dec_2100_a50_intr_disestablish(acv, cookie)
    241 	void *acv, *cookie;
    242 {
    243 #if 0
    244 	struct apecs_config *acp = acv;
    245 #endif
    246 
    247 	sio_intr_disestablish(NULL /*XXX*/, cookie);
    248 }
    249