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