i80312_mainbus.c revision 1.1 1 /* $NetBSD: i80312_mainbus.c,v 1.1 2001/11/09 03:31:37 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * IQ80310 front-end for the i80312 Companion I/O chip. We take care
40 * of setting up the i80312 memory map, PCI interrupt routing, etc.,
41 * which are all specific to the board the i80312 is wired up to.
42 */
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/device.h>
47
48 #include <machine/autoconf.h>
49 #include <machine/bus.h>
50
51 #include <evbarm/iq80310/iq80310reg.h>
52
53 #include <arm/xscale/i80312reg.h>
54 #include <arm/xscale/i80312var.h>
55
56 #include <dev/pci/pcireg.h>
57 #include <dev/pci/pcidevs.h>
58
59 int i80312_mainbus_match(struct device *, struct cfdata *, void *);
60 void i80312_mainbus_attach(struct device *, struct device *, void *);
61
62 struct cfattach iopxs_mainbus_ca = {
63 sizeof(struct i80312_softc), i80312_mainbus_match,
64 i80312_mainbus_attach,
65 };
66
67 /* There can be only one. */
68 int i80312_mainbus_found;
69
70 int
71 i80312_mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
72 {
73 #if 0
74 struct mainbus_attach_args *ma = aux;
75 #endif
76
77 if (i80312_mainbus_found)
78 return (0);
79
80 #if 1
81 /* XXX Shoot arch/arm/mainbus in the head. */
82 return (1);
83 #else
84 if (strcmp(cf->cf_driver->cd_name, ma->ma_name) == 0)
85 return (1);
86
87 return (0);
88 #endif
89 }
90
91 void
92 i80312_mainbus_attach(struct device *parent, struct device *self, void *aux)
93 {
94 struct i80312_softc *sc = (void *) self;
95 paddr_t memstart;
96 psize_t memsize;
97
98 i80312_mainbus_found = 1;
99
100 /*
101 * Fill in the space tag for the i80312's own devices,
102 * and hand-craft the space handle for it (the device
103 * was mapped during early bootstrap).
104 */
105 i80312_bs_init(&i80312_bs_tag, sc);
106 sc->sc_st = &i80312_bs_tag;
107 sc->sc_sh = IQ80310_80312_VBASE;
108
109 /*
110 * We have mapped the the PCI I/O windows in the early
111 * bootstrap phase.
112 */
113 sc->sc_piow_vaddr = IQ80310_PIOW_VBASE;
114 sc->sc_siow_vaddr = IQ80310_SIOW_VBASE;
115
116 sc->sc_is_host = CPLD_READ(IQ80310_BACKPLANE_DET) & 1;
117
118 printf(": i80312 Companion I/O, acting as PCI %s\n",
119 sc->sc_is_host ? "host" : "slave");
120
121 /*
122 * Set the subsystem vendor/device IDs to "Cyclone" "PCI-700",
123 * which is the board-specific identification.
124 */
125 bus_space_write_4(sc->sc_st, sc->sc_sh,
126 I80312_ATU_BASE + PCI_SUBSYS_ID_REG,
127 PCI_ID_CODE(PCI_VENDOR_CYCLONE, PCI_PRODUCT_CYCLONE_PCI_700));
128
129 i80312_sdram_bounds(sc->sc_st, sc->sc_sh, &memstart, &memsize);
130
131 /*
132 * Set the Primary Inbound window xlate base to the start
133 * of RAM. Set the size to 4K, for now. Just for testing
134 * in a host. This obviously has to be customized for each
135 * IQ310 application.
136 *
137 * Note the first 4K of the window is reserved for the
138 * messaging unit, so no RAM is going to be accessed here.
139 *
140 * ..unless we're a host -- in which case, make it work like
141 * the Secondary Inbound window (below).
142 */
143 if (sc->sc_is_host) {
144 sc->sc_pin_base = memstart;
145 sc->sc_pin_xlate = memstart;
146 sc->sc_pin_size = memsize;
147 } else {
148 sc->sc_pin_xlate = memstart;
149 sc->sc_pin_size = 4096;
150 }
151
152 /*
153 * Map the Secondary Inbound window 1:1 with local RAM.
154 */
155 sc->sc_sin_base = memstart;
156 sc->sc_sin_xlate = memstart;
157 sc->sc_sin_size = memsize;
158
159 /*
160 * XXX Don't use the Primary Outbound windows, for now.
161 */
162 sc->sc_pmemout_size = 0;
163 sc->sc_pioout_size = 0;
164
165 /*
166 * Set the Secondary Outbound Memory window to map 1:1
167 * PCI:Local.
168 */
169 sc->sc_smemout_base = I80312_PCI_XLATE_SMW_BASE;
170 sc->sc_smemout_size = I80312_PCI_XLATE_MSIZE;
171
172 /*
173 * Set the Secondary Outbound I/O window to map
174 * to PCI address 0 for all 64K of the I/O space.
175 */
176 sc->sc_sioout_base = 0;
177 sc->sc_sioout_size = I80312_PCI_XLATE_IOSIZE;
178
179 /*
180 * XXX For now, suppress all secondary IDSELs (thus making all
181 * devices from S_AD[11]..S_AD[25] private).
182 */
183 sc->sc_sisr = 0x3ff;
184
185 /*
186 * XXX For now, make the entire Secondary Outbound address
187 * spaces private.
188 */
189 sc->sc_privio_base = sc->sc_sioout_base;
190 sc->sc_privio_size = sc->sc_sioout_size;
191 sc->sc_privmem_base = sc->sc_smemout_base;
192 sc->sc_privmem_size = sc->sc_smemout_size;
193
194 i80312_attach(sc);
195 }
196