i80321_mainbus.c revision 1.3 1 1.3 briggs /* $NetBSD: i80321_mainbus.c,v 1.3 2005/12/15 01:44:00 briggs Exp $ */
2 1.1 gavan
3 1.1 gavan /*
4 1.1 gavan * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
5 1.1 gavan * All rights reserved.
6 1.1 gavan *
7 1.1 gavan * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1 gavan *
9 1.1 gavan * Redistribution and use in source and binary forms, with or without
10 1.1 gavan * modification, are permitted provided that the following conditions
11 1.1 gavan * are met:
12 1.1 gavan * 1. Redistributions of source code must retain the above copyright
13 1.1 gavan * notice, this list of conditions and the following disclaimer.
14 1.1 gavan * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 gavan * notice, this list of conditions and the following disclaimer in the
16 1.1 gavan * documentation and/or other materials provided with the distribution.
17 1.1 gavan * 3. All advertising materials mentioning features or use of this software
18 1.1 gavan * must display the following acknowledgement:
19 1.1 gavan * This product includes software developed for the NetBSD Project by
20 1.1 gavan * Wasabi Systems, Inc.
21 1.1 gavan * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 gavan * or promote products derived from this software without specific prior
23 1.1 gavan * written permission.
24 1.1 gavan *
25 1.1 gavan * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 gavan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 gavan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 gavan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 gavan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 gavan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 gavan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 gavan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 gavan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 gavan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 gavan * POSSIBILITY OF SUCH DAMAGE.
36 1.1 gavan */
37 1.1 gavan
38 1.1 gavan /*
39 1.1 gavan * Iyonix front-end for the i80321 I/O Processor. We take care
40 1.1 gavan * of setting up the i80321 memory map, PCI interrupt routing, etc.,
41 1.1 gavan * which are all specific to the board the i80321 is wired up to.
42 1.1 gavan */
43 1.1 gavan
44 1.1 gavan #include <sys/cdefs.h>
45 1.3 briggs __KERNEL_RCSID(0, "$NetBSD: i80321_mainbus.c,v 1.3 2005/12/15 01:44:00 briggs Exp $");
46 1.1 gavan
47 1.1 gavan #include <sys/param.h>
48 1.1 gavan #include <sys/systm.h>
49 1.1 gavan #include <sys/device.h>
50 1.1 gavan
51 1.1 gavan #include <machine/autoconf.h>
52 1.1 gavan #include <machine/bus.h>
53 1.1 gavan
54 1.1 gavan #include <iyonix/iyonix/iyonixreg.h>
55 1.1 gavan #include <iyonix/iyonix/iyonixvar.h>
56 1.1 gavan
57 1.1 gavan #include <arm/xscale/i80321reg.h>
58 1.1 gavan #include <arm/xscale/i80321var.h>
59 1.1 gavan
60 1.1 gavan #include <dev/pci/pcireg.h>
61 1.1 gavan #include <dev/pci/pcidevs.h>
62 1.1 gavan
63 1.1 gavan int i80321_mainbus_match(struct device *, struct cfdata *, void *);
64 1.1 gavan void i80321_mainbus_attach(struct device *, struct device *, void *);
65 1.1 gavan
66 1.1 gavan CFATTACH_DECL(iopxs_mainbus, sizeof(struct i80321_softc),
67 1.1 gavan i80321_mainbus_match, i80321_mainbus_attach, NULL, NULL);
68 1.1 gavan
69 1.1 gavan /* There can be only one. */
70 1.1 gavan int i80321_mainbus_found;
71 1.1 gavan
72 1.1 gavan int
73 1.1 gavan i80321_mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
74 1.1 gavan {
75 1.1 gavan #if 0
76 1.1 gavan struct mainbus_attach_args *ma = aux;
77 1.1 gavan #endif
78 1.1 gavan
79 1.1 gavan if (i80321_mainbus_found)
80 1.1 gavan return (0);
81 1.1 gavan
82 1.1 gavan #if 1
83 1.1 gavan /* XXX Shoot arch/arm/mainbus in the head. */
84 1.1 gavan return (1);
85 1.1 gavan #else
86 1.1 gavan if (strcmp(cf->cf_name, ma->ma_name) == 0)
87 1.1 gavan return (1);
88 1.1 gavan
89 1.1 gavan return (0);
90 1.1 gavan #endif
91 1.1 gavan }
92 1.1 gavan
93 1.1 gavan void
94 1.1 gavan i80321_mainbus_attach(struct device *parent, struct device *self, void *aux)
95 1.1 gavan {
96 1.1 gavan struct i80321_softc *sc = (void *) self;
97 1.1 gavan pcireg_t b0u, b0l, b1u, b1l;
98 1.1 gavan paddr_t memstart;
99 1.1 gavan psize_t memsize;
100 1.1 gavan
101 1.1 gavan i80321_mainbus_found = 1;
102 1.1 gavan
103 1.1 gavan /*
104 1.1 gavan * Fill in the space tag for the i80321's own devices,
105 1.1 gavan * and hand-craft the space handle for it (the device
106 1.1 gavan * was mapped during early bootstrap).
107 1.1 gavan */
108 1.1 gavan i80321_bs_init(&i80321_bs_tag, sc);
109 1.1 gavan sc->sc_st = &i80321_bs_tag;
110 1.1 gavan sc->sc_sh = IYONIX_80321_VBASE;
111 1.1 gavan
112 1.1 gavan /*
113 1.1 gavan * Slice off a subregion for the Memory Controller -- we need it
114 1.1 gavan * here in order read the memory size.
115 1.1 gavan */
116 1.1 gavan if (bus_space_subregion(sc->sc_st, sc->sc_sh, VERDE_MCU_BASE,
117 1.1 gavan VERDE_MCU_SIZE, &sc->sc_mcu_sh))
118 1.1 gavan panic("%s: unable to subregion MCU registers",
119 1.1 gavan sc->sc_dev.dv_xname);
120 1.1 gavan
121 1.1 gavan if (bus_space_subregion(sc->sc_st, sc->sc_sh, VERDE_ATU_BASE,
122 1.1 gavan VERDE_ATU_SIZE, &sc->sc_atu_sh))
123 1.1 gavan panic("%s: unable to subregion ATU registers",
124 1.1 gavan sc->sc_dev.dv_xname);
125 1.1 gavan
126 1.1 gavan /*
127 1.1 gavan * We have mapped the PCI I/O windows in the early bootstrap phase.
128 1.1 gavan */
129 1.1 gavan sc->sc_iow_vaddr = IYONIX_IOW_VBASE;
130 1.1 gavan
131 1.1 gavan /*
132 1.1 gavan * Check the configuration of the ATU to see if another BIOS
133 1.1 gavan * has configured us. If a PC BIOS didn't configured us, then
134 1.1 gavan * BAR0 is 00000000.0000000c and BAR1 is 00000000.8000000c. If
135 1.1 gavan * a BIOS has configured us, at least one of those should be
136 1.1 gavan * different.
137 1.1 gavan */
138 1.1 gavan b0l = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, PCI_MAPREG_START+0x0);
139 1.1 gavan b0u = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, PCI_MAPREG_START+0x4);
140 1.1 gavan b1l = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, PCI_MAPREG_START+0x8);
141 1.1 gavan b1u = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, PCI_MAPREG_START+0xc);
142 1.1 gavan
143 1.1 gavan if ((b0u != b1u) || (b0l != 0x0000000c) || (b1l != 0x8000000cU))
144 1.1 gavan sc->sc_is_host = 0;
145 1.1 gavan else
146 1.1 gavan sc->sc_is_host = 1;
147 1.1 gavan
148 1.1 gavan sc->sc_is_host = 1;
149 1.1 gavan
150 1.1 gavan aprint_naive(": i80321 I/O Processor\n");
151 1.1 gavan aprint_normal(": i80321 I/O Processor, acting as PCI %s\n",
152 1.1 gavan sc->sc_is_host ? "host" : "slave");
153 1.1 gavan
154 1.1 gavan i80321_sdram_bounds(sc->sc_st, sc->sc_mcu_sh, &memstart, &memsize);
155 1.1 gavan
156 1.1 gavan /*
157 1.1 gavan * We set up the Inbound Windows as follows:
158 1.1 gavan *
159 1.1 gavan * 0 Access to i80321 PMMRs
160 1.1 gavan *
161 1.1 gavan * 1 Reserve space for private devices
162 1.1 gavan *
163 1.1 gavan * 2 RAM access
164 1.1 gavan *
165 1.1 gavan * 3 Unused.
166 1.1 gavan *
167 1.1 gavan * This chunk needs to be customized for each IOP321 application.
168 1.1 gavan */
169 1.1 gavan
170 1.1 gavan if (sc->sc_is_host) {
171 1.1 gavan /* Map PCI:Local 1:1. */
172 1.1 gavan
173 1.1 gavan sc->sc_iwin[1].iwin_base_lo = VERDE_OUT_XLATE_MEM_WIN0_BASE |
174 1.1 gavan PCI_MAPREG_MEM_PREFETCHABLE_MASK |
175 1.1 gavan PCI_MAPREG_MEM_TYPE_64BIT;
176 1.1 gavan sc->sc_iwin[1].iwin_base_hi = 0;
177 1.1 gavan } else {
178 1.1 gavan sc->sc_iwin[1].iwin_base_lo = 0;
179 1.1 gavan sc->sc_iwin[1].iwin_base_hi = 0;
180 1.1 gavan }
181 1.1 gavan sc->sc_iwin[1].iwin_xlate = VERDE_OUT_XLATE_MEM_WIN0_BASE;
182 1.1 gavan sc->sc_iwin[1].iwin_size = VERDE_OUT_XLATE_MEM_WIN_SIZE;
183 1.1 gavan
184 1.1 gavan if (sc->sc_is_host) {
185 1.1 gavan sc->sc_iwin[2].iwin_base_lo = memstart |
186 1.1 gavan PCI_MAPREG_MEM_PREFETCHABLE_MASK |
187 1.1 gavan PCI_MAPREG_MEM_TYPE_64BIT;
188 1.1 gavan sc->sc_iwin[2].iwin_base_hi = 0;
189 1.1 gavan } else {
190 1.1 gavan sc->sc_iwin[2].iwin_base_lo = 0;
191 1.1 gavan sc->sc_iwin[2].iwin_base_hi = 0;
192 1.1 gavan }
193 1.1 gavan sc->sc_iwin[2].iwin_xlate = memstart;
194 1.1 gavan sc->sc_iwin[2].iwin_size = memsize;
195 1.1 gavan
196 1.1 gavan if (sc->sc_is_host) {
197 1.1 gavan sc->sc_iwin[3].iwin_base_lo = 0 |
198 1.1 gavan PCI_MAPREG_MEM_PREFETCHABLE_MASK |
199 1.1 gavan PCI_MAPREG_MEM_TYPE_64BIT;
200 1.1 gavan } else {
201 1.1 gavan sc->sc_iwin[3].iwin_base_lo = 0;
202 1.1 gavan }
203 1.1 gavan sc->sc_iwin[3].iwin_base_hi = 0;
204 1.1 gavan sc->sc_iwin[3].iwin_xlate = 0;
205 1.1 gavan sc->sc_iwin[3].iwin_size = 0;
206 1.1 gavan
207 1.1 gavan /*
208 1.1 gavan * We set up the Outbound Windows as follows:
209 1.1 gavan *
210 1.1 gavan * 0 Access to private PCI space.
211 1.1 gavan *
212 1.1 gavan * 1 Unused.
213 1.1 gavan */
214 1.1 gavan sc->sc_owin[0].owin_xlate_lo =
215 1.1 gavan PCI_MAPREG_MEM_ADDR(sc->sc_iwin[1].iwin_base_lo);
216 1.1 gavan sc->sc_owin[0].owin_xlate_hi = sc->sc_iwin[1].iwin_base_hi;
217 1.1 gavan
218 1.1 gavan /*
219 1.1 gavan * Set the Secondary Outbound I/O window to map
220 1.1 gavan * to PCI address 0 for all 64K of the I/O space.
221 1.1 gavan */
222 1.1 gavan sc->sc_ioout_xlate = 0;
223 1.3 briggs sc->sc_ioout_xlate_offset = 0;
224 1.1 gavan
225 1.1 gavan /*
226 1.1 gavan * Initialize the interrupt part of our PCI chipset tag.
227 1.1 gavan */
228 1.1 gavan iyonix_pci_init(&sc->sc_pci_chipset, sc);
229 1.1 gavan
230 1.1 gavan i80321_attach(sc);
231 1.1 gavan }
232