1 /*        $NetBSD: mainbus.c,v 1.9 2021/08/07 16:18:52 thorpej Exp $  */
2 
3 /*
4  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Christopher G. Demetriou
17  *        for the NetBSD Project.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.9 2021/08/07 16:18:52 thorpej Exp $");
35 
36 #include "mainbus.h"
37 #include "opt_multiprocessor.h"
38 
39 #include <sys/param.h>
40 #include <sys/bus.h>
41 #include <sys/device.h>
42 #include <sys/errno.h>
43 
44 #include <evbppc/ev64260/ev64260.h>
45 
46 #include "locators.h"
47 
48 #if NCPU == 0
49 #error    A cpu device is now required
50 #endif
51 
52 
53 int       mainbus_match(device_t, cfdata_t, void *);
54 void      mainbus_attach(device_t, device_t, void *);
55 int       mainbus_cfprint(void *, const char *);
56 
57 CFATTACH_DECL_NEW(mainbus, 0,
58           mainbus_match, mainbus_attach, NULL, NULL);
59 
60 /*
61  * Probe for the mainbus; always succeeds.
62  */
63 int
mainbus_match(device_t parent,cfdata_t match,void * aux)64 mainbus_match(device_t parent, cfdata_t match, void *aux)
65 {
66 
67           return 1;
68 }
69 
70 /*
71  * Attach the mainbus.
72  */
73 void
mainbus_attach(device_t parent,device_t self,void * aux)74 mainbus_attach(device_t parent, device_t self, void *aux)
75 {
76           struct mainbus_attach_args mba;
77           extern bus_addr_t gt_base;
78 
79           printf("\n");
80 
81           memset(&mba, 0, sizeof(mba));
82 
83           /*
84            * Always find the CPU
85            */
86           mba.mba_name = "cpu";
87           mba.mba_unit = 0;
88           mba.mba_addr = MAINBUSCF_ADDR_DEFAULT;
89           config_found(self, &mba, mainbus_cfprint, CFARGS_NONE);
90 
91 #ifdef MULTIPROCESSOR
92           /*
93            * Try for a second one...
94            */
95           mba.mba_name = "cpu";
96           mba.mba_unit = 1;
97           mba.mba_addr = MAINBUSCF_ADDR_DEFAULT;
98           config_found(self, &mba, mainbus_cfprint, CFARGS_NONE);
99 #endif
100 
101           /*
102            * Now try to configure the Discovery
103            */
104           mba.mba_name = "gt";
105           mba.mba_unit = -1;
106           mba.mba_addr = gt_base;
107           config_found(self, &mba, mainbus_cfprint, CFARGS_NONE);
108 }
109 
110 int
mainbus_cfprint(void * aux,const char * pnp)111 mainbus_cfprint(void *aux, const char *pnp)
112 {
113           struct mainbus_attach_args *mba = aux;
114 
115           if (pnp)
116                     aprint_normal("%s at %s", mba->mba_name, pnp);
117           if (mba->mba_unit != -1)
118                     aprint_normal(" unit %d", mba->mba_unit);
119           if (mba->mba_addr != MAINBUSCF_ADDR_DEFAULT)
120                     aprint_normal(" addr 0x%08x", mba->mba_addr);
121           return UNCONF;
122 }
123 
124 
125 static int          cpu_match(device_t, cfdata_t, void *);
126 static void         cpu_attach(device_t, device_t, void *);
127 
128 CFATTACH_DECL_NEW(cpu, 0, cpu_match, cpu_attach, NULL, NULL);
129 
130 int
cpu_match(device_t parent,cfdata_t cf,void * aux)131 cpu_match(device_t parent, cfdata_t cf, void *aux)
132 {
133           struct mainbus_attach_args *mba = aux;
134 
135           if (strcmp(mba->mba_name, "cpu") != 0)
136                     return 0;
137 
138           return 1;
139 }
140 
141 void
cpu_attach(device_t parent,device_t self,void * aux)142 cpu_attach(device_t parent, device_t self, void *aux)
143 {
144           struct mainbus_attach_args *mba = aux;
145 
146           (void) cpu_attach_common(self, mba->mba_unit);
147 }
148