pci_up1000.c revision 1.18
1/*	$OpenBSD: pci_up1000.c,v 1.18 2017/09/08 05:36:51 deraadt 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 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/param.h>
34#include <sys/time.h>
35#include <sys/systm.h>
36#include <sys/errno.h>
37#include <sys/device.h>
38
39#include <uvm/uvm_extern.h>
40
41#include <machine/autoconf.h>
42#include <machine/bus.h>
43#include <machine/intr.h>
44
45#include <dev/isa/isavar.h>
46
47#include <dev/pci/pcireg.h>
48#include <dev/pci/pcivar.h>
49#include <dev/pci/ppbreg.h>
50#include <dev/pci/pciidereg.h>
51#include <dev/pci/pciidevar.h>
52
53#include <alpha/pci/irongatevar.h>
54
55#include <alpha/pci/pci_up1000.h>
56#include <alpha/pci/siovar.h>
57
58#include "sio.h"
59
60int     api_up1000_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
61const char *api_up1000_intr_string(void *, pci_intr_handle_t);
62int	api_up1000_intr_line(void *, pci_intr_handle_t);
63void    *api_up1000_intr_establish(void *, pci_intr_handle_t,
64	    int, int (*func)(void *), void *, const char *);
65void    api_up1000_intr_disestablish(void *, void *);
66
67void	*api_up1000_pciide_compat_intr_establish(void *, struct device *,
68	    struct pci_attach_args *, int, int (*)(void *), void *);
69void    api_up1000_pciide_compat_intr_disestablish(void *, void *);
70
71void
72pci_up1000_pickintr(struct irongate_config *icp)
73{
74	bus_space_tag_t iot = &icp->ic_iot;
75	pci_chipset_tag_t pc = &icp->ic_pc;
76
77	pc->pc_intr_v = icp;
78	pc->pc_intr_map = api_up1000_intr_map;
79	pc->pc_intr_string = api_up1000_intr_string;
80	pc->pc_intr_line = api_up1000_intr_line;
81	pc->pc_intr_establish = api_up1000_intr_establish;
82	pc->pc_intr_disestablish = api_up1000_intr_disestablish;
83
84	pc->pc_pciide_compat_intr_establish =
85	    api_up1000_pciide_compat_intr_establish;
86	pc->pc_pciide_compat_intr_disestablish =
87	    api_up1000_pciide_compat_intr_disestablish;
88
89#if NSIO
90	sio_intr_setup(pc, iot);
91#else
92	panic("pci_up1000_pickintr: no I/O interrupt handler (no sio)");
93#endif
94}
95
96int
97api_up1000_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
98{
99	int buspin, line = pa->pa_intrline;
100
101	/*
102	 * The console places the interrupt mapping in the "line" value.
103	 * We trust it whenever possible.
104	 */
105	if (line >= 0 && line <= 15) {
106		if (line == 2) {
107#ifdef DEBUG
108			printf("api_up1000_intr_map: changed IRQ 2 to IRQ 9\n");
109#endif
110			line = 9;
111		}
112
113		*ihp = line;
114		return 0;
115	}
116
117	if (pa->pa_bridgetag) {
118		buspin = PPB_INTERRUPT_SWIZZLE(pa->pa_rawintrpin,
119		    pa->pa_device);
120		if (pa->pa_bridgeih[buspin - 1] != 0) {
121			*ihp = pa->pa_bridgeih[buspin - 1];
122			return 0;
123		}
124	}
125
126	return 1;
127}
128
129const char *
130api_up1000_intr_string(void *icv, pci_intr_handle_t ih)
131{
132#if 0
133	struct irongate_config *icp = icv;
134#endif
135
136	return sio_intr_string(NULL /*XXX*/, ih);
137}
138
139int
140api_up1000_intr_line(void *icv, pci_intr_handle_t ih)
141{
142	return sio_intr_line(NULL /*XXX*/, ih);
143}
144
145void *
146api_up1000_intr_establish(void *icv, pci_intr_handle_t ih, int level,
147    int (*func)(void *), void *arg, const char *name)
148{
149#if 0
150	struct irongate_config *icp = icv;
151#endif
152
153	return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
154	    arg, name);
155}
156
157void
158api_up1000_intr_disestablish(void *icv, void *cookie)
159{
160#if 0
161	struct irongate_config *icp = icv;
162#endif
163
164	sio_intr_disestablish(NULL /*XXX*/, cookie);
165}
166
167void *
168api_up1000_pciide_compat_intr_establish(void *icv, struct device *dev,
169    struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
170{
171	pci_chipset_tag_t pc = pa->pa_pc;
172	void *cookie = NULL;
173	int bus, irq;
174
175	pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
176
177	/*
178	 * If this isn't PCI bus #0, all bets are off.
179	 */
180	if (bus != 0)
181		return (NULL);
182
183	irq = PCIIDE_COMPAT_IRQ(chan);
184#if NSIO
185	cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO,
186	    func, arg, dev->dv_xname);
187	if (cookie == NULL)
188		return (NULL);
189#endif
190	return (cookie);
191}
192
193void
194api_up1000_pciide_compat_intr_disestablish(void *v, void *cookie)
195{
196	sio_intr_disestablish(NULL, cookie);
197}
198