xref: /netbsd/sys/arch/hpcmips/hpcmips/mainbus.c (revision c4a72b64)
1 /*	$NetBSD: mainbus.c,v 1.23 2002/10/02 05:26:48 thorpej 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 CFATTACH_DECL(mainbus, sizeof(struct device),
59     mainbus_match, mainbus_attach, NULL, NULL);
60 
61 STATIC int __mainbus_attached;
62 
63 int
64 mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
65 {
66 
67 	return (__mainbus_attached ? 0 : 1);	/* don't attach twice */
68 }
69 
70 void
71 mainbus_attach(struct device *parent, struct device *self, void *aux)
72 {
73 	static const char *devnames[] = {	/* ATTACH ORDER */
74 		"cpu",				/* 1. CPU */
75 		"vrip", "vr4102ip", "vr4122ip",	/* 2. System BUS */
76 		"txsim",
77 		"bivideo", "btnmgr", "hpcapm",	/* 3. misc */
78 	};
79 	struct mainbus_attach_args ma;
80 	int i;
81 
82 	__mainbus_attached = 1;
83 
84 	printf("\n");
85 
86 	/* system bus_space */
87 	ma.ma_iot = hpcmips_system_bus_space();
88 	hpcmips_init_bus_space((struct bus_space_tag_hpcmips *)ma.ma_iot,
89 	    NULL, "main bus", 0, 0xffffffff);
90 
91 
92 	/* search and attach devices in order */
93 	for (i = 0; i < sizeof(devnames) / sizeof(devnames[0]); i++) {
94 		ma.ma_name = devnames[i];
95 		config_search(mainbus_search, self, &ma);
96 	}
97 }
98 
99 int
100 mainbus_search(struct device *parent, struct cfdata *cf, void *aux)
101 {
102 	struct mainbus_attach_args *ma = (void *)aux;
103 	int locator = cf->cf_loc[MAINBUSCF_PLATFORM];
104 
105 	/* check device name */
106 	if (strcmp(ma->ma_name, cf->cf_name) != 0)
107 		return (0);
108 
109 	/* check platform ID in config file */
110 	if (locator != MAINBUSCF_PLATFORM_DEFAULT &&
111 	    !platid_match(&platid, PLATID_DEREFP(locator)))
112 		return (0);
113 
114 	/* attach device */
115 	if (config_match(parent, cf, ma))
116 		config_attach(parent, cf, ma, mainbus_print);
117 
118 	return (0);
119 }
120 
121 int
122 mainbus_print(void *aux, const char *pnp)
123 {
124 
125 	return (pnp ? QUIET : UNCONF);
126 }
127 
128