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