Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / alpha / pci / pci_up1000.c
blob69793641128c8b4876e950be73d90ab32ab2cbbe
1 /* $NetBSD: pci_up1000.c,v 1.9 2007/03/04 21:58:16 mrg Exp $ */
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
34 __KERNEL_RCSID(0, "$NetBSD: pci_up1000.c,v 1.9 2007/03/04 21:58:16 mrg Exp $");
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/time.h>
39 #include <sys/systm.h>
40 #include <sys/errno.h>
41 #include <sys/device.h>
43 #include <uvm/uvm_extern.h>
45 #include <machine/autoconf.h>
46 #include <machine/bus.h>
47 #include <machine/intr.h>
49 #include <dev/isa/isavar.h>
51 #include <dev/pci/pcireg.h>
52 #include <dev/pci/pcivar.h>
53 #include <dev/pci/pciidereg.h>
54 #include <dev/pci/pciidevar.h>
56 #include <alpha/pci/irongatevar.h>
58 #include <alpha/pci/pci_up1000.h>
59 #include <alpha/pci/siovar.h>
60 #include <alpha/pci/sioreg.h>
62 #include "sio.h"
64 int api_up1000_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
65 const char *api_up1000_intr_string(void *, pci_intr_handle_t);
66 const struct evcnt *api_up1000_intr_evcnt(void *, pci_intr_handle_t);
67 void *api_up1000_intr_establish(void *, pci_intr_handle_t,
68 int, int (*func)(void *), void *);
69 void api_up1000_intr_disestablish(void *, void *);
71 void *api_up1000_pciide_compat_intr_establish(void *, struct device *,
72 struct pci_attach_args *, int, int (*)(void *), void *);
74 void
75 pci_up1000_pickintr(struct irongate_config *icp)
77 #if NSIO
78 bus_space_tag_t iot = &icp->ic_iot;
79 pci_chipset_tag_t pc = &icp->ic_pc;
81 pc->pc_intr_v = icp;
82 pc->pc_intr_map = api_up1000_intr_map;
83 pc->pc_intr_string = api_up1000_intr_string;
84 pc->pc_intr_evcnt = api_up1000_intr_evcnt;
85 pc->pc_intr_establish = api_up1000_intr_establish;
86 pc->pc_intr_disestablish = api_up1000_intr_disestablish;
88 pc->pc_pciide_compat_intr_establish =
89 api_up1000_pciide_compat_intr_establish;
91 sio_intr_setup(pc, iot);
92 #else
93 panic("pci_up1000_pickintr: no I/O interrupt handler (no sio)");
94 #endif
97 int
98 api_up1000_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
100 pci_chipset_tag_t pc = pa->pa_pc;
101 int buspin = pa->pa_intrpin;
102 int bustag = pa->pa_intrtag;
103 int line = pa->pa_intrline;
104 int bus, device, function;
106 if (buspin == 0) {
107 /* No IRQ used. */
108 return 1;
110 if (buspin > 4) {
111 printf("api_up1000_intr_map: bad interrupt pin %d\n",
112 buspin);
113 return 1;
116 pci_decompose_tag(pc, bustag, &bus, &device, &function);
119 * The console places the interrupt mapping in the "line" value.
120 * A value of (char)-1 indicates there is no mapping.
122 if (line == 0xff) {
123 printf("api_up1000_intr_map: no mapping for %d/%d/%d\n",
124 bus, device, function);
125 return (1);
128 /* XXX Check for 0? */
129 if (line > 15) {
130 printf("api_up1000_intr_map: ISA IRQ too large (%d)\n",
131 line);
132 return (1);
134 if (line == 2) {
135 printf("api_up1000_intr_map: changed IRQ 2 to IRQ 9\n");
136 line = 9;
139 *ihp = line;
140 return (0);
143 const char *
144 api_up1000_intr_string(void *icv, pci_intr_handle_t ih)
146 #if 0
147 struct irongate_config *icp = icv;
148 #endif
150 return sio_intr_string(NULL /*XXX*/, ih);
153 const struct evcnt *
154 api_up1000_intr_evcnt(void *icv, pci_intr_handle_t ih)
156 #if 0
157 struct irongate_config *icp = icv;
158 #endif
160 return sio_intr_evcnt(NULL /*XXX*/, ih);
163 void *
164 api_up1000_intr_establish(void *icv, pci_intr_handle_t ih, int level,
165 int (*func)(void *), void *arg)
167 #if 0
168 struct irongate_config *icp = icv;
169 #endif
171 return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
172 arg);
175 void
176 api_up1000_intr_disestablish(void *icv, void *cookie)
178 #if 0
179 struct irongate_config *icp = icv;
180 #endif
182 sio_intr_disestablish(NULL /*XXX*/, cookie);
185 void *
186 api_up1000_pciide_compat_intr_establish(void *icv, struct device *dev,
187 struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
189 pci_chipset_tag_t pc = pa->pa_pc;
190 void *cookie = NULL;
191 int bus, irq;
193 pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
196 * If this isn't PCI bus #0, all bets are off.
198 if (bus != 0)
199 return (NULL);
201 irq = PCIIDE_COMPAT_IRQ(chan);
202 #if NSIO
203 cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO,
204 func, arg);
205 if (cookie == NULL)
206 return (NULL);
207 printf("%s: %s channel interrupting at %s\n", dev->dv_xname,
208 PCIIDE_CHANNEL_NAME(chan), sio_intr_string(NULL /*XXX*/, irq));
209 #endif
210 return (cookie);