1 /* $NetBSD: pci_up1000.c,v 1.9 2007/03/04 21:58:16 mrg Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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>
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>
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 *);
75 pci_up1000_pickintr(struct irongate_config
*icp
)
78 bus_space_tag_t iot
= &icp
->ic_iot
;
79 pci_chipset_tag_t pc
= &icp
->ic_pc
;
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
);
93 panic("pci_up1000_pickintr: no I/O interrupt handler (no sio)");
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
;
111 printf("api_up1000_intr_map: bad interrupt pin %d\n",
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.
123 printf("api_up1000_intr_map: no mapping for %d/%d/%d\n",
124 bus
, device
, function
);
128 /* XXX Check for 0? */
130 printf("api_up1000_intr_map: ISA IRQ too large (%d)\n",
135 printf("api_up1000_intr_map: changed IRQ 2 to IRQ 9\n");
144 api_up1000_intr_string(void *icv
, pci_intr_handle_t ih
)
147 struct irongate_config
*icp
= icv
;
150 return sio_intr_string(NULL
/*XXX*/, ih
);
154 api_up1000_intr_evcnt(void *icv
, pci_intr_handle_t ih
)
157 struct irongate_config
*icp
= icv
;
160 return sio_intr_evcnt(NULL
/*XXX*/, ih
);
164 api_up1000_intr_establish(void *icv
, pci_intr_handle_t ih
, int level
,
165 int (*func
)(void *), void *arg
)
168 struct irongate_config
*icp
= icv
;
171 return sio_intr_establish(NULL
/*XXX*/, ih
, IST_LEVEL
, level
, func
,
176 api_up1000_intr_disestablish(void *icv
, void *cookie
)
179 struct irongate_config
*icp
= icv
;
182 sio_intr_disestablish(NULL
/*XXX*/, cookie
);
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
;
193 pci_decompose_tag(pc
, pa
->pa_tag
, &bus
, NULL
, NULL
);
196 * If this isn't PCI bus #0, all bets are off.
201 irq
= PCIIDE_COMPAT_IRQ(chan
);
203 cookie
= sio_intr_establish(NULL
/*XXX*/, irq
, IST_EDGE
, IPL_BIO
,
207 printf("%s: %s channel interrupting at %s\n", dev
->dv_xname
,
208 PCIIDE_CHANNEL_NAME(chan
), sio_intr_string(NULL
/*XXX*/, irq
));