pci_up1000.c revision 1.7
1121461Sharti/*	$OpenBSD: pci_up1000.c,v 1.7 2001/12/14 00:44:59 nate Exp $	*/
2121461Sharti/* $NetBSD: pci_up1000.c,v 1.6 2000/12/28 22:59:07 sommerfeld Exp $ */
3121461Sharti
4121461Sharti/*-
5121461Sharti * Copyright (c) 2000 The NetBSD Foundation, Inc.
6121461Sharti * All rights reserved.
7121461Sharti *
8121461Sharti * This code is derived from software contributed to The NetBSD Foundation
9121461Sharti * by Jason R. Thorpe.
10121461Sharti *
11121461Sharti * Redistribution and use in source and binary forms, with or without
12121461Sharti * modification, are permitted provided that the following conditions
13121461Sharti * are met:
14121461Sharti * 1. Redistributions of source code must retain the above copyright
15121461Sharti *    notice, this list of conditions and the following disclaimer.
16121461Sharti * 2. Redistributions in binary form must reproduce the above copyright
17121461Sharti *    notice, this list of conditions and the following disclaimer in the
18121461Sharti *    documentation and/or other materials provided with the distribution.
19121461Sharti * 3. All advertising materials mentioning features or use of this software
20121461Sharti *    must display the following acknowledgement:
21121461Sharti *	This product includes software developed by the NetBSD
22121461Sharti *	Foundation, Inc. and its contributors.
23121461Sharti * 4. Neither the name of The NetBSD Foundation nor the names of its
24121461Sharti *    contributors may be used to endorse or promote products derived
25121461Sharti *    from this software without specific prior written permission.
26121461Sharti *
27121461Sharti * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28121461Sharti * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29121461Sharti * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30121461Sharti * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31121461Sharti * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32121461Sharti * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33121461Sharti * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34121461Sharti * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35121461Sharti * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36121461Sharti * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37121461Sharti * POSSIBILITY OF SUCH DAMAGE.
38121461Sharti */
39121461Sharti
40121461Sharti#include <sys/types.h>
41121461Sharti#include <sys/param.h>
42121461Sharti#include <sys/time.h>
43121461Sharti#include <sys/systm.h>
44121461Sharti#include <sys/errno.h>
45121461Sharti#include <sys/device.h>
46121461Sharti
47121461Sharti#include <uvm/uvm_extern.h>
48121461Sharti
49121461Sharti#include <machine/autoconf.h>
50121461Sharti#include <machine/bus.h>
51121461Sharti#include <machine/intr.h>
52121461Sharti
53121461Sharti#include <dev/isa/isavar.h>
54121461Sharti
55121461Sharti#include <dev/pci/pcireg.h>
56121461Sharti#include <dev/pci/pcivar.h>
57121461Sharti#include <dev/pci/pciidereg.h>
58121461Sharti#include <dev/pci/pciidevar.h>
59121461Sharti
60121461Sharti#include <alpha/pci/irongatevar.h>
61121461Sharti
62121461Sharti#include <alpha/pci/pci_up1000.h>
63121461Sharti#include <alpha/pci/siovar.h>
64121461Sharti#include <alpha/pci/sioreg.h>
65121461Sharti
66121461Sharti#include "sio.h"
67121461Sharti
68121461Shartiint     api_up1000_intr_map(void *, pcitag_t, int, int, pci_intr_handle_t *);
69121461Sharticonst char *api_up1000_intr_string(void *, pci_intr_handle_t);
70121461Shartiint	api_up1000_intr_line(void *, pci_intr_handle_t);
71121461Sharticonst struct evcnt *api_up1000_intr_evcnt(void *, pci_intr_handle_t);
72121461Shartivoid    *api_up1000_intr_establish(void *, pci_intr_handle_t,
73121461Sharti	    int, int (*func)(void *), void *, char *);
74121461Shartivoid    api_up1000_intr_disestablish(void *, void *);
75121461Sharti
76121461Shartivoid	*api_up1000_pciide_compat_intr_establish(void *, struct device *,
77121461Sharti	    struct pci_attach_args *, int, int (*)(void *), void *);
78121461Shartivoid    api_up1000_pciide_compat_intr_disestablish(void *, void *);
79121461Sharti
80121461Shartivoid
81121461Shartipci_up1000_pickintr(struct irongate_config *icp)
82121461Sharti{
83121461Sharti	bus_space_tag_t iot = &icp->ic_iot;
84121461Sharti	pci_chipset_tag_t pc = &icp->ic_pc;
85121461Sharti
86121461Sharti	pc->pc_intr_v = icp;
87121461Sharti	pc->pc_intr_map = api_up1000_intr_map;
88121461Sharti	pc->pc_intr_string = api_up1000_intr_string;
89121461Sharti	pc->pc_intr_line = api_up1000_intr_line;
90121461Sharti#if 0
91121461Sharti	pc->pc_intr_evcnt = api_up1000_intr_evcnt;
92121461Sharti#endif
93121461Sharti	pc->pc_intr_establish = api_up1000_intr_establish;
94121461Sharti	pc->pc_intr_disestablish = api_up1000_intr_disestablish;
95121461Sharti
96121461Sharti	pc->pc_pciide_compat_intr_establish =
97121461Sharti	    api_up1000_pciide_compat_intr_establish;
98121461Sharti	pc->pc_pciide_compat_intr_disestablish =
99121461Sharti	    api_up1000_pciide_compat_intr_disestablish;
100121461Sharti
101121461Sharti#if NSIO
102121461Sharti	sio_intr_setup(pc, iot);
103121461Sharti	set_iointr(&sio_iointr);
104121461Sharti#else
105121461Sharti	panic("pci_up1000_pickintr: no I/O interrupt handler (no sio)");
106121461Sharti#endif
107121461Sharti}
108137199Sharti
109137199Shartiint
110121461Shartiapi_up1000_intr_map(void *icv, pcitag_t bustag, int buspin, int line, pci_intr_handle_t *ihp)
111137199Sharti{
112121461Sharti	struct irongate_config *icc = icv;
113121461Sharti	pci_chipset_tag_t pc = &icc->ic_pc;
114137199Sharti	int bus, device, function;
115121461Sharti
116121461Sharti	if (buspin == 0) {
117137199Sharti		/* No IRQ used. */
118121461Sharti		return 1;
119121461Sharti	}
120121461Sharti	if (buspin > 4) {
121121461Sharti		printf("api_up1000_intr_map: bad interrupt pin %d\n",
122121461Sharti		    buspin);
123121461Sharti		return 1;
124121461Sharti	}
125121461Sharti
126121461Sharti	alpha_pci_decompose_tag(pc, bustag, &bus, &device, &function);
127121461Sharti
128121461Sharti	/*
129121461Sharti	 * The console places the interrupt mapping in the "line" value.
130121461Sharti	 * A value of (char)-1 indicates there is no mapping.
131121461Sharti	 */
132121461Sharti	if (line == 0xff) {
133121461Sharti		printf("api_up1000_intr_map: no mapping for %d/%d/%d\n",
134121461Sharti		    bus, device, function);
135121461Sharti		return (1);
136121461Sharti	}
137121461Sharti
138121461Sharti	/* XXX Check for 0? */
139121461Sharti	if (line > 15) {
140121461Sharti		printf("api_up1000_intr_map: ISA IRQ too large (%d)\n",
141121461Sharti		    line);
142121461Sharti		return (1);
143121461Sharti	}
144121461Sharti	if (line == 2) {
145121461Sharti		printf("api_up1000_intr_map: changed IRQ 2 to IRQ 9\n");
146121461Sharti		line = 9;
147121461Sharti	}
148121461Sharti
149121461Sharti	*ihp = line;
150121461Sharti	return (0);
151121461Sharti}
152121461Sharti
153121461Sharticonst char *
154121461Shartiapi_up1000_intr_string(void *icv, pci_intr_handle_t ih)
155121461Sharti{
156121461Sharti#if 0
157121461Sharti	struct irongate_config *icp = icv;
158121461Sharti#endif
159121461Sharti
160121461Sharti	return sio_intr_string(NULL /*XXX*/, ih);
161121461Sharti}
162121461Sharti
163121461Shartiint
164121461Shartiapi_up1000_intr_line(void *icv, pci_intr_handle_t ih)
165121461Sharti{
166121461Sharti	return sio_intr_line(NULL /*XXX*/, ih);
167121461Sharti}
168121461Sharti
169121461Sharti#if 0
170121461Sharticonst struct evcnt *
171121461Shartiapi_up1000_intr_evcnt(void *icv, pci_intr_handle_t ih)
172121461Sharti{
173121461Sharti#if 0
174121461Sharti	struct irongate_config *icp = icv;
175121461Sharti#endif
176121461Sharti
177121461Sharti	return sio_intr_evcnt(NULL /*XXX*/, ih);
178121461Sharti}
179121461Sharti#endif
180121461Sharti
181121461Shartivoid *
182121461Shartiapi_up1000_intr_establish(void *icv, pci_intr_handle_t ih, int level,
183121461Sharti    int (*func)(void *), void *arg, char *name)
184121461Sharti{
185121461Sharti#if 0
186121461Sharti	struct irongate_config *icp = icv;
187121461Sharti#endif
188121461Sharti
189121461Sharti	return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
190121461Sharti	    arg, name);
191121461Sharti}
192121461Sharti
193121461Shartivoid
194121461Shartiapi_up1000_intr_disestablish(void *icv, void *cookie)
195121461Sharti{
196121461Sharti#if 0
197121461Sharti	struct irongate_config *icp = icv;
198121461Sharti#endif
199121461Sharti
200121461Sharti	sio_intr_disestablish(NULL /*XXX*/, cookie);
201121461Sharti}
202121461Sharti
203121461Shartivoid *
204121461Shartiapi_up1000_pciide_compat_intr_establish(void *icv, struct device *dev,
205121461Sharti    struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
206121461Sharti{
207121461Sharti	pci_chipset_tag_t pc = pa->pa_pc;
208121461Sharti	void *cookie = NULL;
209121461Sharti	int bus, irq;
210121461Sharti
211121461Sharti	alpha_pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
212121461Sharti
213121461Sharti	/*
214121461Sharti	 * If this isn't PCI bus #0, all bets are off.
215121461Sharti	 */
216121461Sharti	if (bus != 0)
217121461Sharti		return (NULL);
218121461Sharti
219121461Sharti	irq = PCIIDE_COMPAT_IRQ(chan);
220121461Sharti#if NSIO
221121461Sharti	cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO,
222121461Sharti	    func, arg, "up 1000 irq");
223121461Sharti	if (cookie == NULL)
224121461Sharti		return (NULL);
225121461Sharti#endif
226121461Sharti	return (cookie);
227121461Sharti}
228121461Sharti
229121461Shartivoid
230121461Shartiapi_up1000_pciide_compat_intr_disestablish(void *v, void *cookie)
231121461Sharti{
232121461Sharti	sio_intr_disestablish(NULL, cookie);
233121461Sharti}
234121461Sharti