xref: /netbsd/sys/arch/hpcmips/hpcmips/mainbus.c (revision bf9ec67e)
1 /*	$NetBSD: mainbus.c,v 1.19 2002/02/11 09:21:47 takemura Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999
5  *         Shin Takemura and PocketBSD Project. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the PocketBSD project
18  *	and its contributors.
19  * 4. Neither the name of the project nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 
40 #include <machine/bus.h>
41 #include <machine/autoconf.h>
42 #include <machine/platid.h>
43 #include <machine/bus_space_hpcmips.h>
44 
45 #include "locators.h"
46 
47 #ifdef DEBUG
48 #define STATIC
49 #else
50 #define STATIC	static
51 #endif
52 
53 STATIC int mainbus_match(struct device *, struct cfdata *, void *);
54 STATIC void mainbus_attach(struct device *, struct device *, void *);
55 STATIC int mainbus_search(struct device *, struct cfdata *, void *);
56 STATIC int mainbus_print(void *, const char *);
57 
58 struct cfattach mainbus_ca = {
59 	sizeof(struct device), mainbus_match, mainbus_attach
60 };
61 
62 STATIC int __mainbus_attached;
63 
64 int
65 mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
66 {
67 
68 	return (__mainbus_attached ? 0 : 1);	/* don't attach twice */
69 }
70 
71 void
72 mainbus_attach(struct device *parent, struct device *self, void *aux)
73 {
74 	static const char *devnames[] = {	/* ATTACH ORDER */
75 		"cpu",				/* 1. CPU */
76 		"vrip", "vr4102ip", "vr4122ip",	/* 2. System BUS */
77 		"txsim",
78 		"bivideo", "btnmgr", "hpcapm",	/* 3. misc */
79 	};
80 	struct mainbus_attach_args ma;
81 	int i;
82 
83 	__mainbus_attached = 1;
84 
85 	printf("\n");
86 
87 	/* system bus_space */
88 	ma.ma_iot = hpcmips_system_bus_space();
89 	hpcmips_init_bus_space((struct bus_space_tag_hpcmips *)ma.ma_iot,
90 	    NULL, "main bus", 0, 0xffffffff);
91 
92 
93 	/* search and attach devices in order */
94 	for (i = 0; i < sizeof(devnames) / sizeof(devnames[0]); i++) {
95 		ma.ma_name = devnames[i];
96 		config_search(mainbus_search, self, &ma);
97 	}
98 }
99 
100 int
101 mainbus_search(struct device *parent, struct cfdata *cf, void *aux)
102 {
103 	struct mainbus_attach_args *ma = (void *)aux;
104 	int locator = cf->cf_loc[MAINBUSCF_PLATFORM];
105 
106 	/* check device name */
107 	if (strcmp(ma->ma_name, cf->cf_driver->cd_name) != 0)
108 		return (0);
109 
110 	/* check platform ID in config file */
111 	if (locator != MAINBUSCF_PLATFORM_DEFAULT &&
112 	    !platid_match(&platid, PLATID_DEREFP(locator)))
113 		return (0);
114 
115 	/* attach device */
116 	if ((*cf->cf_attach->ca_match)(parent, cf, ma))
117 		config_attach(parent, cf, ma, mainbus_print);
118 
119 	return (0);
120 }
121 
122 int
123 mainbus_print(void *aux, const char *pnp)
124 {
125 
126 	return (pnp ? QUIET : UNCONF);
127 }
128 
129