mainbus.c revision 1.6.2.3 1 1.6.2.3 nathanw /* $NetBSD: mainbus.c,v 1.6.2.3 2002/01/11 23:37:54 nathanw Exp $ */
2 1.6.2.2 nathanw
3 1.6.2.2 nathanw /*-
4 1.6.2.2 nathanw * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.6.2.2 nathanw * All rights reserved.
6 1.6.2.2 nathanw *
7 1.6.2.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.6.2.2 nathanw * by Jason R. Thorpe.
9 1.6.2.2 nathanw *
10 1.6.2.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.6.2.2 nathanw * modification, are permitted provided that the following conditions
12 1.6.2.2 nathanw * are met:
13 1.6.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.6.2.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.6.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.6.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.6.2.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.6.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.6.2.2 nathanw * must display the following acknowledgement:
20 1.6.2.2 nathanw * This product includes software developed by the NetBSD
21 1.6.2.2 nathanw * Foundation, Inc. and its contributors.
22 1.6.2.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.6.2.2 nathanw * contributors may be used to endorse or promote products derived
24 1.6.2.2 nathanw * from this software without specific prior written permission.
25 1.6.2.2 nathanw *
26 1.6.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.6.2.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.6.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.6.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.6.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.6.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.6.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.6.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.6.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.6.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.6.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.6.2.2 nathanw */
38 1.6.2.2 nathanw
39 1.6.2.2 nathanw #include "opt_algor_p4032.h"
40 1.6.2.2 nathanw #include "opt_algor_p5064.h"
41 1.6.2.2 nathanw #include "opt_algor_p6032.h"
42 1.6.2.2 nathanw
43 1.6.2.2 nathanw #include "opt_pci.h"
44 1.6.2.2 nathanw
45 1.6.2.2 nathanw #include <sys/param.h>
46 1.6.2.2 nathanw #include <sys/systm.h>
47 1.6.2.2 nathanw #include <sys/conf.h>
48 1.6.2.2 nathanw #include <sys/reboot.h>
49 1.6.2.2 nathanw #include <sys/device.h>
50 1.6.2.2 nathanw #include <sys/malloc.h>
51 1.6.2.2 nathanw #include <sys/extent.h>
52 1.6.2.2 nathanw
53 1.6.2.2 nathanw #include <machine/bus.h>
54 1.6.2.2 nathanw #include <machine/autoconf.h>
55 1.6.2.2 nathanw
56 1.6.2.2 nathanw #include <mips/cache.h>
57 1.6.2.2 nathanw
58 1.6.2.2 nathanw #include <dev/pci/pcivar.h>
59 1.6.2.2 nathanw #include <dev/pci/pciconf.h>
60 1.6.2.2 nathanw
61 1.6.2.2 nathanw #if defined(PCI_NETBSD_CONFIGURE) && defined(PCI_NETBSD_ENABLE_IDE)
62 1.6.2.2 nathanw #if defined(ALGOR_P5064) || defined(ALGOR_P6032)
63 1.6.2.2 nathanw #include <dev/pci/pciide_piix_reg.h>
64 1.6.2.2 nathanw #endif /* ALGOR_P5064 || ALGOR_P6032 */
65 1.6.2.2 nathanw #endif /* PCI_NETBSD_CONFIGURE && PCI_NETBSD_ENABLE_IDE */
66 1.6.2.2 nathanw
67 1.6.2.2 nathanw #include "locators.h"
68 1.6.2.2 nathanw #include "pci.h"
69 1.6.2.2 nathanw
70 1.6.2.2 nathanw int mainbus_match(struct device *, struct cfdata *, void *);
71 1.6.2.2 nathanw void mainbus_attach(struct device *, struct device *, void *);
72 1.6.2.2 nathanw
73 1.6.2.2 nathanw struct cfattach mainbus_ca = {
74 1.6.2.2 nathanw sizeof(struct device), mainbus_match, mainbus_attach,
75 1.6.2.2 nathanw };
76 1.6.2.2 nathanw
77 1.6.2.2 nathanw int mainbus_print(void *, const char *);
78 1.6.2.2 nathanw int mainbus_submatch(struct device *, struct cfdata *, void *);
79 1.6.2.2 nathanw
80 1.6.2.2 nathanw /* There can be only one. */
81 1.6.2.2 nathanw int mainbus_found;
82 1.6.2.2 nathanw
83 1.6.2.2 nathanw struct mainbusdev {
84 1.6.2.2 nathanw const char *md_name;
85 1.6.2.2 nathanw bus_addr_t md_addr;
86 1.6.2.2 nathanw int md_irq;
87 1.6.2.2 nathanw };
88 1.6.2.2 nathanw
89 1.6.2.2 nathanw #if defined(ALGOR_P4032)
90 1.6.2.2 nathanw #include <algor/algor/algor_p4032reg.h>
91 1.6.2.2 nathanw #include <algor/algor/algor_p4032var.h>
92 1.6.2.2 nathanw
93 1.6.2.2 nathanw struct mainbusdev mainbusdevs[] = {
94 1.6.2.2 nathanw { "cpu", -1, -1 },
95 1.6.2.2 nathanw { "mcclock", P4032_RTC, P4032_IRQ_RTC },
96 1.6.2.2 nathanw { "com", P4032_COM1, P4032_IRQ_COM1 },
97 1.6.2.2 nathanw { "com", P4032_COM2, P4032_IRQ_COM2 },
98 1.6.2.2 nathanw { "lpt", P4032_LPT, P4032_IRQ_LPT },
99 1.6.2.2 nathanw { "pckbc", P4032_PCKBC, P4032_IRQ_PCKBC },
100 1.6.2.2 nathanw { "fdc", P4032_FDC, P4032_IRQ_FLOPPY },
101 1.6.2.2 nathanw { "vtpbc", P4032_V962PBC, -1 },
102 1.6.2.2 nathanw
103 1.6.2.2 nathanw { NULL, 0, 0 },
104 1.6.2.2 nathanw };
105 1.6.2.2 nathanw #endif /* ALGOR_P4032 */
106 1.6.2.2 nathanw
107 1.6.2.2 nathanw #if defined(ALGOR_P5064)
108 1.6.2.2 nathanw #include <algor/algor/algor_p5064reg.h>
109 1.6.2.2 nathanw #include <algor/algor/algor_p5064var.h>
110 1.6.2.2 nathanw
111 1.6.2.2 nathanw struct mainbusdev mainbusdevs[] = {
112 1.6.2.2 nathanw { "cpu", -1, -1 },
113 1.6.2.2 nathanw { "vtpbc", P5064_V360EPC, -1 },
114 1.6.2.2 nathanw
115 1.6.2.2 nathanw { NULL, 0, 0 },
116 1.6.2.2 nathanw };
117 1.6.2.2 nathanw #endif /* ALGOR_P5064 */
118 1.6.2.2 nathanw
119 1.6.2.2 nathanw #if defined(ALGOR_P6032)
120 1.6.2.2 nathanw #include <algor/algor/algor_p6032reg.h>
121 1.6.2.2 nathanw #include <algor/algor/algor_p6032var.h>
122 1.6.2.2 nathanw
123 1.6.2.2 nathanw struct mainbusdev mainbusdevs[] = {
124 1.6.2.2 nathanw { "cpu", -1, -1 },
125 1.6.2.2 nathanw { "bonito", BONITO_REG_BASE, -1 },
126 1.6.2.2 nathanw
127 1.6.2.2 nathanw { NULL, 0, 0 },
128 1.6.2.2 nathanw };
129 1.6.2.2 nathanw #endif /* ALGOR_P6032 */
130 1.6.2.2 nathanw
131 1.6.2.2 nathanw int
132 1.6.2.2 nathanw mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
133 1.6.2.2 nathanw {
134 1.6.2.2 nathanw
135 1.6.2.2 nathanw if (mainbus_found)
136 1.6.2.2 nathanw return (0);
137 1.6.2.2 nathanw
138 1.6.2.2 nathanw return (1);
139 1.6.2.2 nathanw }
140 1.6.2.2 nathanw
141 1.6.2.2 nathanw void
142 1.6.2.2 nathanw mainbus_attach(struct device *parent, struct device *self, void *aux)
143 1.6.2.2 nathanw {
144 1.6.2.2 nathanw struct mainbus_attach_args ma;
145 1.6.2.2 nathanw struct mainbusdev *md;
146 1.6.2.2 nathanw bus_space_tag_t st;
147 1.6.2.2 nathanw #if defined(PCI_NETBSD_CONFIGURE)
148 1.6.2.2 nathanw struct extent *ioext, *memext;
149 1.6.2.2 nathanw pci_chipset_tag_t pc;
150 1.6.2.2 nathanw #if defined(PCI_NETBSD_ENABLE_IDE)
151 1.6.2.2 nathanw pcitag_t idetag;
152 1.6.2.2 nathanw pcireg_t idetim;
153 1.6.2.2 nathanw #endif
154 1.6.2.2 nathanw #endif
155 1.6.2.2 nathanw
156 1.6.2.2 nathanw mainbus_found = 1;
157 1.6.2.2 nathanw
158 1.6.2.2 nathanw printf("\n");
159 1.6.2.2 nathanw
160 1.6.2.2 nathanw #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
161 1.6.2.2 nathanw #if defined(ALGOR_P4032)
162 1.6.2.2 nathanw /*
163 1.6.2.2 nathanw * Reserve the bottom 64K of the I/O space for ISA devices.
164 1.6.2.2 nathanw */
165 1.6.2.2 nathanw ioext = extent_create("pciio", 0x00010000, 0x000effff,
166 1.6.2.2 nathanw M_DEVBUF, NULL, 0, EX_NOWAIT);
167 1.6.2.2 nathanw memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
168 1.6.2.2 nathanw M_DEVBUF, NULL, 0, EX_NOWAIT);
169 1.6.2.2 nathanw
170 1.6.2.2 nathanw pc = &p4032_configuration.ac_pc;
171 1.6.2.2 nathanw #elif defined(ALGOR_P5064)
172 1.6.2.2 nathanw /*
173 1.6.2.2 nathanw * Reserve the bottom 512K of the I/O space for ISA devices.
174 1.6.2.2 nathanw * According to the PMON sources, this is a work-around for
175 1.6.2.2 nathanw * a bug in the ISA bridge.
176 1.6.2.2 nathanw */
177 1.6.2.2 nathanw ioext = extent_create("pciio", 0x00080000, 0x00ffffff,
178 1.6.2.2 nathanw M_DEVBUF, NULL, 0, EX_NOWAIT);
179 1.6.2.2 nathanw memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
180 1.6.2.2 nathanw M_DEVBUF, NULL, 0, EX_NOWAIT);
181 1.6.2.2 nathanw
182 1.6.2.2 nathanw pc = &p5064_configuration.ac_pc;
183 1.6.2.2 nathanw #if defined(PCI_NETBSD_ENABLE_IDE)
184 1.6.2.2 nathanw idetag = pci_make_tag(pc, 0, 2, 1);
185 1.6.2.2 nathanw #endif
186 1.6.2.2 nathanw #elif defined(ALGOR_P6032)
187 1.6.2.2 nathanw /*
188 1.6.2.2 nathanw * Reserve the bottom 64K of the I/O space for ISA devices.
189 1.6.2.2 nathanw */
190 1.6.2.2 nathanw ioext = extent_create("pciio", 0x00010000, 0x000effff,
191 1.6.2.2 nathanw M_DEVBUF, NULL, 0, EX_NOWAIT);
192 1.6.2.2 nathanw memext = extent_create("pcimem", 0x01000000, 0x0affffff,
193 1.6.2.2 nathanw M_DEVBUF, NULL, 0, EX_NOWAIT);
194 1.6.2.2 nathanw
195 1.6.2.2 nathanw pc = &p6032_configuration.ac_pc;
196 1.6.2.2 nathanw #if defined(PCI_NETBSD_ENABLE_IDE)
197 1.6.2.2 nathanw idetag = pci_make_tag(pc, 0, 17, 1);
198 1.6.2.2 nathanw #endif
199 1.6.2.2 nathanw #endif /* ALGOR_P4032 || ALGOR_P5064 || ALGOR_P6032 */
200 1.6.2.2 nathanw
201 1.6.2.3 nathanw pci_configure_bus(pc, ioext, memext, NULL, 0, mips_dcache_align);
202 1.6.2.2 nathanw extent_destroy(ioext);
203 1.6.2.2 nathanw extent_destroy(memext);
204 1.6.2.2 nathanw
205 1.6.2.2 nathanw #if defined(PCI_NETBSD_ENABLE_IDE)
206 1.6.2.2 nathanw /*
207 1.6.2.2 nathanw * Perhaps PMON has not enabled the IDE controller. Easy to
208 1.6.2.2 nathanw * fix -- just set the ENABLE bits for each channel in the
209 1.6.2.2 nathanw * IDETIM register. Just clear all the bits for the channel
210 1.6.2.2 nathanw * except for the ENABLE bits -- the `pciide' driver will
211 1.6.2.2 nathanw * properly configure it later.
212 1.6.2.2 nathanw */
213 1.6.2.2 nathanw idetim = 0;
214 1.6.2.2 nathanw if (PCI_NETBSD_ENABLE_IDE & 0x01)
215 1.6.2.2 nathanw idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 0);
216 1.6.2.2 nathanw if (PCI_NETBSD_ENABLE_IDE & 0x02)
217 1.6.2.2 nathanw idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 1);
218 1.6.2.2 nathanw pci_conf_write(pc, idetag, PIIX_IDETIM, idetim);
219 1.6.2.2 nathanw #endif
220 1.6.2.2 nathanw #endif /* NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) */
221 1.6.2.2 nathanw
222 1.6.2.2 nathanw #if defined(ALGOR_P4032)
223 1.6.2.2 nathanw st = &p4032_configuration.ac_lociot;
224 1.6.2.2 nathanw #elif defined(ALGOR_P5064)
225 1.6.2.2 nathanw st = NULL;
226 1.6.2.2 nathanw #elif defined(ALGOR_P6032)
227 1.6.2.2 nathanw st = NULL;
228 1.6.2.2 nathanw #endif
229 1.6.2.2 nathanw
230 1.6.2.2 nathanw for (md = mainbusdevs; md->md_name != NULL; md++) {
231 1.6.2.2 nathanw ma.ma_name = md->md_name;
232 1.6.2.2 nathanw ma.ma_st = st;
233 1.6.2.2 nathanw ma.ma_addr = md->md_addr;
234 1.6.2.2 nathanw ma.ma_irq = md->md_irq;
235 1.6.2.2 nathanw (void) config_found_sm(self, &ma, mainbus_print,
236 1.6.2.2 nathanw mainbus_submatch);
237 1.6.2.2 nathanw }
238 1.6.2.2 nathanw }
239 1.6.2.2 nathanw
240 1.6.2.2 nathanw int
241 1.6.2.2 nathanw mainbus_print(void *aux, const char *pnp)
242 1.6.2.2 nathanw {
243 1.6.2.2 nathanw struct mainbus_attach_args *ma = aux;
244 1.6.2.2 nathanw
245 1.6.2.2 nathanw if (pnp)
246 1.6.2.2 nathanw printf("%s at %s", ma->ma_name, pnp);
247 1.6.2.2 nathanw if (ma->ma_addr != (bus_addr_t) -1)
248 1.6.2.2 nathanw printf(" %s 0x%lx", mainbuscf_locnames[MAINBUSCF_ADDR],
249 1.6.2.2 nathanw ma->ma_addr);
250 1.6.2.2 nathanw
251 1.6.2.2 nathanw return (UNCONF);
252 1.6.2.2 nathanw }
253 1.6.2.2 nathanw
254 1.6.2.2 nathanw int
255 1.6.2.2 nathanw mainbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
256 1.6.2.2 nathanw {
257 1.6.2.2 nathanw struct mainbus_attach_args *ma = aux;
258 1.6.2.2 nathanw
259 1.6.2.2 nathanw if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT &&
260 1.6.2.2 nathanw cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr)
261 1.6.2.2 nathanw return (0);
262 1.6.2.2 nathanw
263 1.6.2.2 nathanw return ((*cf->cf_attach->ca_match)(parent, cf, aux));
264 1.6.2.2 nathanw }
265