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