xref: /netbsd-src/sys/arch/alpha/alpha/mainbus.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1 /* $NetBSD: mainbus.c,v 1.37 2021/08/07 16:18:40 thorpej Exp $ */
2 
3 /*
4  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
5  * All rights reserved.
6  *
7  * Author: Chris G. Demetriou
8  *
9  * Permission to use, copy, modify and distribute this software and
10  * its documentation is hereby granted, provided that both the copyright
11  * notice and this permission notice appear in all copies of the
12  * software, derivative works or modified versions, and any portions
13  * thereof, and that both notices appear in supporting documentation.
14  *
15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18  *
19  * Carnegie Mellon requests users of this software to return to
20  *
21  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22  *  School of Computer Science
23  *  Carnegie Mellon University
24  *  Pittsburgh PA 15213-3890
25  *
26  * any improvements or extensions that they make and grant Carnegie the
27  * rights to redistribute these changes.
28  */
29 
30 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
31 
32 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.37 2021/08/07 16:18:40 thorpej Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37 #include <sys/reboot.h>
38 #include <sys/conf.h>
39 
40 #include <machine/alpha.h>
41 #include <machine/autoconf.h>
42 #include <machine/rpb.h>
43 #include <machine/cpuconf.h>
44 
45 /* Definition of the mainbus driver. */
46 static int	mbmatch(device_t, cfdata_t, void *);
47 static void	mbattach(device_t, device_t, void *);
48 static int	mbprint(void *, const char *);
49 
50 CFATTACH_DECL_NEW(mainbus, 0, mbmatch, mbattach, NULL, NULL);
51 
52 /* There can be only one. */
53 int	mainbus_found;
54 
55 static int
mbmatch(device_t parent,cfdata_t cf,void * aux)56 mbmatch(device_t parent, cfdata_t cf, void *aux)
57 {
58 
59 	if (mainbus_found)
60 		return (0);
61 
62 	return (1);
63 }
64 
65 static void
mbattach(device_t parent,device_t self,void * aux)66 mbattach(device_t parent, device_t self, void *aux)
67 {
68 	struct mainbus_attach_args ma;
69 	struct pcs *pcsp;
70 	int i, cpuattachcnt;
71 	extern int ncpus;
72 
73 	mainbus_found = 1;
74 
75 	printf("\n");
76 
77 	/*
78 	 * Try to find and attach all of the CPUs in the machine.
79 	 */
80 	cpuattachcnt = 0;
81 	for (i = 0; i < hwrpb->rpb_pcs_cnt; i++) {
82 		pcsp = LOCATE_PCS(hwrpb, i);
83 		if ((pcsp->pcs_flags & PCS_PP) == 0)
84 			continue;
85 
86 		ma.ma_name = "cpu";
87 		ma.ma_slot = i;
88 		if (config_found(self, &ma, mbprint, CFARGS_NONE) != NULL)
89 			cpuattachcnt++;
90 	}
91 	if (ncpus != cpuattachcnt)
92 		printf("WARNING: %d cpus in machine, %d attached\n",
93 			ncpus, cpuattachcnt);
94 
95 	/* Patch-up any routines based on architecture features. */
96 	alpha_patch(false);
97 
98 	if (alpha_is_qemu) {
99 		ma.ma_name = "qemu";
100 		ma.ma_slot = 0;			/* meaningless */
101 		config_found(self, &ma, mbprint, CFARGS_NONE);
102 	}
103 
104 	if (platform.iobus != NULL) {
105 		ma.ma_name = platform.iobus;
106 		ma.ma_slot = 0;			/* meaningless */
107 		config_found(self, &ma, mbprint, CFARGS_NONE);
108 	}
109 }
110 
111 static int
mbprint(void * aux,const char * pnp)112 mbprint(void *aux, const char *pnp)
113 {
114 	struct mainbus_attach_args *ma = aux;
115 
116 	if (pnp)
117 		aprint_normal("%s at %s", ma->ma_name, pnp);
118 
119 	return (UNCONF);
120 }
121