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