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