ixp12x0.c revision 1.2.4.3 1 1.2.4.3 jdolecek /* $NetBSD: ixp12x0.c,v 1.2.4.3 2002/10/10 18:31:53 jdolecek Exp $ */
2 1.2.4.2 jdolecek /*
3 1.2.4.2 jdolecek * Copyright (c) 2002
4 1.2.4.2 jdolecek * Ichiro FUKUHARA <ichiro (at) ichiro.org>.
5 1.2.4.2 jdolecek * All rights reserved.
6 1.2.4.2 jdolecek *
7 1.2.4.2 jdolecek * Redistribution and use in source and binary forms, with or without
8 1.2.4.2 jdolecek * modification, are permitted provided that the following conditions
9 1.2.4.2 jdolecek * are met:
10 1.2.4.2 jdolecek * 1. Redistributions of source code must retain the above copyright
11 1.2.4.2 jdolecek * notice, this list of conditions and the following disclaimer.
12 1.2.4.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.4.2 jdolecek * notice, this list of conditions and the following disclaimer in the
14 1.2.4.2 jdolecek * documentation and/or other materials provided with the distribution.
15 1.2.4.2 jdolecek * 3. All advertising materials mentioning features or use of this software
16 1.2.4.2 jdolecek * must display the following acknowledgement:
17 1.2.4.2 jdolecek * This product includes software developed by Ichiro FUKUHARA.
18 1.2.4.2 jdolecek * 4. The name of the company nor the name of the author may be used to
19 1.2.4.2 jdolecek * endorse or promote products derived from this software without specific
20 1.2.4.2 jdolecek * prior written permission.
21 1.2.4.2 jdolecek *
22 1.2.4.2 jdolecek * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
23 1.2.4.2 jdolecek * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.2.4.2 jdolecek * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.2.4.2 jdolecek * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
26 1.2.4.2 jdolecek * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.2.4.2 jdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.2.4.2 jdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.2.4.2 jdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.2.4.2 jdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.2.4.2 jdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.2.4.2 jdolecek * SUCH DAMAGE.
33 1.2.4.2 jdolecek */
34 1.2.4.2 jdolecek
35 1.2.4.2 jdolecek #include <sys/param.h>
36 1.2.4.2 jdolecek #include <sys/systm.h>
37 1.2.4.2 jdolecek #include <sys/device.h>
38 1.2.4.2 jdolecek #include <uvm/uvm.h>
39 1.2.4.2 jdolecek
40 1.2.4.2 jdolecek #include <machine/bus.h>
41 1.2.4.2 jdolecek
42 1.2.4.2 jdolecek #include <arm/ixp12x0/ixp12x0reg.h>
43 1.2.4.2 jdolecek #include <arm/ixp12x0/ixp12x0var.h>
44 1.2.4.2 jdolecek #include <arm/ixp12x0/ixp12x0_pcireg.h>
45 1.2.4.2 jdolecek
46 1.2.4.2 jdolecek int ixp12x0_pcibus_print(void *, const char *);
47 1.2.4.2 jdolecek
48 1.2.4.2 jdolecek static struct ixp12x0_softc *ixp12x0_softc;
49 1.2.4.2 jdolecek
50 1.2.4.2 jdolecek void
51 1.2.4.2 jdolecek ixp12x0_attach(sc)
52 1.2.4.2 jdolecek struct ixp12x0_softc *sc;
53 1.2.4.2 jdolecek {
54 1.2.4.2 jdolecek struct pcibus_attach_args pba;
55 1.2.4.2 jdolecek pcireg_t reg;
56 1.2.4.2 jdolecek
57 1.2.4.2 jdolecek ixp12x0_softc = sc;
58 1.2.4.2 jdolecek
59 1.2.4.2 jdolecek printf("\n");
60 1.2.4.2 jdolecek /*
61 1.2.4.2 jdolecek * Subregion for PCI Configuration Spase Registers
62 1.2.4.2 jdolecek */
63 1.2.4.2 jdolecek if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, 0,
64 1.2.4.2 jdolecek IXP12X0_PCI_SIZE, &sc->sc_pci_ioh))
65 1.2.4.3 jdolecek panic("%s: unable to subregion PCI registers",
66 1.2.4.2 jdolecek sc->sc_dev.dv_xname);
67 1.2.4.2 jdolecek /*
68 1.2.4.2 jdolecek * PCI bus reset
69 1.2.4.2 jdolecek */
70 1.2.4.2 jdolecek /* XXX assert PCI reset Mode */
71 1.2.4.2 jdolecek reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
72 1.2.4.2 jdolecek SA_CONTROL) &~ SA_CONTROL_PNR;
73 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
74 1.2.4.2 jdolecek SA_CONTROL, reg);
75 1.2.4.2 jdolecek DELAY(10);
76 1.2.4.2 jdolecek
77 1.2.4.2 jdolecek /* XXX Disable door bell and outbound interrupt */
78 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
79 1.2.4.2 jdolecek PCI_CAP_PTR, 0xc);
80 1.2.4.2 jdolecek /* Disable door bell int to PCI */
81 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
82 1.2.4.2 jdolecek DBELL_PCI_MASK, 0x0);
83 1.2.4.2 jdolecek /* Disable door bell int to SA-core */
84 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
85 1.2.4.2 jdolecek DBELL_SA_MASK, 0x0);
86 1.2.4.2 jdolecek
87 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
88 1.2.4.2 jdolecek PCI_ADDR_EXT, 0);
89 1.2.4.2 jdolecek
90 1.2.4.2 jdolecek /* XXX Negate PCI reset */
91 1.2.4.2 jdolecek reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
92 1.2.4.2 jdolecek SA_CONTROL) | SA_CONTROL_PNR;
93 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
94 1.2.4.2 jdolecek SA_CONTROL, reg);
95 1.2.4.2 jdolecek DELAY(10);
96 1.2.4.2 jdolecek /*
97 1.2.4.2 jdolecek * specify window size of memory access and SDRAM.
98 1.2.4.2 jdolecek */
99 1.2.4.2 jdolecek reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
100 1.2.4.2 jdolecek IXP_PCI_MEM_BAR) | IXP1200_PCI_MEM_BAR;
101 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
102 1.2.4.2 jdolecek IXP_PCI_MEM_BAR, reg);
103 1.2.4.2 jdolecek
104 1.2.4.2 jdolecek reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
105 1.2.4.2 jdolecek IXP_PCI_IO_BAR) | IXP1200_PCI_IO_BAR;
106 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
107 1.2.4.2 jdolecek IXP_PCI_IO_BAR, reg);
108 1.2.4.2 jdolecek
109 1.2.4.2 jdolecek reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
110 1.2.4.2 jdolecek IXP_PCI_DRAM_BAR) | IXP1200_PCI_DRAM_BAR;
111 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
112 1.2.4.2 jdolecek IXP_PCI_DRAM_BAR, reg);
113 1.2.4.2 jdolecek
114 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
115 1.2.4.2 jdolecek CSR_BASE_ADDR_MASK, CSR_BASE_ADDR_MASK_1M);
116 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
117 1.2.4.2 jdolecek DRAM_BASE_ADDR_MASK, DRAM_BASE_ADDR_MASK_256MB);
118 1.2.4.2 jdolecek
119 1.2.4.2 jdolecek #if DEBUG
120 1.2.4.2 jdolecek printf("IXP_PCI_MEM_BAR = 0x%08x\nIXP_PCI_IO_BAR = 0x%08x\nIXP_PCI_DRAM_BAR = 0x%08x\nCSR_BASE_ADDR_MASK = 0x%08x\n",
121 1.2.4.2 jdolecek bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_MEM_BAR),
122 1.2.4.2 jdolecek bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_IO_BAR),
123 1.2.4.2 jdolecek bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_DRAM_BAR),
124 1.2.4.2 jdolecek bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, DRAM_BASE_ADDR_MASK));
125 1.2.4.2 jdolecek #endif
126 1.2.4.2 jdolecek /* Initialize complete */
127 1.2.4.2 jdolecek reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
128 1.2.4.2 jdolecek SA_CONTROL) | 0x1;
129 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
130 1.2.4.2 jdolecek SA_CONTROL, reg);
131 1.2.4.2 jdolecek #if DEBUG
132 1.2.4.2 jdolecek printf("SA_CONTROL = 0x%08x\n",
133 1.2.4.2 jdolecek bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, SA_CONTROL));
134 1.2.4.2 jdolecek #endif
135 1.2.4.2 jdolecek /*
136 1.2.4.2 jdolecek * Enable bus mastering and I/O,memory access
137 1.2.4.2 jdolecek */
138 1.2.4.2 jdolecek /* host only */
139 1.2.4.2 jdolecek reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
140 1.2.4.2 jdolecek PCI_COMMAND_STATUS_REG) |
141 1.2.4.2 jdolecek PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
142 1.2.4.2 jdolecek PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_INVALIDATE_ENABLE;
143 1.2.4.2 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
144 1.2.4.2 jdolecek PCI_COMMAND_STATUS_REG, reg);
145 1.2.4.2 jdolecek #if DEBUG
146 1.2.4.2 jdolecek printf("PCI_COMMAND_STATUS_REG = 0x%08x\n",
147 1.2.4.2 jdolecek bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, PCI_COMMAND_STATUS_REG));
148 1.2.4.2 jdolecek #endif
149 1.2.4.2 jdolecek /*
150 1.2.4.2 jdolecek * Initialize the bus space and DMA tags and the PCI chipset tag.
151 1.2.4.2 jdolecek */
152 1.2.4.2 jdolecek ixp12x0_io_bs_init(&sc->ia_pci_iot, sc);
153 1.2.4.2 jdolecek ixp12x0_mem_bs_init(&sc->ia_pci_memt, sc);
154 1.2.4.2 jdolecek ixp12x0_pci_init(&sc->ia_pci_chipset, sc);
155 1.2.4.2 jdolecek ixp12x0_pci_dma_init(&sc->ia_pci_dmat, sc);
156 1.2.4.2 jdolecek
157 1.2.4.2 jdolecek /*
158 1.2.4.2 jdolecek * Attach the PCI bus.
159 1.2.4.2 jdolecek */
160 1.2.4.2 jdolecek pba.pba_busname = "pci";
161 1.2.4.2 jdolecek pba.pba_pc = &sc->ia_pci_chipset;
162 1.2.4.2 jdolecek pba.pba_iot = &sc->ia_pci_iot;
163 1.2.4.2 jdolecek pba.pba_memt = &sc->ia_pci_memt;
164 1.2.4.2 jdolecek pba.pba_dmat = &sc->ia_pci_dmat;
165 1.2.4.2 jdolecek pba.pba_bus = 0; /* bus number = 0 */
166 1.2.4.2 jdolecek pba.pba_intrswiz = 0; /* XXX */
167 1.2.4.2 jdolecek pba.pba_intrtag = 0;
168 1.2.4.2 jdolecek pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
169 1.2.4.2 jdolecek PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
170 1.2.4.2 jdolecek (void) config_found(&sc->sc_dev, &pba, ixp12x0_pcibus_print);
171 1.2.4.2 jdolecek }
172 1.2.4.2 jdolecek
173 1.2.4.2 jdolecek int
174 1.2.4.2 jdolecek ixp12x0_pcibus_print(void *aux, const char *pnp)
175 1.2.4.2 jdolecek {
176 1.2.4.2 jdolecek struct pcibus_attach_args *pba = aux;
177 1.2.4.2 jdolecek
178 1.2.4.2 jdolecek if (pnp)
179 1.2.4.2 jdolecek printf("%s at %s", pba->pba_busname, pnp);
180 1.2.4.2 jdolecek
181 1.2.4.2 jdolecek printf(" bus %d", pba->pba_bus);
182 1.2.4.2 jdolecek
183 1.2.4.2 jdolecek return (UNCONF);
184 1.2.4.2 jdolecek }
185 1.2.4.2 jdolecek
186 1.2.4.2 jdolecek /*
187 1.2.4.2 jdolecek * IXP12x0 specific I/O registers mapping table
188 1.2.4.2 jdolecek */
189 1.2.4.2 jdolecek static struct pmap_ent map_tbl_ixp12x0[] = {
190 1.2.4.2 jdolecek { "StrongARM System and Peripheral Registers",
191 1.2.4.2 jdolecek IXP12X0_SYS_VBASE, IXP12X0_SYS_HWBASE,
192 1.2.4.2 jdolecek IXP12X0_SYS_SIZE,
193 1.2.4.2 jdolecek VM_PROT_READ|VM_PROT_WRITE,
194 1.2.4.2 jdolecek PTE_NOCACHE, },
195 1.2.4.2 jdolecek
196 1.2.4.2 jdolecek { "PCI Registers Accessible Through StrongARM Core",
197 1.2.4.2 jdolecek IXP12X0_PCI_VBASE, IXP12X0_PCI_HWBASE,
198 1.2.4.2 jdolecek IXP12X0_PCI_SIZE,
199 1.2.4.2 jdolecek VM_PROT_READ|VM_PROT_WRITE,
200 1.2.4.2 jdolecek PTE_NOCACHE, },
201 1.2.4.2 jdolecek
202 1.2.4.2 jdolecek { "PCI Registers Accessible Through I/O Cycle Access",
203 1.2.4.2 jdolecek IXP12X0_PCI_IO_VBASE, IXP12X0_PCI_IO_HWBASE,
204 1.2.4.2 jdolecek IXP12X0_PCI_IO_SIZE,
205 1.2.4.2 jdolecek VM_PROT_READ|VM_PROT_WRITE,
206 1.2.4.2 jdolecek PTE_NOCACHE, },
207 1.2.4.2 jdolecek
208 1.2.4.2 jdolecek { "PCI Registers Accessible Through Memory Cycle Access",
209 1.2.4.2 jdolecek IXP12X0_PCI_MEM_VBASE, IXP12X0_PCI_MEM_VBASE,
210 1.2.4.2 jdolecek IXP12X0_PCI_MEM_SIZE,
211 1.2.4.2 jdolecek VM_PROT_READ|VM_PROT_WRITE,
212 1.2.4.2 jdolecek PTE_NOCACHE, },
213 1.2.4.2 jdolecek
214 1.2.4.2 jdolecek { "PCI Type0 Configuration Space",
215 1.2.4.2 jdolecek IXP12X0_PCI_TYPE0_VBASE, IXP12X0_PCI_TYPE0_VBASE,
216 1.2.4.2 jdolecek IXP12X0_PCI_TYPEX_SIZE,
217 1.2.4.2 jdolecek VM_PROT_READ|VM_PROT_WRITE,
218 1.2.4.2 jdolecek PTE_NOCACHE, },
219 1.2.4.2 jdolecek
220 1.2.4.2 jdolecek { "PCI Type1 Configuration Space",
221 1.2.4.2 jdolecek IXP12X0_PCI_TYPE1_VBASE, IXP12X0_PCI_TYPE1_VBASE,
222 1.2.4.2 jdolecek IXP12X0_PCI_TYPEX_SIZE,
223 1.2.4.2 jdolecek VM_PROT_READ|VM_PROT_WRITE,
224 1.2.4.2 jdolecek PTE_NOCACHE, },
225 1.2.4.2 jdolecek
226 1.2.4.2 jdolecek { NULL, 0, 0, 0, 0, 0 },
227 1.2.4.2 jdolecek };
228 1.2.4.2 jdolecek
229 1.2.4.2 jdolecek /*
230 1.2.4.2 jdolecek * mapping virtual memories
231 1.2.4.2 jdolecek */
232 1.2.4.2 jdolecek void
233 1.2.4.2 jdolecek ixp12x0_pmap_chunk_table(vaddr_t l1pt, struct pmap_ent* m)
234 1.2.4.2 jdolecek {
235 1.2.4.2 jdolecek int loop;
236 1.2.4.2 jdolecek
237 1.2.4.2 jdolecek loop = 0;
238 1.2.4.2 jdolecek while (m[loop].msg) {
239 1.2.4.2 jdolecek printf("mapping %s...\n", m[loop].msg);
240 1.2.4.2 jdolecek pmap_map_chunk(l1pt, m[loop].va, m[loop].pa,
241 1.2.4.2 jdolecek m[loop].sz, m[loop].prot, m[loop].cache);
242 1.2.4.2 jdolecek ++loop;
243 1.2.4.2 jdolecek }
244 1.2.4.2 jdolecek }
245 1.2.4.2 jdolecek
246 1.2.4.2 jdolecek /*
247 1.2.4.2 jdolecek * mapping I/O registers
248 1.2.4.2 jdolecek */
249 1.2.4.2 jdolecek void
250 1.2.4.2 jdolecek ixp12x0_pmap_io_reg(vaddr_t l1pt)
251 1.2.4.2 jdolecek {
252 1.2.4.2 jdolecek ixp12x0_pmap_chunk_table(l1pt, map_tbl_ixp12x0);
253 1.2.4.2 jdolecek }
254 1.2.4.2 jdolecek
255 1.2.4.2 jdolecek void
256 1.2.4.2 jdolecek ixp12x0_reset(void)
257 1.2.4.2 jdolecek {
258 1.2.4.2 jdolecek bus_space_write_4(ixp12x0_softc->sc_iot, ixp12x0_softc->sc_pci_ioh,
259 1.2.4.2 jdolecek IXPPCI_IXP1200_RESET, RESET_FULL);
260 1.2.4.2 jdolecek }
261