1*957f3eeaSvisa /* $OpenBSD: mainbus.c,v 1.13 2020/08/28 15:07:55 visa Exp $ */
2c6b2ceb4Ssyuu
3c6b2ceb4Ssyuu /*
4c6b2ceb4Ssyuu * Copyright (c) 2001-2003 Opsycon AB (www.opsycon.se / www.opsycon.com)
5c6b2ceb4Ssyuu *
6c6b2ceb4Ssyuu * Redistribution and use in source and binary forms, with or without
7c6b2ceb4Ssyuu * modification, are permitted provided that the following conditions
8c6b2ceb4Ssyuu * are met:
9c6b2ceb4Ssyuu * 1. Redistributions of source code must retain the above copyright
10c6b2ceb4Ssyuu * notice, this list of conditions and the following disclaimer.
11c6b2ceb4Ssyuu * 2. Redistributions in binary form must reproduce the above copyright
12c6b2ceb4Ssyuu * notice, this list of conditions and the following disclaimer in the
13c6b2ceb4Ssyuu * documentation and/or other materials provided with the distribution.
14c6b2ceb4Ssyuu *
15c6b2ceb4Ssyuu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16c6b2ceb4Ssyuu * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17c6b2ceb4Ssyuu * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18c6b2ceb4Ssyuu * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19c6b2ceb4Ssyuu * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20c6b2ceb4Ssyuu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21c6b2ceb4Ssyuu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22c6b2ceb4Ssyuu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23c6b2ceb4Ssyuu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24c6b2ceb4Ssyuu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25c6b2ceb4Ssyuu * SUCH DAMAGE.
26c6b2ceb4Ssyuu *
27c6b2ceb4Ssyuu */
28c6b2ceb4Ssyuu
29c6b2ceb4Ssyuu #include <sys/param.h>
30c6b2ceb4Ssyuu #include <sys/systm.h>
31c6b2ceb4Ssyuu #include <sys/device.h>
32*957f3eeaSvisa #include <sys/malloc.h>
33c6b2ceb4Ssyuu
34*957f3eeaSvisa #include <dev/ofw/openfirm.h>
35c6b2ceb4Ssyuu #include <machine/autoconf.h>
3618dfececSvisa #include <machine/octeonvar.h>
37c6b2ceb4Ssyuu
38d4086a48Svisa #include <octeon/dev/cn30xxcorereg.h>
39d4086a48Svisa
40c6b2ceb4Ssyuu int mainbus_match(struct device *, void *, void *);
41c6b2ceb4Ssyuu void mainbus_attach(struct device *, struct device *, void *);
42c6b2ceb4Ssyuu int mainbus_print(void *, const char *);
43c6b2ceb4Ssyuu
44c6b2ceb4Ssyuu const struct cfattach mainbus_ca = {
45c6b2ceb4Ssyuu sizeof(struct device), mainbus_match, mainbus_attach
46c6b2ceb4Ssyuu };
47c6b2ceb4Ssyuu
48c6b2ceb4Ssyuu struct cfdriver mainbus_cd = {
49c6b2ceb4Ssyuu NULL, "mainbus", DV_DULL
50c6b2ceb4Ssyuu };
51c6b2ceb4Ssyuu
52c6b2ceb4Ssyuu int
mainbus_match(struct device * parent,void * cfdata,void * aux)53c6b2ceb4Ssyuu mainbus_match(struct device *parent, void *cfdata, void *aux)
54c6b2ceb4Ssyuu {
55c6b2ceb4Ssyuu static int mainbus_attached = 0;
56c6b2ceb4Ssyuu
57c6b2ceb4Ssyuu if (mainbus_attached != 0)
58c6b2ceb4Ssyuu return 0;
59c6b2ceb4Ssyuu
60c6b2ceb4Ssyuu return mainbus_attached = 1;
61c6b2ceb4Ssyuu }
62c6b2ceb4Ssyuu
63c6b2ceb4Ssyuu void
mainbus_attach(struct device * parent,struct device * self,void * aux)64c6b2ceb4Ssyuu mainbus_attach(struct device *parent, struct device *self, void *aux)
65c6b2ceb4Ssyuu {
66c6b2ceb4Ssyuu struct cpu_attach_args caa;
67*957f3eeaSvisa char model[128];
68*957f3eeaSvisa int len, node;
69c6b2ceb4Ssyuu #ifdef MULTIPROCESSOR
70c6b2ceb4Ssyuu struct cpu_hwinfo hw;
7118dfececSvisa int cpuid;
72c6b2ceb4Ssyuu #endif
73c6b2ceb4Ssyuu
74*957f3eeaSvisa printf(": board %u rev %u.%u", octeon_boot_info->board_type,
752827814cSvisa octeon_boot_info->board_rev_major,
762827814cSvisa octeon_boot_info->board_rev_minor);
7705aabe32Smiod
78*957f3eeaSvisa node = OF_peer(0);
79*957f3eeaSvisa if (node != 0) {
80*957f3eeaSvisa len = OF_getprop(node, "model", model, sizeof(model));
81*957f3eeaSvisa if (len > 0) {
82*957f3eeaSvisa printf(", model %s", model);
83*957f3eeaSvisa hw_prod = malloc(len, M_DEVBUF, M_NOWAIT);
84*957f3eeaSvisa if (hw_prod != NULL)
85*957f3eeaSvisa strlcpy(hw_prod, model, len);
86*957f3eeaSvisa }
87*957f3eeaSvisa }
88*957f3eeaSvisa
89*957f3eeaSvisa printf("\n");
90*957f3eeaSvisa
91c6b2ceb4Ssyuu bzero(&caa, sizeof caa);
92c6b2ceb4Ssyuu caa.caa_maa.maa_name = "cpu";
93c6b2ceb4Ssyuu caa.caa_hw = &bootcpu_hwinfo;
94c6b2ceb4Ssyuu config_found(self, &caa, mainbus_print);
95c6b2ceb4Ssyuu
96c6b2ceb4Ssyuu #ifdef MULTIPROCESSOR
9792611b2eSvisa for (cpuid = 1; cpuid < MAXCPUS &&
9818dfececSvisa octeon_boot_info->core_mask & (1 << cpuid); cpuid++) {
99c6b2ceb4Ssyuu bcopy(&bootcpu_hwinfo, &hw, sizeof(struct cpu_hwinfo));
100c6b2ceb4Ssyuu caa.caa_hw = &hw;
101c6b2ceb4Ssyuu config_found(self, &caa, mainbus_print);
10218dfececSvisa }
103c6b2ceb4Ssyuu #endif
104c6b2ceb4Ssyuu
105c6b2ceb4Ssyuu caa.caa_maa.maa_name = "clock";
106c6b2ceb4Ssyuu config_found(self, &caa.caa_maa, mainbus_print);
107c6b2ceb4Ssyuu
108c6b2ceb4Ssyuu /* on-board I/O */
10961e15267Ssyuu caa.caa_maa.maa_name = "iobus";
110c6b2ceb4Ssyuu config_found(self, &caa.caa_maa, mainbus_print);
1111d0b786fSpirofti
1121d0b786fSpirofti caa.caa_maa.maa_name = "octrtc";
1131d0b786fSpirofti config_found(self, &caa.caa_maa, mainbus_print);
1141d0b786fSpirofti
115d4086a48Svisa #ifdef CRYPTO
116d4086a48Svisa if (!ISSET(octeon_get_cvmctl(), COP_0_CVMCTL_NOCRYPTO)) {
117d4086a48Svisa caa.caa_maa.maa_name = "octcrypto";
118d4086a48Svisa config_found(self, &caa.caa_maa, mainbus_print);
119d4086a48Svisa }
120d4086a48Svisa #endif
121c6b2ceb4Ssyuu }
122c6b2ceb4Ssyuu
123c6b2ceb4Ssyuu int
mainbus_print(void * aux,const char * pnp)124c6b2ceb4Ssyuu mainbus_print(void *aux, const char *pnp)
125c6b2ceb4Ssyuu {
126c6b2ceb4Ssyuu return pnp != NULL ? QUIET : UNCONF;
127c6b2ceb4Ssyuu }
128