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