i80312.c revision 1.6 1 1.6 thorpej /* $NetBSD: i80312.c,v 1.6 2001/11/30 19:29:44 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 2001 Wasabi Systems, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1 thorpej *
9 1.1 thorpej * Redistribution and use in source and binary forms, with or without
10 1.1 thorpej * modification, are permitted provided that the following conditions
11 1.1 thorpej * are met:
12 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer.
14 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.1 thorpej * documentation and/or other materials provided with the distribution.
17 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.1 thorpej * must display the following acknowledgement:
19 1.1 thorpej * This product includes software developed for the NetBSD Project by
20 1.1 thorpej * Wasabi Systems, Inc.
21 1.1 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 thorpej * or promote products derived from this software without specific prior
23 1.1 thorpej * written permission.
24 1.1 thorpej *
25 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
36 1.1 thorpej */
37 1.1 thorpej
38 1.1 thorpej /*
39 1.1 thorpej * Autoconfiguration support for the Intel i80312 Companion I/O chip.
40 1.1 thorpej */
41 1.1 thorpej
42 1.1 thorpej #include <sys/param.h>
43 1.1 thorpej #include <sys/systm.h>
44 1.1 thorpej #include <sys/device.h>
45 1.1 thorpej
46 1.1 thorpej #include <machine/bus.h>
47 1.1 thorpej
48 1.1 thorpej #include <arm/xscale/i80312reg.h>
49 1.1 thorpej #include <arm/xscale/i80312var.h>
50 1.1 thorpej
51 1.1 thorpej #include <dev/pci/ppbreg.h>
52 1.1 thorpej
53 1.1 thorpej /*
54 1.1 thorpej * Statically-allocated bus_space stucture used to access the
55 1.1 thorpej * i80312's own registers.
56 1.1 thorpej */
57 1.1 thorpej struct bus_space i80312_bs_tag;
58 1.1 thorpej
59 1.5 thorpej /*
60 1.5 thorpej * There can be only one i80312, so we keep a global pointer to
61 1.5 thorpej * the softc, so board-specific code can use features of the
62 1.5 thorpej * i80312 without having to have a handle on the softc itself.
63 1.5 thorpej */
64 1.5 thorpej struct i80312_softc *i80312_softc;
65 1.5 thorpej
66 1.1 thorpej int i80312_pcibus_print(void *, const char *);
67 1.1 thorpej
68 1.1 thorpej /*
69 1.1 thorpej * i80312_attach:
70 1.1 thorpej *
71 1.1 thorpej * Board-independent attach routine for the i80312.
72 1.1 thorpej */
73 1.1 thorpej void
74 1.1 thorpej i80312_attach(struct i80312_softc *sc)
75 1.1 thorpej {
76 1.1 thorpej struct pcibus_attach_args pba;
77 1.1 thorpej uint32_t atucr;
78 1.1 thorpej pcireg_t preg;
79 1.1 thorpej
80 1.1 thorpej /*
81 1.1 thorpej * Slice off some useful subregion handles.
82 1.1 thorpej */
83 1.1 thorpej
84 1.1 thorpej if (bus_space_subregion(sc->sc_st, sc->sc_sh, I80312_PPB_BASE,
85 1.1 thorpej I80312_PPB_SIZE, &sc->sc_ppb_sh))
86 1.1 thorpej panic("%s: unable to subregion PPB registers\n",
87 1.1 thorpej sc->sc_dev.dv_xname);
88 1.1 thorpej
89 1.1 thorpej if (bus_space_subregion(sc->sc_st, sc->sc_sh, I80312_ATU_BASE,
90 1.1 thorpej I80312_ATU_SIZE, &sc->sc_atu_sh))
91 1.1 thorpej panic("%s: unable to subregion ATU registers\n",
92 1.5 thorpej sc->sc_dev.dv_xname);
93 1.5 thorpej
94 1.5 thorpej if (bus_space_subregion(sc->sc_st, sc->sc_sh, I80312_INTC_BASE,
95 1.5 thorpej I80312_INTC_SIZE, &sc->sc_intc_sh))
96 1.5 thorpej panic("%s: unable to subregion INTC registers\n",
97 1.1 thorpej sc->sc_dev.dv_xname);
98 1.1 thorpej
99 1.3 thorpej /* We expect the Memory Controller to be already sliced off. */
100 1.3 thorpej
101 1.1 thorpej /*
102 1.1 thorpej * Disable the private space decode.
103 1.1 thorpej */
104 1.1 thorpej sc->sc_sder = bus_space_read_1(sc->sc_st, sc->sc_ppb_sh,
105 1.1 thorpej I80312_PPB_SDER);
106 1.1 thorpej sc->sc_sder &= ~PPB_SDER_PMSE;
107 1.1 thorpej bus_space_write_1(sc->sc_st, sc->sc_ppb_sh,
108 1.1 thorpej I80312_PPB_SDER, sc->sc_sder);
109 1.1 thorpej
110 1.1 thorpej /*
111 1.1 thorpej * Program the Secondary ID Select register.
112 1.1 thorpej */
113 1.1 thorpej bus_space_write_2(sc->sc_st, sc->sc_ppb_sh,
114 1.1 thorpej I80312_PPB_SISR, sc->sc_sisr);
115 1.1 thorpej
116 1.1 thorpej /*
117 1.1 thorpej * Program the private secondary bus spaces.
118 1.1 thorpej */
119 1.1 thorpej if (sc->sc_privmem_size && sc->sc_privio_size) {
120 1.1 thorpej bus_space_write_1(sc->sc_st, sc->sc_ppb_sh, I80312_PPB_SIOBR,
121 1.1 thorpej (sc->sc_privio_base >> 12) << 4);
122 1.1 thorpej bus_space_write_1(sc->sc_st, sc->sc_ppb_sh, I80312_PPB_SIOLR,
123 1.1 thorpej ((sc->sc_privio_base + sc->sc_privio_size - 1)
124 1.1 thorpej >> 12) << 4);
125 1.1 thorpej
126 1.1 thorpej bus_space_write_2(sc->sc_st, sc->sc_ppb_sh, I80312_PPB_SMBR,
127 1.1 thorpej (sc->sc_privmem_base >> 20) << 4);
128 1.1 thorpej bus_space_write_2(sc->sc_st, sc->sc_ppb_sh, I80312_PPB_SMLR,
129 1.1 thorpej ((sc->sc_privmem_base + sc->sc_privmem_size - 1)
130 1.1 thorpej >> 20) << 4);
131 1.1 thorpej
132 1.1 thorpej sc->sc_sder |= PPB_SDER_PMSE;
133 1.1 thorpej bus_space_write_1(sc->sc_st, sc->sc_ppb_sh, I80312_PPB_SDER,
134 1.1 thorpej sc->sc_sder);
135 1.1 thorpej } else if (sc->sc_privmem_size || sc->sc_privio_size) {
136 1.1 thorpej printf("%s: WARNING: privmem_size 0x%08x privio_size 0x%08x\n",
137 1.1 thorpej sc->sc_dev.dv_xname, sc->sc_privmem_size,
138 1.1 thorpej sc->sc_privio_size);
139 1.1 thorpej printf("%s: private bus spaces not enabled\n",
140 1.1 thorpej sc->sc_dev.dv_xname);
141 1.1 thorpej }
142 1.1 thorpej
143 1.1 thorpej /*
144 1.1 thorpej * Program the Primary Inbound window.
145 1.1 thorpej */
146 1.1 thorpej if (sc->sc_is_host)
147 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
148 1.1 thorpej PCI_MAPREG_START, sc->sc_pin_base);
149 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
150 1.1 thorpej I80312_ATU_PIAL, ATU_LIMIT(sc->sc_pin_size));
151 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
152 1.1 thorpej I80312_ATU_PIATV, sc->sc_pin_xlate);
153 1.1 thorpej
154 1.1 thorpej /*
155 1.1 thorpej * Program the Secondary Inbound window.
156 1.1 thorpej */
157 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
158 1.1 thorpej I80312_ATU_SIAM, sc->sc_sin_base);
159 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
160 1.1 thorpej I80312_ATU_SIAL, ATU_LIMIT(sc->sc_sin_size));
161 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
162 1.1 thorpej I80312_ATU_SIATV, sc->sc_sin_xlate);
163 1.2 thorpej
164 1.2 thorpej /*
165 1.2 thorpej * Mask (disable) the ATU interrupt sources.
166 1.2 thorpej * XXX May want to revisit this if we encounter
167 1.2 thorpej * XXX an application that wants it.
168 1.2 thorpej */
169 1.2 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
170 1.2 thorpej I80312_ATU_PAIM,
171 1.2 thorpej ATU_AIM_MPEIM | ATU_AIM_TATIM | ATU_AIM_TAMIM |
172 1.2 thorpej ATU_AIM_MAIM | ATU_AIM_SAIM | ATU_AIM_DPEIM |
173 1.2 thorpej ATU_AIM_PSTIM);
174 1.2 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
175 1.2 thorpej I80312_ATU_SAIM,
176 1.2 thorpej ATU_AIM_MPEIM | ATU_AIM_TATIM | ATU_AIM_TAMIM |
177 1.2 thorpej ATU_AIM_MAIM | ATU_AIM_SAIM | ATU_AIM_DPEIM);
178 1.1 thorpej
179 1.1 thorpej /*
180 1.1 thorpej * Clear:
181 1.1 thorpej *
182 1.1 thorpej * Primary Outbound ATU Enable
183 1.1 thorpej * Secondary Outbound ATU Enable
184 1.1 thorpej * Secondary Direct Addressing Select
185 1.1 thorpej * Direct Addressing Enable
186 1.1 thorpej */
187 1.1 thorpej atucr = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, I80312_ATU_ACR);
188 1.1 thorpej atucr &= ~(ATU_ACR_POAE|ATU_ACR_SOAE|ATU_ACR_SDAS|ATU_ACR_DAE);
189 1.1 thorpej
190 1.1 thorpej /*
191 1.1 thorpej * Program the Primary Outbound windows.
192 1.1 thorpej */
193 1.1 thorpej if (sc->sc_pmemout_size)
194 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
195 1.1 thorpej I80312_ATU_POMWV, sc->sc_pmemout_base);
196 1.1 thorpej if (sc->sc_pioout_size)
197 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
198 1.1 thorpej I80312_ATU_POIOWV, sc->sc_pioout_base);
199 1.1 thorpej if (sc->sc_pmemout_size || sc->sc_pioout_size)
200 1.1 thorpej atucr |= ATU_ACR_POAE;
201 1.1 thorpej
202 1.1 thorpej /*
203 1.1 thorpej * Program the Secondary Outbound windows.
204 1.1 thorpej */
205 1.1 thorpej if (sc->sc_smemout_size)
206 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
207 1.1 thorpej I80312_ATU_SOMWV, sc->sc_smemout_base);
208 1.1 thorpej if (sc->sc_sioout_size)
209 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
210 1.1 thorpej I80312_ATU_SOIOWV, sc->sc_sioout_base);
211 1.1 thorpej if (sc->sc_smemout_size || sc->sc_sioout_size)
212 1.1 thorpej atucr |= ATU_ACR_SOAE;
213 1.1 thorpej
214 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh, I80312_ATU_ACR, atucr);
215 1.1 thorpej
216 1.1 thorpej /*
217 1.1 thorpej * Enable bus mastering, memory access, SERR, and parity
218 1.1 thorpej * checking on the ATU.
219 1.1 thorpej */
220 1.1 thorpej if (sc->sc_is_host) {
221 1.1 thorpej preg = bus_space_read_4(sc->sc_st, sc->sc_atu_sh,
222 1.1 thorpej PCI_COMMAND_STATUS_REG);
223 1.1 thorpej preg |= PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE |
224 1.1 thorpej PCI_COMMAND_PARITY_ENABLE | PCI_COMMAND_SERR_ENABLE;
225 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
226 1.1 thorpej PCI_COMMAND_STATUS_REG, preg);
227 1.1 thorpej }
228 1.1 thorpej preg = bus_space_read_4(sc->sc_st, sc->sc_atu_sh,
229 1.1 thorpej I80312_ATU_SACS);
230 1.1 thorpej preg |= PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE |
231 1.1 thorpej PCI_COMMAND_PARITY_ENABLE | PCI_COMMAND_SERR_ENABLE;
232 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
233 1.1 thorpej I80312_ATU_SACS, preg);
234 1.1 thorpej
235 1.1 thorpej /*
236 1.1 thorpej * Configure the bridge. If we're a host, set the primary
237 1.1 thorpej * bus to bus #0 and the secondary bus to bus #1. We also
238 1.1 thorpej * set the PPB's subordinate bus # to 1. It will be fixed
239 1.1 thorpej * up later when we fully configure the bus.
240 1.1 thorpej *
241 1.1 thorpej * If we're a slave, just use the bus #'s that the host
242 1.1 thorpej * provides.
243 1.1 thorpej */
244 1.1 thorpej if (sc->sc_is_host) {
245 1.1 thorpej bus_space_write_4(sc->sc_st, sc->sc_ppb_sh,
246 1.1 thorpej PPB_REG_BUSINFO,
247 1.1 thorpej (0 << PCI_BRIDGE_BUS_PRIMARY_SHIFT) |
248 1.1 thorpej (1 << PCI_BRIDGE_BUS_SECONDARY_SHIFT) |
249 1.1 thorpej (1 << PCI_BRIDGE_BUS_SUBORDINATE_SHIFT));
250 1.1 thorpej }
251 1.1 thorpej
252 1.1 thorpej /*
253 1.1 thorpej * Initialize the bus space and DMA tags and the PCI chipset tag.
254 1.1 thorpej */
255 1.1 thorpej i80312_io_bs_init(&sc->sc_pci_iot, sc);
256 1.1 thorpej i80312_mem_bs_init(&sc->sc_pci_memt, sc);
257 1.1 thorpej i80312_pci_dma_init(&sc->sc_pci_dmat, sc);
258 1.1 thorpej i80312_pci_init(&sc->sc_pci_chipset, sc);
259 1.1 thorpej
260 1.1 thorpej /*
261 1.6 thorpej * Attach the PCI bus.
262 1.6 thorpej *
263 1.6 thorpej * Note: We only probe the Secondary PCI bus, since that
264 1.6 thorpej * is the only bus on which we can have a private device
265 1.6 thorpej * space.
266 1.1 thorpej */
267 1.6 thorpej preg = bus_space_read_4(sc->sc_st, sc->sc_ppb_sh, PPB_REG_BUSINFO);
268 1.1 thorpej pba.pba_busname = "pci";
269 1.1 thorpej pba.pba_iot = &sc->sc_pci_iot;
270 1.1 thorpej pba.pba_memt = &sc->sc_pci_memt;
271 1.1 thorpej pba.pba_dmat = &sc->sc_pci_dmat;
272 1.1 thorpej pba.pba_pc = &sc->sc_pci_chipset;
273 1.6 thorpej pba.pba_bus = PPB_BUSINFO_SECONDARY(preg);
274 1.4 thorpej /* XXX MRL/MRM/MWI seem to have problems, at the moment. */
275 1.4 thorpej pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED /* |
276 1.4 thorpej PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY */;
277 1.1 thorpej (void) config_found(&sc->sc_dev, &pba, i80312_pcibus_print);
278 1.1 thorpej }
279 1.1 thorpej
280 1.1 thorpej /*
281 1.1 thorpej * i80312_pcibus_print:
282 1.1 thorpej *
283 1.1 thorpej * Autoconfiguration cfprint routine when attaching
284 1.1 thorpej * to the "pcibus" attribute.
285 1.1 thorpej */
286 1.1 thorpej int
287 1.1 thorpej i80312_pcibus_print(void *aux, const char *pnp)
288 1.1 thorpej {
289 1.1 thorpej struct pcibus_attach_args *pba = aux;
290 1.1 thorpej
291 1.1 thorpej if (pnp)
292 1.1 thorpej printf("%s at %s", pba->pba_busname, pnp);
293 1.1 thorpej
294 1.1 thorpej printf(" bus %d", pba->pba_bus);
295 1.1 thorpej
296 1.1 thorpej return (UNCONF);
297 1.1 thorpej }
298