1 /* $NetBSD: mainbus.c,v 1.18 2021/08/07 16:19:01 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 * DECstation port: Jonathan Stone
9 *
10 * Permission to use, copy, modify and distribute this software and
11 * its documentation is hereby granted, provided that both the copyright
12 * notice and this permission notice appear in all copies of the
13 * software, derivative works or modified versions, and any portions
14 * thereof, and that both notices appear in supporting documentation.
15 *
16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 *
20 * Carnegie Mellon requests users of this software to return to
21 *
22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
23 * School of Computer Science
24 * Carnegie Mellon University
25 * Pittsburgh PA 15213-3890
26 *
27 * any improvements or extensions that they make and grant Carnegie the
28 * rights to redistribute these changes.
29 */
30
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.18 2021/08/07 16:19:01 thorpej Exp $");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37
38 #include <machine/autoconf.h>
39 #include <machine/cpu.h>
40
41 #include <news68k/news68k/machid.h>
42
43 /* Definition of the mainbus driver. */
44 static int mainbus_match(device_t, cfdata_t, void *);
45 static void mainbus_attach(device_t, device_t, void *);
46 static int mainbus_search(device_t, cfdata_t, const int *, void *);
47 static int mainbus_print(void *, const char *);
48
49 CFATTACH_DECL_NEW(mainbus, 0,
50 mainbus_match, mainbus_attach, NULL, NULL);
51
52 static int mainbus_found;
53
54 static int
mainbus_match(device_t parent,cfdata_t cfdata,void * aux)55 mainbus_match(device_t parent, cfdata_t cfdata, void *aux)
56 {
57
58 if (mainbus_found)
59 return 0;
60
61 return 1;
62 }
63
64 static void
mainbus_attach(device_t parent,device_t self,void * aux)65 mainbus_attach(device_t parent, device_t self, void *aux)
66 {
67 struct mainbus_attach_args ma;
68
69 mainbus_found = 1;
70 aprint_normal("\n");
71
72 config_search(self, &ma,
73 CFARGS(.search = mainbus_search));
74 }
75
76 static int
mainbus_search(device_t parent,cfdata_t cf,const int * ldesc,void * aux)77 mainbus_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
78 {
79 struct mainbus_attach_args *ma = aux;
80
81 ma->ma_name = cf->cf_name;
82 ma->ma_systype = cf->cf_systype;
83
84 if (config_probe(parent, cf, ma))
85 config_attach(parent, cf, ma, mainbus_print, CFARGS_NONE);
86
87 return 0;
88 }
89
90 static int
mainbus_print(void * aux,const char * cp)91 mainbus_print(void *aux, const char *cp)
92 {
93 struct mainbus_attach_args *ma = aux;
94
95 if (cp)
96 aprint_normal("%s at %s", ma->ma_name, cp);
97
98 return UNCONF;
99 }
100