xref: /openbsd-src/sys/arch/octeon/dev/mainbus.c (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1 /*	$OpenBSD: mainbus.c,v 1.12 2018/04/09 13:46:15 visa Exp $ */
2 
3 /*
4  * Copyright (c) 2001-2003 Opsycon AB  (www.opsycon.se / www.opsycon.com)
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  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  */
28 
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/device.h>
32 
33 #include <machine/autoconf.h>
34 #include <machine/octeonvar.h>
35 
36 #include <octeon/dev/cn30xxcorereg.h>
37 
38 int	mainbus_match(struct device *, void *, void *);
39 void	mainbus_attach(struct device *, struct device *, void *);
40 int	mainbus_print(void *, const char *);
41 
42 const struct cfattach mainbus_ca = {
43 	sizeof(struct device), mainbus_match, mainbus_attach
44 };
45 
46 struct cfdriver mainbus_cd = {
47 	NULL, "mainbus", DV_DULL
48 };
49 
50 int
51 mainbus_match(struct device *parent, void *cfdata, void *aux)
52 {
53 	static int mainbus_attached = 0;
54 
55 	if (mainbus_attached != 0)
56 		return 0;
57 
58 	return mainbus_attached = 1;
59 }
60 
61 void
62 mainbus_attach(struct device *parent, struct device *self, void *aux)
63 {
64 	struct cpu_attach_args caa;
65 #ifdef MULTIPROCESSOR
66 	struct cpu_hwinfo hw;
67 	int cpuid;
68 #endif
69 
70 	printf(": board %u rev %u.%u\n", octeon_boot_info->board_type,
71 	    octeon_boot_info->board_rev_major,
72 	    octeon_boot_info->board_rev_minor);
73 
74 	bzero(&caa, sizeof caa);
75 	caa.caa_maa.maa_name = "cpu";
76 	caa.caa_hw = &bootcpu_hwinfo;
77 	config_found(self, &caa, mainbus_print);
78 
79 #ifdef MULTIPROCESSOR
80 	for (cpuid = 1; cpuid < MAXCPUS &&
81 	    octeon_boot_info->core_mask & (1 << cpuid); cpuid++) {
82 		bcopy(&bootcpu_hwinfo, &hw, sizeof(struct cpu_hwinfo));
83 		caa.caa_hw = &hw;
84 		config_found(self, &caa, mainbus_print);
85 	}
86 #endif
87 
88 	caa.caa_maa.maa_name = "clock";
89 	config_found(self, &caa.caa_maa, mainbus_print);
90 
91 	/* on-board I/O */
92 	caa.caa_maa.maa_name = "iobus";
93 	config_found(self, &caa.caa_maa, mainbus_print);
94 
95 	caa.caa_maa.maa_name = "octrtc";
96 	config_found(self, &caa.caa_maa, mainbus_print);
97 
98 #ifdef CRYPTO
99 	if (!ISSET(octeon_get_cvmctl(), COP_0_CVMCTL_NOCRYPTO)) {
100 		caa.caa_maa.maa_name = "octcrypto";
101 		config_found(self, &caa.caa_maa, mainbus_print);
102 	}
103 #endif
104 }
105 
106 int
107 mainbus_print(void *aux, const char *pnp)
108 {
109 	return pnp != NULL ? QUIET : UNCONF;
110 }
111