mainbus.c revision 1.2 1 /* $NetBSD: mainbus.c,v 1.2 2021/02/15 22:39:46 reinoud Exp $ */
2
3 /*-
4 * Copyright (c) 2021 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Simon Burge.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.2 2021/02/15 22:39:46 reinoud Exp $");
34
35 #include <sys/param.h>
36 #include <sys/device.h>
37
38 #include <evbmips/mipssim/autoconf.h>
39 #include <evbmips/mipssim/mipssimreg.h>
40 #include <evbmips/mipssim/mipssimvar.h>
41
42 static int mainbus_match(device_t, cfdata_t, void *);
43 static void mainbus_attach(device_t, device_t, void *);
44 static int mainbus_print(void *, const char *);
45
46 CFATTACH_DECL_NEW(mainbus, 0,
47 mainbus_match, mainbus_attach, NULL, NULL);
48
49 /* There can be only one. */
50 static int mainbus_found;
51
52 struct mainbusdev {
53 const char *md_name;
54 paddr_t md_addr;
55 int md_irq;
56 };
57
58 static struct mainbusdev mainbusdevs[] = {
59 { "cpu", },
60 { "com", MIPSSIM_UART0_ADDR, 2 },
61 #ifdef notyet
62 { "mipsnet", MIPSSIM_MIPSNET0_ADDR, 0 },
63 #endif
64 { NULL, }
65 };
66
67 static int
68 mainbus_match(device_t parent, cfdata_t match, void *aux)
69 {
70
71 if (mainbus_found)
72 return (0);
73
74 return (1);
75 }
76
77 static void
78 mainbus_attach(device_t parent, device_t self, void *aux)
79 {
80 struct mainbus_attach_args maa;
81 struct mipssim_config *mcp = &mipssim_configuration;
82 const struct mainbusdev *md;
83
84 mainbus_found = 1;
85 printf("\n");
86
87 /* attach children */
88 for (md = mainbusdevs; md->md_name != NULL; md++) {
89 maa.ma_name = md->md_name;
90 maa.ma_addr = md->md_addr;
91 maa.ma_irq = md->md_irq;
92 maa.ma_iot = &mcp->mc_iot;
93 maa.ma_dmat = &mcp->mc_dmat;
94 config_found_ia(self, "mainbus", &maa, mainbus_print);
95 }
96
97 /* attach virtio children */
98 for (int i = 0; i < VIRTIO_NUM_TRANSPORTS; i++) {
99 maa.ma_name = "virtio";
100 maa.ma_addr = MIPSSIM_VIRTIO_ADDR + VIRTIO_STRIDE * i;
101 maa.ma_irq = 1;
102 maa.ma_iot = &mcp->mc_iot;
103 maa.ma_dmat = &mcp->mc_dmat;
104 config_found_ia(self, "mainbus", &maa, mainbus_print);
105 }
106 }
107
108 static int
109 mainbus_print(void *aux, const char *pnp)
110 {
111
112 return (QUIET);
113 }
114