i80321.c revision 1.1.2.4 1 1.1.2.4 nathanw /* $NetBSD: i80321.c,v 1.1.2.4 2002/08/01 02:41:20 nathanw Exp $ */
2 1.1.2.2 nathanw
3 1.1.2.2 nathanw /*
4 1.1.2.2 nathanw * Copyright (c) 2002 Wasabi Systems, Inc.
5 1.1.2.2 nathanw * All rights reserved.
6 1.1.2.2 nathanw *
7 1.1.2.2 nathanw * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1.2.2 nathanw *
9 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
10 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
11 1.1.2.2 nathanw * are met:
12 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
13 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
14 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
16 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
17 1.1.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
18 1.1.2.2 nathanw * must display the following acknowledgement:
19 1.1.2.2 nathanw * This product includes software developed for the NetBSD Project by
20 1.1.2.2 nathanw * Wasabi Systems, Inc.
21 1.1.2.2 nathanw * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1.2.2 nathanw * or promote products derived from this software without specific prior
23 1.1.2.2 nathanw * written permission.
24 1.1.2.2 nathanw *
25 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1.2.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
36 1.1.2.2 nathanw */
37 1.1.2.2 nathanw
38 1.1.2.2 nathanw /*
39 1.1.2.2 nathanw * Autoconfiguration support for the Intel i80321 I/O Processor.
40 1.1.2.2 nathanw */
41 1.1.2.2 nathanw
42 1.1.2.2 nathanw #include <sys/param.h>
43 1.1.2.2 nathanw #include <sys/systm.h>
44 1.1.2.2 nathanw #include <sys/device.h>
45 1.1.2.2 nathanw
46 1.1.2.2 nathanw #include <machine/bus.h>
47 1.1.2.2 nathanw
48 1.1.2.2 nathanw #include <arm/xscale/i80321reg.h>
49 1.1.2.2 nathanw #include <arm/xscale/i80321var.h>
50 1.1.2.2 nathanw
51 1.1.2.2 nathanw /*
52 1.1.2.2 nathanw * Statically-allocated bus_space stucture used to access the
53 1.1.2.2 nathanw * i80321's own registers.
54 1.1.2.2 nathanw */
55 1.1.2.2 nathanw struct bus_space i80321_bs_tag;
56 1.1.2.2 nathanw
57 1.1.2.2 nathanw /*
58 1.1.2.2 nathanw * There can be only one i80321, so we keep a global pointer to
59 1.1.2.2 nathanw * the softc, so board-specific code can use features of the
60 1.1.2.2 nathanw * i80321 without having to have a handle on the softc itself.
61 1.1.2.2 nathanw */
62 1.1.2.2 nathanw struct i80321_softc *i80321_softc;
63 1.1.2.2 nathanw
64 1.1.2.4 nathanw int i80321_iopxs_print(void *, const char *);
65 1.1.2.2 nathanw int i80321_pcibus_print(void *, const char *);
66 1.1.2.2 nathanw
67 1.1.2.4 nathanw /* Built-in devices. */
68 1.1.2.4 nathanw static const struct iopxs_device {
69 1.1.2.4 nathanw const char *id_name;
70 1.1.2.4 nathanw bus_addr_t id_offset;
71 1.1.2.4 nathanw bus_size_t id_size;
72 1.1.2.4 nathanw } iopxs_devices[] = {
73 1.1.2.4 nathanw { "iopaau", VERDE_AAU_BASE, VERDE_AAU_SIZE },
74 1.1.2.4 nathanw { "iopdma", VERDE_DMA_BASE, VERDE_DMA_SIZE },
75 1.1.2.4 nathanw { "iopssp", VERDE_SSP_BASE, VERDE_SSP_SIZE },
76 1.1.2.4 nathanw { "iopwdog", 0, 0 },
77 1.1.2.4 nathanw { NULL, 0, 0 }
78 1.1.2.4 nathanw };
79 1.1.2.4 nathanw
80 1.1.2.2 nathanw /*
81 1.1.2.2 nathanw * i80321_attach:
82 1.1.2.2 nathanw *
83 1.1.2.2 nathanw * Board-independent attach routine for the i80321.
84 1.1.2.2 nathanw */
85 1.1.2.2 nathanw void
86 1.1.2.2 nathanw i80321_attach(struct i80321_softc *sc)
87 1.1.2.2 nathanw {
88 1.1.2.2 nathanw struct pcibus_attach_args pba;
89 1.1.2.4 nathanw const struct iopxs_device *id;
90 1.1.2.4 nathanw struct iopxs_attach_args ia;
91 1.1.2.2 nathanw pcireg_t preg;
92 1.1.2.2 nathanw
93 1.1.2.2 nathanw i80321_softc = sc;
94 1.1.2.2 nathanw
95 1.1.2.2 nathanw /*
96 1.1.2.2 nathanw * Slice off some useful subregion handles.
97 1.1.2.2 nathanw */
98 1.1.2.2 nathanw
99 1.1.2.2 nathanw if (bus_space_subregion(sc->sc_st, sc->sc_sh, VERDE_ATU_BASE,
100 1.1.2.2 nathanw VERDE_ATU_SIZE, &sc->sc_atu_sh))
101 1.1.2.2 nathanw panic("%s: unable to subregion ATU registers\n",
102 1.1.2.2 nathanw sc->sc_dev.dv_xname);
103 1.1.2.2 nathanw
104 1.1.2.2 nathanw /* We expect the Memory Controller to be already sliced off. */
105 1.1.2.2 nathanw
106 1.1.2.2 nathanw /*
107 1.1.2.2 nathanw * Program the Inbound windows.
108 1.1.2.2 nathanw */
109 1.1.2.2 nathanw if (sc->sc_is_host) {
110 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
111 1.1.2.2 nathanw PCI_MAPREG_START, sc->sc_iwin[0].iwin_base_lo);
112 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
113 1.1.2.2 nathanw PCI_MAPREG_START + 0x04, sc->sc_iwin[0].iwin_base_hi);
114 1.1.2.2 nathanw }
115 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IALR0,
116 1.1.2.2 nathanw (0xffffffff - (sc->sc_iwin[0].iwin_size - 1)) & 0xffffffc0);
117 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IATVR0,
118 1.1.2.2 nathanw sc->sc_iwin[0].iwin_xlate);
119 1.1.2.2 nathanw
120 1.1.2.2 nathanw if (sc->sc_is_host) {
121 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
122 1.1.2.2 nathanw PCI_MAPREG_START + 0x08, sc->sc_iwin[1].iwin_base_lo);
123 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
124 1.1.2.2 nathanw PCI_MAPREG_START + 0x0c, sc->sc_iwin[1].iwin_base_hi);
125 1.1.2.2 nathanw }
126 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IALR1,
127 1.1.2.2 nathanw (0xffffffff - (sc->sc_iwin[1].iwin_size - 1)) & 0xffffffc0);
128 1.1.2.2 nathanw /* no xlate for window 1 */
129 1.1.2.2 nathanw
130 1.1.2.2 nathanw if (sc->sc_is_host) {
131 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
132 1.1.2.2 nathanw PCI_MAPREG_START + 0x10, sc->sc_iwin[2].iwin_base_lo);
133 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
134 1.1.2.2 nathanw PCI_MAPREG_START + 0x14, sc->sc_iwin[2].iwin_base_hi);
135 1.1.2.2 nathanw }
136 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IALR2,
137 1.1.2.2 nathanw (0xffffffff - (sc->sc_iwin[2].iwin_size - 1)) & 0xffffffc0);
138 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IATVR2,
139 1.1.2.2 nathanw sc->sc_iwin[2].iwin_xlate);
140 1.1.2.2 nathanw
141 1.1.2.2 nathanw if (sc->sc_is_host) {
142 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
143 1.1.2.2 nathanw ATU_IABAR3, sc->sc_iwin[3].iwin_base_lo);
144 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
145 1.1.2.2 nathanw ATU_IAUBAR3, sc->sc_iwin[3].iwin_base_hi);
146 1.1.2.2 nathanw }
147 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IALR3,
148 1.1.2.2 nathanw (0xffffffff - (sc->sc_iwin[3].iwin_size - 1)) & 0xffffffc0);
149 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IATVR3,
150 1.1.2.2 nathanw sc->sc_iwin[3].iwin_xlate);
151 1.1.2.2 nathanw
152 1.1.2.2 nathanw /*
153 1.1.2.2 nathanw * Mask (disable) the ATU interrupt sources.
154 1.1.2.2 nathanw * XXX May want to revisit this if we encounter
155 1.1.2.2 nathanw * XXX an application that wants it.
156 1.1.2.2 nathanw */
157 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
158 1.1.2.2 nathanw ATU_ATUIMR,
159 1.1.2.2 nathanw ATUIMR_IMW1BU|ATUIMR_ISCEM|ATUIMR_RSCEM|ATUIMR_PST|
160 1.1.2.2 nathanw ATUIMR_DPE|ATUIMR_P_SERR_ASRT|ATUIMR_PMA|ATUIMR_PTAM|
161 1.1.2.2 nathanw ATUIMR_PTAT|ATUIMR_PMPE);
162 1.1.2.2 nathanw
163 1.1.2.2 nathanw /*
164 1.1.2.2 nathanw * Program the outbound windows.
165 1.1.2.2 nathanw */
166 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
167 1.1.2.2 nathanw ATU_OIOWTVR, sc->sc_ioout_xlate);
168 1.1.2.2 nathanw
169 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
170 1.1.2.2 nathanw ATU_OMWTVR0, sc->sc_owin[0].owin_xlate_lo);
171 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
172 1.1.2.2 nathanw ATU_OUMWTVR0, sc->sc_owin[0].owin_xlate_hi);
173 1.1.2.2 nathanw
174 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
175 1.1.2.2 nathanw ATU_OMWTVR1, sc->sc_owin[1].owin_xlate_lo);
176 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
177 1.1.2.2 nathanw ATU_OUMWTVR1, sc->sc_owin[1].owin_xlate_hi);
178 1.1.2.2 nathanw
179 1.1.2.2 nathanw /*
180 1.1.2.2 nathanw * Set up the ATU configuration register. All we do
181 1.1.2.2 nathanw * right now is enable Outbound Windows.
182 1.1.2.2 nathanw */
183 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_ATUCR,
184 1.1.2.2 nathanw ATUCR_OUT_EN);
185 1.1.2.2 nathanw
186 1.1.2.2 nathanw /*
187 1.1.2.2 nathanw * Enable bus mastering, memory access, SERR, and parity
188 1.1.2.2 nathanw * checking on the ATU.
189 1.1.2.2 nathanw */
190 1.1.2.2 nathanw if (sc->sc_is_host) {
191 1.1.2.2 nathanw preg = bus_space_read_4(sc->sc_st, sc->sc_atu_sh,
192 1.1.2.2 nathanw PCI_COMMAND_STATUS_REG);
193 1.1.2.2 nathanw preg |= PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE |
194 1.1.2.2 nathanw PCI_COMMAND_PARITY_ENABLE | PCI_COMMAND_SERR_ENABLE;
195 1.1.2.2 nathanw bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
196 1.1.2.2 nathanw PCI_COMMAND_STATUS_REG, preg);
197 1.1.2.2 nathanw }
198 1.1.2.2 nathanw
199 1.1.2.4 nathanw /* Initialize the bus space tags. */
200 1.1.2.2 nathanw i80321_io_bs_init(&sc->sc_pci_iot, sc);
201 1.1.2.2 nathanw i80321_mem_bs_init(&sc->sc_pci_memt, sc);
202 1.1.2.4 nathanw
203 1.1.2.4 nathanw /* Initialize the PCI chipset tag. */
204 1.1.2.2 nathanw i80321_pci_init(&sc->sc_pci_chipset, sc);
205 1.1.2.2 nathanw
206 1.1.2.4 nathanw /* Initialize the DMA tags. */
207 1.1.2.4 nathanw i80321_pci_dma_init(&sc->sc_pci_dmat, sc);
208 1.1.2.4 nathanw i80321_local_dma_init(&sc->sc_local_dmat, sc);
209 1.1.2.4 nathanw
210 1.1.2.4 nathanw /*
211 1.1.2.4 nathanw * Attach all the IOP built-ins.
212 1.1.2.4 nathanw */
213 1.1.2.4 nathanw for (id = iopxs_devices; id->id_name != NULL; id++) {
214 1.1.2.4 nathanw ia.ia_name = id->id_name;
215 1.1.2.4 nathanw ia.ia_st = sc->sc_st;
216 1.1.2.4 nathanw ia.ia_sh = sc->sc_sh;
217 1.1.2.4 nathanw ia.ia_dmat = &sc->sc_local_dmat;
218 1.1.2.4 nathanw ia.ia_offset = id->id_offset;
219 1.1.2.4 nathanw ia.ia_size = id->id_size;
220 1.1.2.4 nathanw
221 1.1.2.4 nathanw (void) config_found(&sc->sc_dev, &ia, i80321_iopxs_print);
222 1.1.2.4 nathanw }
223 1.1.2.4 nathanw
224 1.1.2.2 nathanw /*
225 1.1.2.2 nathanw * Attach the PCI bus.
226 1.1.2.2 nathanw */
227 1.1.2.2 nathanw preg = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, ATU_PCIXSR);
228 1.1.2.2 nathanw preg = PCIXSR_BUSNO(preg);
229 1.1.2.2 nathanw if (preg == 0xff)
230 1.1.2.2 nathanw preg = 0;
231 1.1.2.2 nathanw pba.pba_busname = "pci";
232 1.1.2.2 nathanw pba.pba_iot = &sc->sc_pci_iot;
233 1.1.2.2 nathanw pba.pba_memt = &sc->sc_pci_memt;
234 1.1.2.2 nathanw pba.pba_dmat = &sc->sc_pci_dmat;
235 1.1.2.2 nathanw pba.pba_pc = &sc->sc_pci_chipset;
236 1.1.2.2 nathanw pba.pba_bus = preg;
237 1.1.2.3 nathanw pba.pba_bridgetag = NULL;
238 1.1.2.2 nathanw pba.pba_intrswiz = 0; /* XXX what if busno != 0? */
239 1.1.2.2 nathanw pba.pba_intrtag = 0;
240 1.1.2.2 nathanw pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
241 1.1.2.2 nathanw PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
242 1.1.2.2 nathanw (void) config_found(&sc->sc_dev, &pba, i80321_pcibus_print);
243 1.1.2.2 nathanw }
244 1.1.2.2 nathanw
245 1.1.2.2 nathanw /*
246 1.1.2.4 nathanw * i80321_iopxs_print:
247 1.1.2.4 nathanw *
248 1.1.2.4 nathanw * Autoconfiguration cfprint routine when attaching
249 1.1.2.4 nathanw * to the "iopxs" device.
250 1.1.2.4 nathanw */
251 1.1.2.4 nathanw int
252 1.1.2.4 nathanw i80321_iopxs_print(void *aux, const char *pnp)
253 1.1.2.4 nathanw {
254 1.1.2.4 nathanw
255 1.1.2.4 nathanw return (QUIET);
256 1.1.2.4 nathanw }
257 1.1.2.4 nathanw
258 1.1.2.4 nathanw /*
259 1.1.2.2 nathanw * i80321_pcibus_print:
260 1.1.2.2 nathanw *
261 1.1.2.2 nathanw * Autoconfiguration cfprint routine when attaching
262 1.1.2.2 nathanw * to the "pcibus" attribute.
263 1.1.2.2 nathanw */
264 1.1.2.2 nathanw int
265 1.1.2.2 nathanw i80321_pcibus_print(void *aux, const char *pnp)
266 1.1.2.2 nathanw {
267 1.1.2.2 nathanw struct pcibus_attach_args *pba = aux;
268 1.1.2.2 nathanw
269 1.1.2.2 nathanw if (pnp)
270 1.1.2.2 nathanw printf("%s at %s", pba->pba_busname, pnp);
271 1.1.2.2 nathanw
272 1.1.2.2 nathanw printf(" bus %d", pba->pba_bus);
273 1.1.2.2 nathanw
274 1.1.2.2 nathanw return (UNCONF);
275 1.1.2.2 nathanw }
276