pci_2100_a50.c revision 1.15 1 /* $NetBSD: pci_2100_a50.c,v 1.15 1997/05/31 05:46:06 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.15 1997/05/31 05:46:06 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 #ifndef DIAGNOSTIC
112 pirq = 0; /* XXX gcc -Wuninitialized */
113 #endif
114
115 if (buspin == 0) {
116 /* No IRQ used. */
117 return 1;
118 }
119 if (buspin > 4) {
120 printf("dec_2100_a50_intr_map: bad interrupt pin %d\n",
121 buspin);
122 return 1;
123 }
124
125 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 case 14: /* slot 3 */
134 switch (buspin) {
135 case PCI_INTERRUPT_PIN_A:
136 case PCI_INTERRUPT_PIN_D:
137 pirq = 0;
138 break;
139 case PCI_INTERRUPT_PIN_B:
140 pirq = 2;
141 break;
142 case PCI_INTERRUPT_PIN_C:
143 pirq = 1;
144 break;
145 #ifdef DIAGNOSTIC
146 default: /* XXX gcc -Wuninitialized */
147 panic("dec_2100_a50_intr_map bogus PCI pin %d\n",
148 buspin);
149 #endif
150 };
151 break;
152
153 case 12: /* slot 2 */
154 switch (buspin) {
155 case PCI_INTERRUPT_PIN_A:
156 case PCI_INTERRUPT_PIN_D:
157 pirq = 1;
158 break;
159 case PCI_INTERRUPT_PIN_B:
160 pirq = 0;
161 break;
162 case PCI_INTERRUPT_PIN_C:
163 pirq = 2;
164 break;
165 #ifdef DIAGNOSTIC
166 default: /* XXX gcc -Wuninitialized */
167 panic("dec_2100_a50_intr_map bogus PCI pin %d\n",
168 buspin);
169 #endif
170 };
171 break;
172
173 case 13: /* slot 3 */
174 switch (buspin) {
175 case PCI_INTERRUPT_PIN_A:
176 case PCI_INTERRUPT_PIN_D:
177 pirq = 2;
178 break;
179 case PCI_INTERRUPT_PIN_B:
180 pirq = 1;
181 break;
182 case PCI_INTERRUPT_PIN_C:
183 pirq = 0;
184 break;
185 #ifdef DIAGNOSTIC
186 default: /* XXX gcc -Wuninitialized */
187 panic("dec_2100_a50_intr_map bogus PCI pin %d\n",
188 buspin);
189 #endif
190 };
191 break;
192
193 default:
194 printf("dec_2100_a50_intr_map: weird device number %d\n",
195 device);
196 return 1;
197 }
198
199 pirqreg = pci_conf_read(pc, pci_make_tag(pc, 0, APECS_SIO_DEVICE, 0),
200 SIO_PCIREG_PIRQ_RTCTRL);
201 #if 0
202 printf("pci_2100_a50_map_int: device %d pin %c: pirq %d, reg = %x\n",
203 device, '@' + buspin, pirq, pirqreg);
204 #endif
205 pirqline = (pirqreg >> (pirq * 8)) & 0xff;
206 if ((pirqline & 0x80) != 0)
207 return 1;
208 pirqline &= 0xf;
209
210 #if 0
211 printf("pci_2100_a50_map_int: device %d pin %c: mapped to line %d\n",
212 device, '@' + buspin, pirqline);
213 #endif
214
215 *ihp = pirqline;
216 return (0);
217 }
218
219 const char *
220 dec_2100_a50_intr_string(acv, ih)
221 void *acv;
222 pci_intr_handle_t ih;
223 {
224 #if 0
225 struct apecs_config *acp = acv;
226 #endif
227
228 return sio_intr_string(NULL /*XXX*/, ih);
229 }
230
231 void *
232 dec_2100_a50_intr_establish(acv, ih, level, func, arg)
233 void *acv, *arg;
234 pci_intr_handle_t ih;
235 int level;
236 int (*func) __P((void *));
237 {
238 #if 0
239 struct apecs_config *acp = acv;
240 #endif
241
242 return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
243 arg);
244 }
245
246 void
247 dec_2100_a50_intr_disestablish(acv, cookie)
248 void *acv, *cookie;
249 {
250 #if 0
251 struct apecs_config *acp = acv;
252 #endif
253
254 sio_intr_disestablish(NULL /*XXX*/, cookie);
255 }
256