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