1 /* $NetBSD: mainbus.c,v 1.33 2021/08/07 16:18:54 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/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.33 2021/08/07 16:18:54 thorpej Exp $");
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 #include <sys/bus.h>
44
45 #include <machine/autoconf.h>
46 #include <machine/platid.h>
47 #include <machine/bus_space_hpcmips.h>
48
49 #include "locators.h"
50
51 #ifdef DEBUG
52 #define STATIC
53 #else
54 #define STATIC static
55 #endif
56
57 STATIC int mainbus_match(device_t, cfdata_t, void *);
58 STATIC void mainbus_attach(device_t, device_t, void *);
59 STATIC int mainbus_search(device_t, cfdata_t, const int *, void *);
60 STATIC int mainbus_print(void *, const char *);
61
62 CFATTACH_DECL_NEW(mainbus, 0,
63 mainbus_match, mainbus_attach, NULL, NULL);
64
65 STATIC int __mainbus_attached;
66
67 int
mainbus_match(device_t parent,cfdata_t cf,void * aux)68 mainbus_match(device_t parent, cfdata_t cf, void *aux)
69 {
70
71 return (__mainbus_attached ? 0 : 1); /* don't attach twice */
72 }
73
74 void
mainbus_attach(device_t parent,device_t self,void * aux)75 mainbus_attach(device_t parent, device_t self, void *aux)
76 {
77 static const char * const devnames[] = { /* ATTACH ORDER */
78 "cpu", /* 1. CPU */
79 "vrip", "vr4102ip", "vr4122ip",
80 "vr4181ip", /* 2. System BUS */
81 "txsim",
82 "bivideo", "btnmgr", /* 3. misc */
83 };
84 struct mainbus_attach_args ma;
85 int i;
86
87 __mainbus_attached = 1;
88
89 printf("\n");
90
91 /* system bus_space */
92 ma.ma_iot = hpcmips_system_bus_space();
93 hpcmips_init_bus_space((struct bus_space_tag_hpcmips *)ma.ma_iot,
94 NULL, "main bus", 0, 0xffffffff);
95
96
97 /* search and attach devices in order */
98 for (i = 0; i < sizeof(devnames) / sizeof(devnames[0]); i++) {
99 ma.ma_name = devnames[i];
100 config_search(self, &ma,
101 CFARGS(.search = mainbus_search,
102 .iattr = "mainbus"));
103 }
104
105 /* APM */
106 config_found(self, NULL, mainbus_print,
107 CFARGS(.iattr = "hpcapmif"));
108 }
109
110 int
mainbus_search(device_t parent,cfdata_t cf,const int * ldesc,void * aux)111 mainbus_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
112 {
113 struct mainbus_attach_args *ma = (void *)aux;
114 int locator = cf->cf_loc[MAINBUSCF_PLATFORM];
115
116 /* check device name */
117 if (strcmp(ma->ma_name, cf->cf_name) != 0)
118 return (0);
119
120 /* check platform ID in config file */
121 if (locator != MAINBUSCF_PLATFORM_DEFAULT &&
122 !platid_match(&platid, PLATID_DEREFP(locator)))
123 return (0);
124
125 /* attach device */
126 if (config_probe(parent, cf, ma))
127 config_attach(parent, cf, ma, mainbus_print, CFARGS_NONE);
128
129 return (0);
130 }
131
132 int
mainbus_print(void * aux,const char * pnp)133 mainbus_print(void *aux, const char *pnp)
134 {
135
136 return (pnp ? QUIET : UNCONF);
137 }
138
139