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