iop_pci.c revision 1.15.4.1 1 /* $NetBSD: iop_pci.c,v 1.15.4.1 2006/12/30 20:48:46 yamt Exp $ */
2
3 /*-
4 * Copyright (c) 2000, 2001, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * PCI front-end for `iop' driver.
41 */
42
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: iop_pci.c,v 1.15.4.1 2006/12/30 20:48:46 yamt Exp $");
45
46 #include "opt_i2o.h"
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 #include <sys/device.h>
52 #include <sys/queue.h>
53 #include <sys/proc.h>
54
55 #include <machine/endian.h>
56 #include <machine/bus.h>
57
58 #include <dev/pci/pcidevs.h>
59 #include <dev/pci/pcivar.h>
60
61 #include <dev/i2o/i2o.h>
62 #include <dev/i2o/iopreg.h>
63 #include <dev/i2o/iopio.h>
64 #include <dev/i2o/iopvar.h>
65
66 #define PCI_INTERFACE_I2O_POLLED 0x00
67 #define PCI_INTERFACE_I2O_INTRDRIVEN 0x01
68
69 static void iop_pci_attach(struct device *, struct device *, void *);
70 static int iop_pci_match(struct device *, struct cfdata *, void *);
71
72 CFATTACH_DECL(iop_pci, sizeof(struct iop_softc),
73 iop_pci_match, iop_pci_attach, NULL, NULL);
74
75 static int
76 iop_pci_match(struct device *parent, struct cfdata *match,
77 void *aux)
78 {
79 struct pci_attach_args *pa;
80 u_int product, vendor;
81 pcireg_t reg;
82
83 pa = aux;
84
85 /*
86 * Look for an "intelligent I/O processor" that adheres to the I2O
87 * specification. Ignore the device if it doesn't support interrupt
88 * driven operation.
89 */
90 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_I2O &&
91 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_I2O_STANDARD &&
92 PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_I2O_INTRDRIVEN)
93 return (1);
94
95 /*
96 * Match boards that don't conform exactly to the spec.
97 */
98 vendor = PCI_VENDOR(pa->pa_id);
99 product = PCI_PRODUCT(pa->pa_id);
100
101 if (vendor == PCI_VENDOR_DPT &&
102 (product == PCI_PRODUCT_DPT_RAID_I2O ||
103 product == PCI_PRODUCT_DPT_RAID_2005S))
104 return (1);
105
106 if (vendor == PCI_VENDOR_INTEL &&
107 (product == PCI_PRODUCT_INTEL_80960RM_2 ||
108 product == PCI_PRODUCT_INTEL_80960_RP)) {
109 reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
110 if (PCI_VENDOR(reg) == PCI_VENDOR_PROMISE)
111 return (1);
112 }
113
114 return (0);
115 }
116
117 static void
118 iop_pci_attach(struct device *parent, struct device *self, void *aux)
119 {
120 struct pci_attach_args *pa;
121 struct iop_softc *sc;
122 pci_chipset_tag_t pc;
123 pci_intr_handle_t ih;
124 const char *intrstr;
125 pcireg_t reg;
126 int i;
127
128 sc = (struct iop_softc *)self;
129 pa = (struct pci_attach_args *)aux;
130 pc = pa->pa_pc;
131 printf(": ");
132
133 /*
134 * The kernel always uses the first memory mapping to communicate
135 * with the IOP.
136 */
137 for (i = PCI_MAPREG_START; i < PCI_MAPREG_END; i += 4) {
138 reg = pci_conf_read(pc, pa->pa_tag, i);
139 if (PCI_MAPREG_TYPE(reg) == PCI_MAPREG_TYPE_MEM) {
140 sc->sc_memaddr = PCI_MAPREG_MEM_ADDR(reg);
141 break;
142 }
143 }
144 if (i == PCI_MAPREG_END) {
145 printf("can't find mapping\n");
146 return;
147 }
148
149 /* Map the register window. */
150 if (pci_mapreg_map(pa, i, PCI_MAPREG_TYPE_MEM, 0, &sc->sc_iot,
151 &sc->sc_ioh, NULL, NULL)) {
152 printf("%s: can't map register window\n", sc->sc_dv.dv_xname);
153 return;
154 }
155
156 /* Map the 2nd register window. */
157 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_DPT &&
158 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_DPT_RAID_2005S) {
159 i += 4; /* next BAR */
160 if (i == PCI_MAPREG_END) {
161 printf("can't find mapping\n");
162 return;
163 }
164
165 #if 0
166 /* Should we check it? (see FreeBSD's asr driver) */
167 reg = pci_conf_read(pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
168 printf("subid %x, %x\n", PCI_VENDOR(reg), PCI_PRODUCT(reg));
169 #endif
170 if (pci_mapreg_map(pa, i, PCI_MAPREG_TYPE_MEM, 0,
171 &sc->sc_msg_iot, &sc->sc_msg_ioh, NULL, NULL)) {
172 printf("%s: can't map 2nd register window\n",
173 sc->sc_dv.dv_xname);
174 return;
175 }
176 } else {
177 /* iop devices other than 2005S */
178 sc->sc_msg_iot = sc->sc_iot;
179 sc->sc_msg_ioh = sc->sc_ioh;
180 }
181
182 sc->sc_pcibus = pa->pa_bus;
183 sc->sc_pcidev = pa->pa_device;
184 sc->sc_dmat = pa->pa_dmat;
185 sc->sc_bus_memt = pa->pa_memt;
186 sc->sc_bus_iot = pa->pa_iot;
187
188 /* Enable the device. */
189 reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
190 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
191 reg | PCI_COMMAND_MASTER_ENABLE);
192
193 /* Map and establish the interrupt. XXX IPL_BIO. */
194 if (pci_intr_map(pa, &ih)) {
195 printf("can't map interrupt\n");
196 return;
197 }
198 intrstr = pci_intr_string(pc, ih);
199 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, iop_intr, sc);
200 if (sc->sc_ih == NULL) {
201 printf("can't establish interrupt");
202 if (intrstr != NULL)
203 printf(" at %s", intrstr);
204 printf("\n");
205 return;
206 }
207
208 /* Attach to the bus-independent code. */
209 iop_init(sc, intrstr);
210 }
211