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