xref: /netbsd-src/sys/arch/evbmips/malta/dev/mainbus.c (revision 27527e67bbdf8d9ec84fd58803048ed6d181ece2)
1 /*	$NetBSD: mainbus.c,v 1.10 2005/12/11 12:17:11 christos Exp $	*/
2 
3 /*
4  * Copyright 2002 Wasabi Systems, Inc.
5  * All rights reserved.
6  *
7  * Written by Simon Burge 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 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.10 2005/12/11 12:17:11 christos Exp $");
40 
41 #include "opt_pci.h"
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 #if defined(PCI_NETBSD_CONFIGURE)
47 #include <sys/extent.h>
48 #include <sys/malloc.h>
49 #endif
50 
51 #include <dev/pci/pcivar.h>
52 #if defined(PCI_NETBSD_CONFIGURE)
53 #include <dev/pci/pciconf.h>
54 #endif
55 
56 #include <mips/cache.h>
57 #include <mips/cpuregs.h>
58 
59 #include <evbmips/malta/autoconf.h>
60 #include <evbmips/malta/maltareg.h>
61 #include <evbmips/malta/maltavar.h>
62 
63 #if defined(PCI_NETBSD_ENABLE_IDE)
64 #include <dev/pci/pciide_piix_reg.h>
65 #endif /* PCI_NETBSD_ENABLE_IDE */
66 
67 #include "locators.h"
68 #include "pci.h"
69 
70 static int	mainbus_match(struct device *, struct cfdata *, void *);
71 static void	mainbus_attach(struct device *, struct device *, void *);
72 static int	mainbus_submatch(struct device *, struct cfdata *,
73 				 const int *, void *);
74 static int	mainbus_print(void *, const char *);
75 
76 CFATTACH_DECL(mainbus, sizeof(struct device),
77     mainbus_match, mainbus_attach, NULL, NULL);
78 
79 /* There can be only one. */
80 int	mainbus_found;
81 
82 struct mainbusdev {
83 	const char *md_name;
84 	bus_addr_t md_addr;
85 	int md_intr;
86 };
87 
88 struct mainbusdev mainbusdevs[] = {
89 	{ "cpu",		-1,			-1 },
90 	{ "gt",			MALTA_CORECTRL_BASE,	-1 },
91 	{ "com",		MALTA_CBUSUART,		MALTA_CBUSUART_INTR },
92 	{ "i2c",		MALTA_I2C_BASE,		-1 },
93 	{ "gpio",		MALTA_GPIO_BASE,	-1 },
94 	{ NULL,			0,			0 },
95 };
96 
97 static int
98 mainbus_match(parent, match, aux)
99 	struct device *parent;
100 	struct cfdata *match;
101 	void *aux;
102 {
103 
104 	if (mainbus_found)
105 		return (0);
106 
107 	return (1);
108 }
109 
110 static void
111 mainbus_attach(parent, self, aux)
112 	struct device *parent;
113 	struct device *self;
114 	void *aux;
115 {
116 	struct mainbus_attach_args ma;
117 	struct mainbusdev *md;
118 #if defined(PCI_NETBSD_CONFIGURE)
119 	struct extent *ioext, *memext;
120 #endif
121 #if defined(PCI_NETBSD_ENABLE_IDE)
122 	struct malta_config *mcp = &malta_configuration;
123 	pci_chipset_tag_t pc = &mcp->mc_pc;
124 	pcitag_t idetag;
125 	pcireg_t idetim;
126 #endif
127 
128 	mainbus_found = 1;
129 	printf("\n");
130 
131 #if defined(PCI_NETBSD_CONFIGURE)
132 	ioext = extent_create("pciio",  0x00001000, 0x0000efff,
133 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
134 	memext = extent_create("pcimem", MALTA_PCIMEM1_BASE,
135 	    MALTA_PCIMEM1_BASE + MALTA_PCIMEM1_SIZE,
136 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
137 
138 	pci_configure_bus(pc, ioext, memext, NULL, 0, mips_dcache_align);
139 	extent_destroy(ioext);
140 	extent_destroy(memext);
141 #endif /* PCI_NETBSD_CONFIGURE */
142 
143 #if defined(PCI_NETBSD_ENABLE_IDE)
144 	/*
145 	 * Perhaps PMON has not enabled the IDE controller.  Easy to
146 	 * fix -- just set the ENABLE bits for each channel in the
147 	 * IDETIM register.  Just clear all the bits for the channel
148 	 * except for the ENABLE bits -- the `pciide' driver will
149 	 * properly configure it later.
150 	 */
151 	idetim = 0;
152 	if (PCI_NETBSD_ENABLE_IDE & 0x01)
153 		idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 0);
154 	if (PCI_NETBSD_ENABLE_IDE & 0x02)
155 		idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 1);
156 
157 	/* pciide0 is pci device 10, function 1 */
158 	idetag = pci_make_tag(pc, 0, 10, 1);
159 	pci_conf_write(pc, idetag, PIIX_IDETIM, idetim);
160 #endif
161 	for (md = mainbusdevs; md->md_name != NULL; md++) {
162 		ma.ma_name = md->md_name;
163 		ma.ma_addr = md->md_addr;
164 		ma.ma_intr = md->md_intr;
165 		(void) config_found_sm_loc(self, "mainbus", NULL, &ma,
166 		    mainbus_print, mainbus_submatch);
167 	}
168 }
169 
170 static int
171 mainbus_submatch(struct device *parent, struct cfdata *cf,
172 		 const int *ldesc, void *aux)
173 {
174 	struct mainbus_attach_args *ma = aux;
175 
176 	if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT &&
177 	    cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr)
178 		return (0);
179 
180 	return (config_match(parent, cf, aux));
181 }
182 
183 static int
184 mainbus_print(void *aux, const char *pnp)
185 {
186 	struct mainbus_attach_args *ma = aux;
187 
188 	if (pnp != 0)
189 		return QUIET;
190 
191 	if (pnp)
192 		aprint_normal("%s at %s", ma->ma_name, pnp);
193 	if (ma->ma_addr != MAINBUSCF_ADDR_DEFAULT)
194 		aprint_normal(" addr 0x%lx", ma->ma_addr);
195 
196 	return (UNCONF);
197 }
198