pci_axppci_33.c revision 1.11 1 /* $NetBSD: pci_axppci_33.c,v 1.11 1997/04/07 02:01:21 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> /* 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/lcavar.h>
49
50 #include <alpha/pci/pci_axppci_33.h>
51 #include <alpha/pci/siovar.h>
52 #include <alpha/pci/sioreg.h>
53
54 #include "sio.h"
55
56 int dec_axppci_33_intr_map __P((void *, pcitag_t, int, int,
57 pci_intr_handle_t *));
58 const char *dec_axppci_33_intr_string __P((void *, pci_intr_handle_t));
59 void *dec_axppci_33_intr_establish __P((void *, pci_intr_handle_t,
60 int, int (*func)(void *), void *));
61 void dec_axppci_33_intr_disestablish __P((void *, void *));
62
63 #define LCA_SIO_DEVICE 7 /* XXX */
64
65 void
66 pci_axppci_33_pickintr(lcp)
67 struct lca_config *lcp;
68 {
69 bus_space_tag_t iot = lcp->lc_iot;
70 pci_chipset_tag_t pc = &lcp->lc_pc;
71 pcireg_t sioclass;
72 int sioII;
73
74 /* XXX MAGIC NUMBER */
75 sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0),
76 PCI_CLASS_REG);
77 sioII = (sioclass & 0xff) >= 3;
78
79 if (!sioII)
80 printf("WARNING: SIO NOT SIO II... NO BETS...\n");
81
82 pc->pc_intr_v = lcp;
83 pc->pc_intr_map = dec_axppci_33_intr_map;
84 pc->pc_intr_string = dec_axppci_33_intr_string;
85 pc->pc_intr_establish = dec_axppci_33_intr_establish;
86 pc->pc_intr_disestablish = dec_axppci_33_intr_disestablish;
87
88 #if NSIO
89 sio_intr_setup(iot);
90 set_iointr(&sio_iointr);
91 #else
92 panic("pci_axppci_33_pickintr: no I/O interrupt handler (no sio)");
93 #endif
94 }
95
96 int
97 dec_axppci_33_intr_map(lcv, bustag, buspin, line, ihp)
98 void *lcv;
99 pcitag_t bustag;
100 int buspin, line;
101 pci_intr_handle_t *ihp;
102 {
103 struct lca_config *lcp = lcv;
104 pci_chipset_tag_t pc = &lcp->lc_pc;
105 int device, pirq;
106 pcireg_t pirqreg;
107 u_int8_t pirqline;
108
109 if (buspin == 0) {
110 /* No IRQ used. */
111 return 1;
112 }
113 if (buspin > 4) {
114 printf("pci_map_int: bad interrupt pin %d\n", 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 switch (buspin) {
127 case PCI_INTERRUPT_PIN_A:
128 case PCI_INTERRUPT_PIN_D:
129 pirq = 0;
130 break;
131 case PCI_INTERRUPT_PIN_B:
132 pirq = 2;
133 break;
134 case PCI_INTERRUPT_PIN_C:
135 pirq = 1;
136 break;
137 #ifdef DIAGNOSTIC
138 default: /* XXX gcc -Wuninitialized */
139 panic("dec_axppci_33_intr_map bogus PCI pin %d\n",
140 buspin);
141 #endif
142 };
143 break;
144
145 case 12: /* slot 2 */
146 switch (buspin) {
147 case PCI_INTERRUPT_PIN_A:
148 case PCI_INTERRUPT_PIN_D:
149 pirq = 1;
150 break;
151 case PCI_INTERRUPT_PIN_B:
152 pirq = 0;
153 break;
154 case PCI_INTERRUPT_PIN_C:
155 pirq = 2;
156 break;
157 #ifdef DIAGNOSTIC
158 default: /* XXX gcc -Wuninitialized */
159 panic("dec_axppci_33_intr_map bogus PCI pin %d\n",
160 buspin);
161 #endif
162 };
163 break;
164
165 case 8: /* slot 3 */
166 switch (buspin) {
167 case PCI_INTERRUPT_PIN_A:
168 case PCI_INTERRUPT_PIN_D:
169 pirq = 2;
170 break;
171 case PCI_INTERRUPT_PIN_B:
172 pirq = 1;
173 break;
174 case PCI_INTERRUPT_PIN_C:
175 pirq = 0;
176 break;
177 #ifdef DIAGNOSTIC
178 default: /* XXX gcc -Wuninitialized */
179 panic("dec_axppci_33_intr_map bogus PCI pin %d\n",
180 buspin);
181 #endif
182 };
183 break;
184
185 default:
186 printf("dec_axppci_33_intr_map: weird device number %d\n",
187 device);
188 return 1;
189 }
190
191 pirqreg = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0),
192 SIO_PCIREG_PIRQ_RTCTRL);
193 #if 0
194 printf("pci_axppci_33_map_int: device %d pin %c: pirq %d, reg = %x\n",
195 device, '@' + buspin, pirq, pirqreg);
196 #endif
197 pirqline = (pirqreg >> (pirq * 8)) & 0xff;
198 if ((pirqline & 0x80) != 0)
199 return 1; /* not routed? */
200 pirqline &= 0xf;
201
202 #if 0
203 printf("pci_axppci_33_map_int: device %d pin %c: mapped to line %d\n",
204 device, '@' + buspin, pirqline);
205 #endif
206
207 *ihp = pirqline;
208 return (0);
209 }
210
211 const char *
212 dec_axppci_33_intr_string(lcv, ih)
213 void *lcv;
214 pci_intr_handle_t ih;
215 {
216 #if 0
217 struct lca_config *lcp = lcv;
218 #endif
219
220 return sio_intr_string(NULL /*XXX*/, ih);
221 }
222
223 void *
224 dec_axppci_33_intr_establish(lcv, ih, level, func, arg)
225 void *lcv, *arg;
226 pci_intr_handle_t ih;
227 int level;
228 int (*func) __P((void *));
229 {
230 #if 0
231 struct lca_config *lcp = lcv;
232 #endif
233
234 return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
235 arg);
236 }
237
238 void
239 dec_axppci_33_intr_disestablish(lcv, cookie)
240 void *lcv, *cookie;
241 {
242 #if 0
243 struct lca_config *lcp = lcv;
244 #endif
245
246 sio_intr_disestablish(NULL /*XXX*/, cookie);
247 }
248