1 /* $NetBSD: mainbus.c,v 1.9 2021/08/07 16:18:51 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2014 Michael Lorenz
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 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.9 2021/08/07 16:18:51 thorpej Exp $");
31
32 #include "opt_multiprocessor.h"
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37
38 #include <mips/cache.h>
39 #include <mips/cpuregs.h>
40
41 #include <mips/ingenic/ingenic_regs.h>
42
43 #include "opt_ingenic.h"
44
45 #include "locators.h"
46
47 static int mainbus_match(device_t, cfdata_t, void *);
48 static void mainbus_attach(device_t, device_t, void *);
49 static int mainbus_print(void *, const char *);
50
51 CFATTACH_DECL_NEW(mainbus, 0,
52 mainbus_match, mainbus_attach, NULL, NULL);
53
54 /* There can be only one. */
55 int mainbus_found = 0;
56
57 struct mainbusdev {
58 const char *md_name;
59 };
60
61 struct mainbusdev mainbusdevs[] = {
62 { "cpu", },
63 #ifdef MULTIPROCESSOR
64 { "cpu", },
65 #endif
66 { "apbus", },
67 { NULL, }
68 };
69
70 static int
mainbus_match(device_t parent,cfdata_t match,void * aux)71 mainbus_match(device_t parent, cfdata_t match, void *aux)
72 {
73
74 if (mainbus_found)
75 return (0);
76
77 return (1);
78 }
79
80 static void
mainbus_attach(device_t parent,device_t self,void * aux)81 mainbus_attach(device_t parent, device_t self, void *aux)
82 {
83 const struct mainbusdev *md;
84
85 mainbus_found = 1;
86 printf("\n");
87
88 for (md = mainbusdevs; md->md_name != NULL; md++) {
89 struct mainbusdev ma = *md;
90 config_found(self, &ma, mainbus_print, CFARGS_NONE);
91 }
92
93 #ifdef INGENIC_DEBUG
94 printf("TFR: %08x\n", readreg(JZ_TC_TFR));
95 printf("TMR: %08x\n", readreg(JZ_TC_TMR));
96
97 /* send ourselves an IPI */
98 mips_cp0_corembox_write(0x12345678, 0);
99 delay(1000);
100
101 /* send the other core an IPI */
102 mips_cp0_corembox_write(0x12345678, 1);
103 delay(1000);
104 #endif
105 }
106
107 static int
mainbus_print(void * aux,const char * pnp)108 mainbus_print(void *aux, const char *pnp)
109 {
110
111 return (QUIET);
112 }
113