pci_axppci_33.c revision 1.9 1 /* $NetBSD: pci_axppci_33.c,v 1.9 1996/10/23 04:12:27 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 <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/time.h>
33 #include <sys/systm.h>
34 #include <sys/errno.h>
35 #include <sys/device.h>
36 #include <vm/vm.h>
37
38 #include <machine/autoconf.h>
39 #include <machine/bus.h>
40 #include <machine/intr.h>
41
42 #include <dev/isa/isavar.h>
43 #include <dev/pci/pcireg.h>
44 #include <dev/pci/pcivar.h>
45
46 #include <alpha/pci/lcavar.h>
47
48 #include <alpha/pci/pci_axppci_33.h>
49 #include <alpha/pci/siovar.h>
50 #include <alpha/pci/sioreg.h>
51
52 #include "sio.h"
53
54 int dec_axppci_33_intr_map __P((void *, pcitag_t, int, int,
55 pci_intr_handle_t *));
56 const char *dec_axppci_33_intr_string __P((void *, pci_intr_handle_t));
57 void *dec_axppci_33_intr_establish __P((void *, pci_intr_handle_t,
58 int, int (*func)(void *), void *));
59 void dec_axppci_33_intr_disestablish __P((void *, void *));
60
61 #define LCA_SIO_DEVICE 7 /* XXX */
62
63 void
64 pci_axppci_33_pickintr(lcp)
65 struct lca_config *lcp;
66 {
67 bus_space_tag_t iot = lcp->lc_iot;
68 pci_chipset_tag_t pc = &lcp->lc_pc;
69 pcireg_t sioclass;
70 int sioII;
71
72 /* XXX MAGIC NUMBER */
73 sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0),
74 PCI_CLASS_REG);
75 sioII = (sioclass & 0xff) >= 3;
76
77 if (!sioII)
78 printf("WARNING: SIO NOT SIO II... NO BETS...\n");
79
80 pc->pc_intr_v = lcp;
81 pc->pc_intr_map = dec_axppci_33_intr_map;
82 pc->pc_intr_string = dec_axppci_33_intr_string;
83 pc->pc_intr_establish = dec_axppci_33_intr_establish;
84 pc->pc_intr_disestablish = dec_axppci_33_intr_disestablish;
85
86 #if NSIO
87 sio_intr_setup(iot);
88 set_iointr(&sio_iointr);
89 #else
90 panic("pci_axppci_33_pickintr: no I/O interrupt handler (no sio)");
91 #endif
92 }
93
94 int
95 dec_axppci_33_intr_map(lcv, bustag, buspin, line, ihp)
96 void *lcv;
97 pcitag_t bustag;
98 int buspin, line;
99 pci_intr_handle_t *ihp;
100 {
101 struct lca_config *lcp = lcv;
102 pci_chipset_tag_t pc = &lcp->lc_pc;
103 int device, pirq;
104 pcireg_t pirqreg;
105 u_int8_t pirqline;
106
107 if (buspin == 0) {
108 /* No IRQ used. */
109 return 1;
110 }
111 if (buspin > 4) {
112 printf("pci_map_int: bad interrupt pin %d\n", buspin);
113 return 1;
114 }
115
116 pci_decompose_tag(pc, bustag, NULL, &device, NULL);
117
118 switch (device) {
119 case 6: /* NCR SCSI */
120 pirq = 3;
121 break;
122
123 case 11: /* slot 1 */
124 switch (buspin) {
125 case PCI_INTERRUPT_PIN_A:
126 case PCI_INTERRUPT_PIN_D:
127 pirq = 0;
128 break;
129 case PCI_INTERRUPT_PIN_B:
130 pirq = 2;
131 break;
132 case PCI_INTERRUPT_PIN_C:
133 pirq = 1;
134 break;
135 };
136 break;
137
138 case 12: /* slot 2 */
139 switch (buspin) {
140 case PCI_INTERRUPT_PIN_A:
141 case PCI_INTERRUPT_PIN_D:
142 pirq = 1;
143 break;
144 case PCI_INTERRUPT_PIN_B:
145 pirq = 0;
146 break;
147 case PCI_INTERRUPT_PIN_C:
148 pirq = 2;
149 break;
150 };
151 break;
152
153 case 8: /* slot 3 */
154 switch (buspin) {
155 case PCI_INTERRUPT_PIN_A:
156 case PCI_INTERRUPT_PIN_D:
157 pirq = 2;
158 break;
159 case PCI_INTERRUPT_PIN_B:
160 pirq = 1;
161 break;
162 case PCI_INTERRUPT_PIN_C:
163 pirq = 0;
164 break;
165 };
166 break;
167 default:
168 printf("dec_axppci_33_pci_map_int: unknown device %d\n",
169 device);
170 panic("dec_axppci_33_pci_map_int: bad device number");
171 }
172
173 pirqreg = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0),
174 SIO_PCIREG_PIRQ_RTCTRL);
175 #if 0
176 printf("pci_axppci_33_map_int: device %d pin %c: pirq %d, reg = %x\n",
177 device, '@' + buspin, pirq, pirqreg);
178 #endif
179 pirqline = (pirqreg >> (pirq * 8)) & 0xff;
180 if ((pirqline & 0x80) != 0)
181 return 1; /* not routed? */
182 pirqline &= 0xf;
183
184 #if 0
185 printf("pci_axppci_33_map_int: device %d pin %c: mapped to line %d\n",
186 device, '@' + buspin, pirqline);
187 #endif
188
189 *ihp = pirqline;
190 return (0);
191 }
192
193 const char *
194 dec_axppci_33_intr_string(lcv, ih)
195 void *lcv;
196 pci_intr_handle_t ih;
197 {
198 struct lca_config *lcp = lcv;
199
200 return sio_intr_string(NULL /*XXX*/, ih);
201 }
202
203 void *
204 dec_axppci_33_intr_establish(lcv, ih, level, func, arg)
205 void *lcv, *arg;
206 pci_intr_handle_t ih;
207 int level;
208 int (*func) __P((void *));
209 {
210 struct lca_config *lcp = lcv;
211
212 return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
213 arg);
214 }
215
216 void
217 dec_axppci_33_intr_disestablish(lcv, cookie)
218 void *lcv, *cookie;
219 {
220 struct lca_config *lcp = lcv;
221
222 sio_intr_disestablish(NULL /*XXX*/, cookie);
223 }
224