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