pci_up1000.c revision 1.6.4.2 1 /* $NetBSD: pci_up1000.c,v 1.6.4.2 2002/06/23 17:34:15 jdolecek Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
40
41 __KERNEL_RCSID(0, "$NetBSD: pci_up1000.c,v 1.6.4.2 2002/06/23 17:34:15 jdolecek Exp $");
42
43 #include <sys/types.h>
44 #include <sys/param.h>
45 #include <sys/time.h>
46 #include <sys/systm.h>
47 #include <sys/errno.h>
48 #include <sys/device.h>
49
50 #include <uvm/uvm_extern.h>
51
52 #include <machine/autoconf.h>
53 #include <machine/bus.h>
54 #include <machine/intr.h>
55
56 #include <dev/isa/isavar.h>
57
58 #include <dev/pci/pcireg.h>
59 #include <dev/pci/pcivar.h>
60 #include <dev/pci/pciidereg.h>
61 #include <dev/pci/pciidevar.h>
62
63 #include <alpha/pci/irongatevar.h>
64
65 #include <alpha/pci/pci_up1000.h>
66 #include <alpha/pci/siovar.h>
67 #include <alpha/pci/sioreg.h>
68
69 #include "sio.h"
70
71 int api_up1000_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
72 const char *api_up1000_intr_string(void *, pci_intr_handle_t);
73 const struct evcnt *api_up1000_intr_evcnt(void *, pci_intr_handle_t);
74 void *api_up1000_intr_establish(void *, pci_intr_handle_t,
75 int, int (*func)(void *), void *);
76 void api_up1000_intr_disestablish(void *, void *);
77
78 void *api_up1000_pciide_compat_intr_establish(void *, struct device *,
79 struct pci_attach_args *, int, int (*)(void *), void *);
80
81 void
82 pci_up1000_pickintr(struct irongate_config *icp)
83 {
84 bus_space_tag_t iot = &icp->ic_iot;
85 pci_chipset_tag_t pc = &icp->ic_pc;
86
87 pc->pc_intr_v = icp;
88 pc->pc_intr_map = api_up1000_intr_map;
89 pc->pc_intr_string = api_up1000_intr_string;
90 pc->pc_intr_evcnt = api_up1000_intr_evcnt;
91 pc->pc_intr_establish = api_up1000_intr_establish;
92 pc->pc_intr_disestablish = api_up1000_intr_disestablish;
93
94 pc->pc_pciide_compat_intr_establish =
95 api_up1000_pciide_compat_intr_establish;
96
97 #if NSIO
98 sio_intr_setup(pc, iot);
99 #else
100 panic("pci_up1000_pickintr: no I/O interrupt handler (no sio)");
101 #endif
102 }
103
104 int
105 api_up1000_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
106 {
107 pci_chipset_tag_t pc = pa->pa_pc;
108 int buspin = pa->pa_intrpin;
109 int bustag = pa->pa_intrtag;
110 int line = pa->pa_intrline;
111 int bus, device, function;
112
113 if (buspin == 0) {
114 /* No IRQ used. */
115 return 1;
116 }
117 if (buspin > 4) {
118 printf("api_up1000_intr_map: bad interrupt pin %d\n",
119 buspin);
120 return 1;
121 }
122
123 pci_decompose_tag(pc, bustag, &bus, &device, &function);
124
125 /*
126 * The console places the interrupt mapping in the "line" value.
127 * A value of (char)-1 indicates there is no mapping.
128 */
129 if (line == 0xff) {
130 printf("api_up1000_intr_map: no mapping for %d/%d/%d\n",
131 bus, device, function);
132 return (1);
133 }
134
135 /* XXX Check for 0? */
136 if (line > 15) {
137 printf("api_up1000_intr_map: ISA IRQ too large (%d)\n",
138 line);
139 return (1);
140 }
141 if (line == 2) {
142 printf("api_up1000_intr_map: changed IRQ 2 to IRQ 9\n");
143 line = 9;
144 }
145
146 *ihp = line;
147 return (0);
148 }
149
150 const char *
151 api_up1000_intr_string(void *icv, pci_intr_handle_t ih)
152 {
153 #if 0
154 struct irongate_config *icp = icv;
155 #endif
156
157 return sio_intr_string(NULL /*XXX*/, ih);
158 }
159
160 const struct evcnt *
161 api_up1000_intr_evcnt(void *icv, pci_intr_handle_t ih)
162 {
163 #if 0
164 struct irongate_config *icp = icv;
165 #endif
166
167 return sio_intr_evcnt(NULL /*XXX*/, ih);
168 }
169
170 void *
171 api_up1000_intr_establish(void *icv, pci_intr_handle_t ih, int level,
172 int (*func)(void *), void *arg)
173 {
174 #if 0
175 struct irongate_config *icp = icv;
176 #endif
177
178 return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
179 arg);
180 }
181
182 void
183 api_up1000_intr_disestablish(void *icv, void *cookie)
184 {
185 #if 0
186 struct irongate_config *icp = icv;
187 #endif
188
189 sio_intr_disestablish(NULL /*XXX*/, cookie);
190 }
191
192 void *
193 api_up1000_pciide_compat_intr_establish(void *icv, struct device *dev,
194 struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
195 {
196 pci_chipset_tag_t pc = pa->pa_pc;
197 void *cookie = NULL;
198 int bus, irq;
199
200 pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
201
202 /*
203 * If this isn't PCI bus #0, all bets are off.
204 */
205 if (bus != 0)
206 return (NULL);
207
208 irq = PCIIDE_COMPAT_IRQ(chan);
209 #if NSIO
210 cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO,
211 func, arg);
212 if (cookie == NULL)
213 return (NULL);
214 printf("%s: %s channel interrupting at %s\n", dev->dv_xname,
215 PCIIDE_CHANNEL_NAME(chan), sio_intr_string(NULL /*XXX*/, irq));
216 #endif
217 return (cookie);
218 }
219