pci_up1000.c revision 1.3 1 /* $NetBSD: pci_up1000.c,v 1.3 2000/06/05 21:47:28 thorpej 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.3 2000/06/05 21:47:28 thorpej 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 #include <vm/vm.h>
50
51 #include <machine/autoconf.h>
52 #include <machine/bus.h>
53 #include <machine/intr.h>
54
55 #include <dev/isa/isavar.h>
56
57 #include <dev/pci/pcireg.h>
58 #include <dev/pci/pcivar.h>
59 #include <dev/pci/pciidereg.h>
60 #include <dev/pci/pciidevar.h>
61
62 #include <alpha/pci/irongatevar.h>
63
64 #include <alpha/pci/pci_up1000.h>
65 #include <alpha/pci/siovar.h>
66 #include <alpha/pci/sioreg.h>
67
68 #include "sio.h"
69
70 int api_up1000_intr_map(void *, pcitag_t, int, int, pci_intr_handle_t *);
71 const char *api_up1000_intr_string(void *, pci_intr_handle_t);
72 const struct evcnt *api_up1000_intr_evcnt(void *, pci_intr_handle_t);
73 void *api_up1000_intr_establish(void *, pci_intr_handle_t,
74 int, int (*func)(void *), void *);
75 void api_up1000_intr_disestablish(void *, void *);
76
77 void *api_up1000_pciide_compat_intr_establish(void *, struct device *,
78 struct pci_attach_args *, int, int (*)(void *), void *);
79
80 void
81 pci_up1000_pickintr(struct irongate_config *icp)
82 {
83 bus_space_tag_t iot = &icp->ic_iot;
84 pci_chipset_tag_t pc = &icp->ic_pc;
85
86 pc->pc_intr_v = icp;
87 pc->pc_intr_map = api_up1000_intr_map;
88 pc->pc_intr_string = api_up1000_intr_string;
89 pc->pc_intr_evcnt = api_up1000_intr_evcnt;
90 pc->pc_intr_establish = api_up1000_intr_establish;
91 pc->pc_intr_disestablish = api_up1000_intr_disestablish;
92
93 pc->pc_pciide_compat_intr_establish =
94 api_up1000_pciide_compat_intr_establish;
95
96 #if NSIO
97 sio_intr_setup(pc, iot);
98 set_iointr(&sio_iointr);
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(void *icv, pcitag_t bustag, int buspin, int line,
106 pci_intr_handle_t *ihp)
107 {
108 struct irongate_config *icp = icv;
109 pci_chipset_tag_t pc = &icp->ic_pc;
110 int bus, device, function;
111
112 if (buspin == 0) {
113 /* No IRQ used. */
114 return 1;
115 }
116 if (buspin > 4) {
117 printf("api_up1000_intr_map: bad interrupt pin %d\n",
118 buspin);
119 return 1;
120 }
121
122 alpha_pci_decompose_tag(pc, bustag, &bus, &device, &function);
123
124 /*
125 * The console places the interrupt mapping in the "line" value.
126 * A value of (char)-1 indicates there is no mapping.
127 */
128 if (line == 0xff) {
129 printf("api_up1000_intr_map: no mapping for %d/%d/%d\n",
130 bus, device, function);
131 return (1);
132 }
133
134 /* XXX Check for 0? */
135 if (line > 15) {
136 printf("api_up1000_intr_map: ISA IRQ too large (%d)\n",
137 line);
138 return (1);
139 }
140 if (line == 2) {
141 printf("api_up1000_intr_map: changed IRQ 2 to IRQ 9\n");
142 line = 9;
143 }
144
145 *ihp = line;
146 return (0);
147 }
148
149 const char *
150 api_up1000_intr_string(void *icv, pci_intr_handle_t ih)
151 {
152 #if 0
153 struct irongate_config *icp = icv;
154 #endif
155
156 return sio_intr_string(NULL /*XXX*/, ih);
157 }
158
159 const struct evcnt *
160 api_up1000_intr_evcnt(void *icv, pci_intr_handle_t ih)
161 {
162 #if 0
163 struct irongate_config *icp = icv;
164 #endif
165
166 return sio_intr_evcnt(NULL /*XXX*/, ih);
167 }
168
169 void *
170 api_up1000_intr_establish(void *icv, pci_intr_handle_t ih, int level,
171 int (*func)(void *), void *arg)
172 {
173 #if 0
174 struct irongate_config *icp = icv;
175 #endif
176
177 return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
178 arg);
179 }
180
181 void
182 api_up1000_intr_disestablish(void *icv, void *cookie)
183 {
184 #if 0
185 struct irongate_config *icp = icv;
186 #endif
187
188 sio_intr_disestablish(NULL /*XXX*/, cookie);
189 }
190
191 void *
192 api_up1000_pciide_compat_intr_establish(void *icv, struct device *dev,
193 struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
194 {
195 pci_chipset_tag_t pc = pa->pa_pc;
196 void *cookie = NULL;
197 int bus, irq;
198
199 alpha_pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
200
201 /*
202 * If this isn't PCI bus #0, all bets are off.
203 */
204 if (bus != 0)
205 return (NULL);
206
207 irq = PCIIDE_COMPAT_IRQ(chan);
208 #if NSIO
209 cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO,
210 func, arg);
211 #endif
212 return (cookie);
213 }
214