xref: /netbsd-src/sys/arch/sgimips/sgimips/mainbus.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1 /*	$NetBSD: mainbus.c,v 1.22 2021/08/07 16:19:05 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 2000 Soren S. Jorvang
5  * 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 for the
18  *          NetBSD Project.  See http://www.NetBSD.org/ for
19  *          information about NetBSD.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.22 2021/08/07 16:19:05 thorpej Exp $");
37 
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
41 
42 #include <mips/cpuregs.h>
43 
44 #include <machine/autoconf.h>
45 #include <machine/machtype.h>
46 
47 #include <dev/arcbios/arcbios.h>
48 #include <dev/arcbios/arcbiosvar.h>
49 
50 #include "locators.h"
51 
52 static int	mainbus_match(device_t, cfdata_t, void *);
53 static void	mainbus_attach(device_t, device_t, void *);
54 static int	mainbus_search(device_t, cfdata_t, const int *, void *);
55 int		mainbus_print(void *, const char *);
56 
57 CFATTACH_DECL_NEW(mainbus, 0,
58     mainbus_match, mainbus_attach, NULL, NULL);
59 
60 static int
mainbus_match(device_t parent,cfdata_t cf,void * aux)61 mainbus_match(device_t parent, cfdata_t cf, void *aux)
62 {
63 	return 1;
64 }
65 
66 static void
mainbus_attach(device_t parent,device_t self,void * aux)67 mainbus_attach(device_t parent, device_t self, void *aux)
68 {
69 	struct mainbus_attach_args ma;
70 
71 	aprint_normal(": %s [%s, %s], %d processor%s\n",
72 	    arcbios_system_identifier,
73 	    arcbios_sysid_vendor, arcbios_sysid_product,
74 	    ncpus, ncpus == 1 ? "" : "s");
75 
76 	config_search(self, &ma,
77 	    CFARGS(.search = mainbus_search));
78 }
79 
80 static int
mainbus_search(device_t parent,cfdata_t cf,const int * ldesc,void * aux)81 mainbus_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
82 {
83 	struct mainbus_attach_args *ma = aux;
84 
85 	do {
86 		ma->ma_name = NULL;
87 		ma->ma_addr = cf->cf_loc[MAINBUSCF_ADDR];
88 		ma->ma_iot = 0;
89 		ma->ma_ioh = MIPS_PHYS_TO_KSEG1(ma->ma_addr);
90 		if (config_probe(parent, cf, ma))
91 			config_attach(parent, cf, ma, mainbus_print, CFARGS_NONE);
92 	} while (cf->cf_fstate == FSTATE_STAR);
93 
94 	return 0;
95 }
96 
97 int
mainbus_print(void * aux,const char * pnp)98 mainbus_print(void *aux, const char *pnp)
99 {
100 	struct mainbus_attach_args *ma = aux;
101 
102 	if (pnp != 0)
103 		return QUIET;
104 
105 	if (ma->ma_addr != (u_long) MAINBUSCF_ADDR_DEFAULT)
106 		aprint_normal(" addr 0x%lx", ma->ma_addr);
107 
108 	return UNCONF;
109 }
110