hdlg_pci.c revision 1.1.10.2 1 1.1.10.2 tron /* $NetBSD: hdlg_pci.c,v 1.1.10.2 2006/05/24 15:47:54 tron Exp $ */
2 1.1.10.2 tron
3 1.1.10.2 tron /*
4 1.1.10.2 tron * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
5 1.1.10.2 tron * All rights reserved.
6 1.1.10.2 tron *
7 1.1.10.2 tron * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1.10.2 tron *
9 1.1.10.2 tron * Redistribution and use in source and binary forms, with or without
10 1.1.10.2 tron * modification, are permitted provided that the following conditions
11 1.1.10.2 tron * are met:
12 1.1.10.2 tron * 1. Redistributions of source code must retain the above copyright
13 1.1.10.2 tron * notice, this list of conditions and the following disclaimer.
14 1.1.10.2 tron * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.10.2 tron * notice, this list of conditions and the following disclaimer in the
16 1.1.10.2 tron * documentation and/or other materials provided with the distribution.
17 1.1.10.2 tron * 3. All advertising materials mentioning features or use of this software
18 1.1.10.2 tron * must display the following acknowledgement:
19 1.1.10.2 tron * This product includes software developed for the NetBSD Project by
20 1.1.10.2 tron * Wasabi Systems, Inc.
21 1.1.10.2 tron * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1.10.2 tron * or promote products derived from this software without specific prior
23 1.1.10.2 tron * written permission.
24 1.1.10.2 tron *
25 1.1.10.2 tron * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1.10.2 tron * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1.10.2 tron * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1.10.2 tron * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1.10.2 tron * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1.10.2 tron * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1.10.2 tron * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1.10.2 tron * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1.10.2 tron * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1.10.2 tron * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1.10.2 tron * POSSIBILITY OF SUCH DAMAGE.
36 1.1.10.2 tron */
37 1.1.10.2 tron
38 1.1.10.2 tron #include <sys/cdefs.h>
39 1.1.10.2 tron __KERNEL_RCSID(0, "$NetBSD: hdlg_pci.c,v 1.1.10.2 2006/05/24 15:47:54 tron Exp $");
40 1.1.10.2 tron
41 1.1.10.2 tron #include <sys/param.h>
42 1.1.10.2 tron #include <sys/systm.h>
43 1.1.10.2 tron #include <sys/device.h>
44 1.1.10.2 tron
45 1.1.10.2 tron #include <machine/autoconf.h>
46 1.1.10.2 tron #include <machine/bus.h>
47 1.1.10.2 tron
48 1.1.10.2 tron #include <evbarm/hdl_g/hdlgreg.h>
49 1.1.10.2 tron #include <evbarm/hdl_g/hdlgvar.h>
50 1.1.10.2 tron
51 1.1.10.2 tron #include <arm/xscale/i80321reg.h>
52 1.1.10.2 tron #include <arm/xscale/i80321var.h>
53 1.1.10.2 tron
54 1.1.10.2 tron #include <dev/pci/pcidevs.h>
55 1.1.10.2 tron #include <dev/pci/ppbreg.h>
56 1.1.10.2 tron
57 1.1.10.2 tron int hdlg_pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
58 1.1.10.2 tron const char *hdlg_pci_intr_string(void *, pci_intr_handle_t);
59 1.1.10.2 tron const struct evcnt *hdlg_pci_intr_evcnt(void *, pci_intr_handle_t);
60 1.1.10.2 tron void *hdlg_pci_intr_establish(void *, pci_intr_handle_t,
61 1.1.10.2 tron int, int (*func)(void *), void *);
62 1.1.10.2 tron void hdlg_pci_intr_disestablish(void *, void *);
63 1.1.10.2 tron
64 1.1.10.2 tron void
65 1.1.10.2 tron hdlg_pci_init(pci_chipset_tag_t pc, void *cookie)
66 1.1.10.2 tron {
67 1.1.10.2 tron
68 1.1.10.2 tron pc->pc_intr_v = cookie; /* the i80321 softc */
69 1.1.10.2 tron pc->pc_intr_map = hdlg_pci_intr_map;
70 1.1.10.2 tron pc->pc_intr_string = hdlg_pci_intr_string;
71 1.1.10.2 tron pc->pc_intr_evcnt = hdlg_pci_intr_evcnt;
72 1.1.10.2 tron pc->pc_intr_establish = hdlg_pci_intr_establish;
73 1.1.10.2 tron pc->pc_intr_disestablish = hdlg_pci_intr_disestablish;
74 1.1.10.2 tron }
75 1.1.10.2 tron
76 1.1.10.2 tron int
77 1.1.10.2 tron hdlg_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
78 1.1.10.2 tron {
79 1.1.10.2 tron struct i80321_softc *sc = pa->pa_pc->pc_intr_v;
80 1.1.10.2 tron uint32_t busno;
81 1.1.10.2 tron int b, d, f;
82 1.1.10.2 tron
83 1.1.10.2 tron /*
84 1.1.10.2 tron * GigaLANDISK's interrupts are routed like so:
85 1.1.10.2 tron *
86 1.1.10.2 tron * XINT0 Intel i82541PI Gig-E
87 1.1.10.2 tron *
88 1.1.10.2 tron * XINT1 ACARD ATP875-A
89 1.1.10.2 tron *
90 1.1.10.2 tron * XINT2 NEC echi/ochi
91 1.1.10.2 tron *
92 1.1.10.2 tron * XINT3 UART
93 1.1.10.2 tron */
94 1.1.10.2 tron
95 1.1.10.2 tron busno = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, ATU_PCIXSR);
96 1.1.10.2 tron busno = PCIXSR_BUSNO(busno);
97 1.1.10.2 tron if (busno == 0xff)
98 1.1.10.2 tron busno = 0;
99 1.1.10.2 tron
100 1.1.10.2 tron pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, &b, &d, &f);
101 1.1.10.2 tron
102 1.1.10.2 tron /* No mappings for devices not on our bus. */
103 1.1.10.2 tron if (b != busno)
104 1.1.10.2 tron goto no_mapping;
105 1.1.10.2 tron
106 1.1.10.2 tron switch (d) {
107 1.1.10.2 tron case 1: /* i82541PI Gig-E */
108 1.1.10.2 tron if (pa->pa_intrpin == 1) {
109 1.1.10.2 tron *ihp = ICU_INT_XINT(0);
110 1.1.10.2 tron return 0;
111 1.1.10.2 tron }
112 1.1.10.2 tron goto no_mapping;
113 1.1.10.2 tron
114 1.1.10.2 tron case 2: /* ATP875-A */
115 1.1.10.2 tron if (pa->pa_intrpin == 1) {
116 1.1.10.2 tron *ihp = ICU_INT_XINT(1);
117 1.1.10.2 tron return 0;
118 1.1.10.2 tron }
119 1.1.10.2 tron goto no_mapping;
120 1.1.10.2 tron
121 1.1.10.2 tron case 3: /* echi/ochi */
122 1.1.10.2 tron switch (pa->pa_intrpin) {
123 1.1.10.2 tron case 1: /* ohci */
124 1.1.10.2 tron case 2: /* ohci */
125 1.1.10.2 tron case 3: /* ehci */
126 1.1.10.2 tron *ihp = ICU_INT_XINT(2);
127 1.1.10.2 tron return 0;
128 1.1.10.2 tron }
129 1.1.10.2 tron goto no_mapping;
130 1.1.10.2 tron
131 1.1.10.2 tron default:
132 1.1.10.2 tron no_mapping:
133 1.1.10.2 tron printf("hdlg_pci_intr_map: no mapping for %d/%d/%d\n",
134 1.1.10.2 tron pa->pa_bus, pa->pa_device, pa->pa_function);
135 1.1.10.2 tron return 1;
136 1.1.10.2 tron }
137 1.1.10.2 tron
138 1.1.10.2 tron return 0;
139 1.1.10.2 tron }
140 1.1.10.2 tron
141 1.1.10.2 tron const char *
142 1.1.10.2 tron hdlg_pci_intr_string(void *v, pci_intr_handle_t ih)
143 1.1.10.2 tron {
144 1.1.10.2 tron
145 1.1.10.2 tron return i80321_irqnames[ih];
146 1.1.10.2 tron }
147 1.1.10.2 tron
148 1.1.10.2 tron const struct evcnt *
149 1.1.10.2 tron hdlg_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
150 1.1.10.2 tron {
151 1.1.10.2 tron
152 1.1.10.2 tron /* XXX For now. */
153 1.1.10.2 tron return NULL;
154 1.1.10.2 tron }
155 1.1.10.2 tron
156 1.1.10.2 tron void *
157 1.1.10.2 tron hdlg_pci_intr_establish(void *v, pci_intr_handle_t ih, int ipl,
158 1.1.10.2 tron int (*func)(void *), void *arg)
159 1.1.10.2 tron {
160 1.1.10.2 tron
161 1.1.10.2 tron return i80321_intr_establish(ih, ipl, func, arg);
162 1.1.10.2 tron }
163 1.1.10.2 tron
164 1.1.10.2 tron void
165 1.1.10.2 tron hdlg_pci_intr_disestablish(void *v, void *cookie)
166 1.1.10.2 tron {
167 1.1.10.2 tron
168 1.1.10.2 tron i80321_intr_disestablish(cookie);
169 1.1.10.2 tron }
170