xref: /netbsd/sys/arch/algor/dev/mainbus.c (revision bf9ec67e)
1 /*	$NetBSD: mainbus.c,v 1.8 2002/01/02 14:48:09 thorpej 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 <mips/cache.h>
57 
58 #include <dev/pci/pcivar.h>
59 #include <dev/pci/pciconf.h>
60 
61 #if defined(PCI_NETBSD_CONFIGURE) && defined(PCI_NETBSD_ENABLE_IDE)
62 #if defined(ALGOR_P5064) || defined(ALGOR_P6032)
63 #include <dev/pci/pciide_piix_reg.h>
64 #endif /* ALGOR_P5064 || ALGOR_P6032 */
65 #endif /* PCI_NETBSD_CONFIGURE && PCI_NETBSD_ENABLE_IDE */
66 
67 #include "locators.h"
68 #include "pci.h"
69 
70 int	mainbus_match(struct device *, struct cfdata *, void *);
71 void	mainbus_attach(struct device *, struct device *, void *);
72 
73 struct cfattach mainbus_ca = {
74 	sizeof(struct device), mainbus_match, mainbus_attach,
75 };
76 
77 int	mainbus_print(void *, const char *);
78 int	mainbus_submatch(struct device *, struct cfdata *, void *);
79 
80 /* There can be only one. */
81 int	mainbus_found;
82 
83 struct mainbusdev {
84 	const char *md_name;
85 	bus_addr_t md_addr;
86 	int md_irq;
87 };
88 
89 #if defined(ALGOR_P4032)
90 #include <algor/algor/algor_p4032reg.h>
91 #include <algor/algor/algor_p4032var.h>
92 
93 struct mainbusdev mainbusdevs[] = {
94 	{ "cpu",		-1,			-1 },
95 	{ "mcclock",		P4032_RTC,		P4032_IRQ_RTC },
96 	{ "com",		P4032_COM1,		P4032_IRQ_COM1 },
97 	{ "com",		P4032_COM2,		P4032_IRQ_COM2 },
98 	{ "lpt",		P4032_LPT,		P4032_IRQ_LPT },
99 	{ "pckbc",		P4032_PCKBC,		P4032_IRQ_PCKBC },
100 	{ "fdc",		P4032_FDC,		P4032_IRQ_FLOPPY },
101 	{ "vtpbc",		P4032_V962PBC,		-1 },
102 
103 	{ NULL,			0,			0 },
104 };
105 #endif /* ALGOR_P4032 */
106 
107 #if defined(ALGOR_P5064)
108 #include <algor/algor/algor_p5064reg.h>
109 #include <algor/algor/algor_p5064var.h>
110 
111 struct mainbusdev mainbusdevs[] = {
112 	{ "cpu",		-1,			-1 },
113 	{ "vtpbc",		P5064_V360EPC,		-1 },
114 
115 	{ NULL,			0,			0 },
116 };
117 #endif /* ALGOR_P5064 */
118 
119 #if defined(ALGOR_P6032)
120 #include <algor/algor/algor_p6032reg.h>
121 #include <algor/algor/algor_p6032var.h>
122 
123 struct mainbusdev mainbusdevs[] = {
124 	{ "cpu",		-1,			-1 },
125 	{ "bonito",		BONITO_REG_BASE,	-1 },
126 
127 	{ NULL,			0,			0 },
128 };
129 #endif /* ALGOR_P6032 */
130 
131 int
132 mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
133 {
134 
135 	if (mainbus_found)
136 		return (0);
137 
138 	return (1);
139 }
140 
141 void
142 mainbus_attach(struct device *parent, struct device *self, void *aux)
143 {
144 	struct mainbus_attach_args ma;
145 	struct mainbusdev *md;
146 	bus_space_tag_t st;
147 #if defined(PCI_NETBSD_CONFIGURE)
148 	struct extent *ioext, *memext;
149 	pci_chipset_tag_t pc;
150 #if defined(PCI_NETBSD_ENABLE_IDE)
151 	pcitag_t idetag;
152 	pcireg_t idetim;
153 #endif
154 #endif
155 
156 	mainbus_found = 1;
157 
158 	printf("\n");
159 
160 #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
161 #if defined(ALGOR_P4032)
162 	/*
163 	 * Reserve the bottom 64K of the I/O space for ISA devices.
164 	 */
165 	ioext  = extent_create("pciio",  0x00010000, 0x000effff,
166 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
167 	memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
168 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
169 
170 	pc = &p4032_configuration.ac_pc;
171 #elif defined(ALGOR_P5064)
172 	/*
173 	 * Reserve the bottom 512K of the I/O space for ISA devices.
174 	 * According to the PMON sources, this is a work-around for
175 	 * a bug in the ISA bridge.
176 	 */
177 	ioext  = extent_create("pciio",  0x00080000, 0x00ffffff,
178 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
179 	memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
180 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
181 
182 	pc = &p5064_configuration.ac_pc;
183 #if defined(PCI_NETBSD_ENABLE_IDE)
184 	idetag = pci_make_tag(pc, 0, 2, 1);
185 #endif
186 #elif defined(ALGOR_P6032)
187 	/*
188 	 * Reserve the bottom 64K of the I/O space for ISA devices.
189 	 */
190 	ioext  = extent_create("pciio",  0x00010000, 0x000effff,
191 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
192 	memext = extent_create("pcimem", 0x01000000, 0x0affffff,
193 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
194 
195 	pc = &p6032_configuration.ac_pc;
196 #if defined(PCI_NETBSD_ENABLE_IDE)
197 	idetag = pci_make_tag(pc, 0, 17, 1);
198 #endif
199 #endif /* ALGOR_P4032 || ALGOR_P5064 || ALGOR_P6032 */
200 
201 	pci_configure_bus(pc, ioext, memext, NULL, 0, mips_dcache_align);
202 	extent_destroy(ioext);
203 	extent_destroy(memext);
204 
205 #if defined(PCI_NETBSD_ENABLE_IDE)
206 	/*
207 	 * Perhaps PMON has not enabled the IDE controller.  Easy to
208 	 * fix -- just set the ENABLE bits for each channel in the
209 	 * IDETIM register.  Just clear all the bits for the channel
210 	 * except for the ENABLE bits -- the `pciide' driver will
211 	 * properly configure it later.
212 	 */
213 	idetim = 0;
214 	if (PCI_NETBSD_ENABLE_IDE & 0x01)
215 		idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 0);
216 	if (PCI_NETBSD_ENABLE_IDE & 0x02)
217 		idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 1);
218 	pci_conf_write(pc, idetag, PIIX_IDETIM, idetim);
219 #endif
220 #endif /* NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) */
221 
222 #if defined(ALGOR_P4032)
223 	st = &p4032_configuration.ac_lociot;
224 #elif defined(ALGOR_P5064)
225 	st = NULL;
226 #elif defined(ALGOR_P6032)
227 	st = NULL;
228 #endif
229 
230 	for (md = mainbusdevs; md->md_name != NULL; md++) {
231 		ma.ma_name = md->md_name;
232 		ma.ma_st = st;
233 		ma.ma_addr = md->md_addr;
234 		ma.ma_irq = md->md_irq;
235 		(void) config_found_sm(self, &ma, mainbus_print,
236 		    mainbus_submatch);
237 	}
238 }
239 
240 int
241 mainbus_print(void *aux, const char *pnp)
242 {
243 	struct mainbus_attach_args *ma = aux;
244 
245 	if (pnp)
246 		printf("%s at %s", ma->ma_name, pnp);
247 	if (ma->ma_addr != (bus_addr_t) -1)
248 		printf(" %s 0x%lx", mainbuscf_locnames[MAINBUSCF_ADDR],
249 		    ma->ma_addr);
250 
251 	return (UNCONF);
252 }
253 
254 int
255 mainbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
256 {
257 	struct mainbus_attach_args *ma = aux;
258 
259 	if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT &&
260 	    cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr)
261 		return (0);
262 
263 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
264 }
265