Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / algor / dev / mainbus.c
blob6e1c8de53e1f03cf539273a530ab7795d165b855
1 /* $NetBSD: mainbus.c,v 1.19 2005/12/11 12:16:08 christos Exp $ */
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.19 2005/12/11 12:16:08 christos Exp $");
35 #include "opt_algor_p4032.h"
36 #include "opt_algor_p5064.h"
37 #include "opt_algor_p6032.h"
39 #include "opt_pci.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/conf.h>
44 #include <sys/reboot.h>
45 #include <sys/device.h>
46 #include <sys/malloc.h>
47 #include <sys/extent.h>
49 #include <machine/bus.h>
50 #include <machine/autoconf.h>
52 #include <mips/cache.h>
54 #include <dev/pci/pcivar.h>
55 #include <dev/pci/pciconf.h>
57 #if defined(PCI_NETBSD_CONFIGURE) && defined(PCI_NETBSD_ENABLE_IDE)
58 #if defined(ALGOR_P5064) || defined(ALGOR_P6032)
59 #include <dev/pci/pciide_piix_reg.h>
60 #endif /* ALGOR_P5064 || ALGOR_P6032 */
61 #endif /* PCI_NETBSD_CONFIGURE && PCI_NETBSD_ENABLE_IDE */
63 #include "locators.h"
64 #include "pci.h"
66 int mainbus_match(struct device *, struct cfdata *, void *);
67 void mainbus_attach(struct device *, struct device *, void *);
69 CFATTACH_DECL(mainbus, sizeof(struct device),
70 mainbus_match, mainbus_attach, NULL, NULL);
72 int mainbus_print(void *, const char *);
73 int mainbus_submatch(struct device *, struct cfdata *,
74 const int *, void *);
76 /* There can be only one. */
77 int mainbus_found;
79 struct mainbusdev {
80 const char *md_name;
81 bus_addr_t md_addr;
82 int md_irq;
85 #if defined(ALGOR_P4032)
86 #include <algor/algor/algor_p4032reg.h>
87 #include <algor/algor/algor_p4032var.h>
89 struct mainbusdev mainbusdevs[] = {
90 { "cpu", -1, -1 },
91 { "mcclock", P4032_RTC, P4032_IRQ_RTC },
92 { "com", P4032_COM1, P4032_IRQ_COM1 },
93 { "com", P4032_COM2, P4032_IRQ_COM2 },
94 { "lpt", P4032_LPT, P4032_IRQ_LPT },
95 { "pckbc", P4032_PCKBC, P4032_IRQ_PCKBC },
96 { "fdc", P4032_FDC, P4032_IRQ_FLOPPY },
97 { "vtpbc", P4032_V962PBC, -1 },
99 { NULL, 0, 0 },
101 #endif /* ALGOR_P4032 */
103 #if defined(ALGOR_P5064)
104 #include <algor/algor/algor_p5064reg.h>
105 #include <algor/algor/algor_p5064var.h>
107 struct mainbusdev mainbusdevs[] = {
108 { "cpu", -1, -1 },
109 { "vtpbc", P5064_V360EPC, -1 },
111 { NULL, 0, 0 },
113 #endif /* ALGOR_P5064 */
115 #if defined(ALGOR_P6032)
116 #include <algor/algor/algor_p6032reg.h>
117 #include <algor/algor/algor_p6032var.h>
119 struct mainbusdev mainbusdevs[] = {
120 { "cpu", -1, -1 },
121 { "bonito", BONITO_REG_BASE, -1 },
123 { NULL, 0, 0 },
125 #endif /* ALGOR_P6032 */
128 mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
131 if (mainbus_found)
132 return (0);
134 return (1);
137 void
138 mainbus_attach(struct device *parent, struct device *self, void *aux)
140 struct mainbus_attach_args ma;
141 struct mainbusdev *md;
142 bus_space_tag_t st;
143 #if defined(PCI_NETBSD_CONFIGURE)
144 struct extent *ioext, *memext;
145 pci_chipset_tag_t pc;
146 #if defined(PCI_NETBSD_ENABLE_IDE)
147 pcitag_t idetag;
148 pcireg_t idetim;
149 #endif
150 #endif
152 mainbus_found = 1;
154 printf("\n");
156 #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
157 #if defined(ALGOR_P4032)
159 * Reserve the bottom 64K of the I/O space for ISA devices.
161 ioext = extent_create("pciio", 0x00010000, 0x000effff,
162 M_DEVBUF, NULL, 0, EX_NOWAIT);
163 memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
164 M_DEVBUF, NULL, 0, EX_NOWAIT);
166 pc = &p4032_configuration.ac_pc;
167 #elif defined(ALGOR_P5064)
169 * Reserve the bottom 512K of the I/O space for ISA devices.
170 * According to the PMON sources, this is a work-around for
171 * a bug in the ISA bridge.
173 ioext = extent_create("pciio", 0x00080000, 0x00ffffff,
174 M_DEVBUF, NULL, 0, EX_NOWAIT);
175 memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
176 M_DEVBUF, NULL, 0, EX_NOWAIT);
178 pc = &p5064_configuration.ac_pc;
179 #if defined(PCI_NETBSD_ENABLE_IDE)
180 idetag = pci_make_tag(pc, 0, 2, 1);
181 #endif
182 #elif defined(ALGOR_P6032)
184 * Reserve the bottom 64K of the I/O space for ISA devices.
186 ioext = extent_create("pciio", 0x00010000, 0x000effff,
187 M_DEVBUF, NULL, 0, EX_NOWAIT);
188 memext = extent_create("pcimem", 0x01000000, 0x0affffff,
189 M_DEVBUF, NULL, 0, EX_NOWAIT);
191 pc = &p6032_configuration.ac_pc;
192 #if defined(PCI_NETBSD_ENABLE_IDE)
193 idetag = pci_make_tag(pc, 0, 17, 1);
194 #endif
195 #endif /* ALGOR_P4032 || ALGOR_P5064 || ALGOR_P6032 */
197 pci_configure_bus(pc, ioext, memext, NULL, 0, mips_dcache_align);
198 extent_destroy(ioext);
199 extent_destroy(memext);
201 #if defined(PCI_NETBSD_ENABLE_IDE)
203 * Perhaps PMON has not enabled the IDE controller. Easy to
204 * fix -- just set the ENABLE bits for each channel in the
205 * IDETIM register. Just clear all the bits for the channel
206 * except for the ENABLE bits -- the `pciide' driver will
207 * properly configure it later.
209 idetim = 0;
210 if (PCI_NETBSD_ENABLE_IDE & 0x01)
211 idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 0);
212 if (PCI_NETBSD_ENABLE_IDE & 0x02)
213 idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 1);
214 pci_conf_write(pc, idetag, PIIX_IDETIM, idetim);
215 #endif
216 #endif /* NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) */
218 #if defined(ALGOR_P4032)
219 st = &p4032_configuration.ac_lociot;
220 #elif defined(ALGOR_P5064)
221 st = NULL;
222 #elif defined(ALGOR_P6032)
223 st = NULL;
224 #endif
226 for (md = mainbusdevs; md->md_name != NULL; md++) {
227 ma.ma_name = md->md_name;
228 ma.ma_st = st;
229 ma.ma_addr = md->md_addr;
230 ma.ma_irq = md->md_irq;
231 (void) config_found_sm_loc(self, "mainbus", NULL, &ma,
232 mainbus_print, mainbus_submatch);
237 mainbus_print(void *aux, const char *pnp)
239 struct mainbus_attach_args *ma = aux;
241 if (pnp)
242 aprint_normal("%s at %s", ma->ma_name, pnp);
243 if (ma->ma_addr != (bus_addr_t) -1)
244 aprint_normal(" addr 0x%lx", ma->ma_addr);
246 return (UNCONF);
250 mainbus_submatch(struct device *parent, struct cfdata *cf,
251 const int *ldesc, void *aux)
253 struct mainbus_attach_args *ma = aux;
255 if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT &&
256 cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr)
257 return (0);
259 return (config_match(parent, cf, aux));