1 /* $OpenBSD: mainbus.c,v 1.13 2020/08/28 15:07:55 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 #include <sys/malloc.h>
33
34 #include <dev/ofw/openfirm.h>
35 #include <machine/autoconf.h>
36 #include <machine/octeonvar.h>
37
38 #include <octeon/dev/cn30xxcorereg.h>
39
40 int mainbus_match(struct device *, void *, void *);
41 void mainbus_attach(struct device *, struct device *, void *);
42 int mainbus_print(void *, const char *);
43
44 const struct cfattach mainbus_ca = {
45 sizeof(struct device), mainbus_match, mainbus_attach
46 };
47
48 struct cfdriver mainbus_cd = {
49 NULL, "mainbus", DV_DULL
50 };
51
52 int
mainbus_match(struct device * parent,void * cfdata,void * aux)53 mainbus_match(struct device *parent, void *cfdata, void *aux)
54 {
55 static int mainbus_attached = 0;
56
57 if (mainbus_attached != 0)
58 return 0;
59
60 return mainbus_attached = 1;
61 }
62
63 void
mainbus_attach(struct device * parent,struct device * self,void * aux)64 mainbus_attach(struct device *parent, struct device *self, void *aux)
65 {
66 struct cpu_attach_args caa;
67 char model[128];
68 int len, node;
69 #ifdef MULTIPROCESSOR
70 struct cpu_hwinfo hw;
71 int cpuid;
72 #endif
73
74 printf(": board %u rev %u.%u", octeon_boot_info->board_type,
75 octeon_boot_info->board_rev_major,
76 octeon_boot_info->board_rev_minor);
77
78 node = OF_peer(0);
79 if (node != 0) {
80 len = OF_getprop(node, "model", model, sizeof(model));
81 if (len > 0) {
82 printf(", model %s", model);
83 hw_prod = malloc(len, M_DEVBUF, M_NOWAIT);
84 if (hw_prod != NULL)
85 strlcpy(hw_prod, model, len);
86 }
87 }
88
89 printf("\n");
90
91 bzero(&caa, sizeof caa);
92 caa.caa_maa.maa_name = "cpu";
93 caa.caa_hw = &bootcpu_hwinfo;
94 config_found(self, &caa, mainbus_print);
95
96 #ifdef MULTIPROCESSOR
97 for (cpuid = 1; cpuid < MAXCPUS &&
98 octeon_boot_info->core_mask & (1 << cpuid); cpuid++) {
99 bcopy(&bootcpu_hwinfo, &hw, sizeof(struct cpu_hwinfo));
100 caa.caa_hw = &hw;
101 config_found(self, &caa, mainbus_print);
102 }
103 #endif
104
105 caa.caa_maa.maa_name = "clock";
106 config_found(self, &caa.caa_maa, mainbus_print);
107
108 /* on-board I/O */
109 caa.caa_maa.maa_name = "iobus";
110 config_found(self, &caa.caa_maa, mainbus_print);
111
112 caa.caa_maa.maa_name = "octrtc";
113 config_found(self, &caa.caa_maa, mainbus_print);
114
115 #ifdef CRYPTO
116 if (!ISSET(octeon_get_cvmctl(), COP_0_CVMCTL_NOCRYPTO)) {
117 caa.caa_maa.maa_name = "octcrypto";
118 config_found(self, &caa.caa_maa, mainbus_print);
119 }
120 #endif
121 }
122
123 int
mainbus_print(void * aux,const char * pnp)124 mainbus_print(void *aux, const char *pnp)
125 {
126 return pnp != NULL ? QUIET : UNCONF;
127 }
128