rump_autoconf.c revision 1.2 1 1.2 thorpej /* $NetBSD: rump_autoconf.c,v 1.2 2021/04/24 23:37:01 thorpej Exp $ */
2 1.1 bad
3 1.1 bad /*
4 1.1 bad * Copyright (c) 2009 Antti Kantee. All Rights Reserved.
5 1.1 bad *
6 1.1 bad * Redistribution and use in source and binary forms, with or without
7 1.1 bad * modification, are permitted provided that the following conditions
8 1.1 bad * are met:
9 1.1 bad * 1. Redistributions of source code must retain the above copyright
10 1.1 bad * notice, this list of conditions and the following disclaimer.
11 1.1 bad * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 bad * notice, this list of conditions and the following disclaimer in the
13 1.1 bad * documentation and/or other materials provided with the distribution.
14 1.1 bad *
15 1.1 bad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 1.1 bad * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 1.1 bad * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 1.1 bad * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.1 bad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.1 bad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 1.1 bad * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 bad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.1 bad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1 bad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1 bad * SUCH DAMAGE.
26 1.1 bad */
27 1.1 bad
28 1.1 bad #include <sys/cdefs.h>
29 1.2 thorpej __KERNEL_RCSID(0, "$NetBSD: rump_autoconf.c,v 1.2 2021/04/24 23:37:01 thorpej Exp $");
30 1.1 bad
31 1.1 bad #include <sys/param.h>
32 1.1 bad #include <sys/device.h>
33 1.1 bad #include <sys/kernel.h>
34 1.1 bad
35 1.1 bad static int mainbus_match(device_t, cfdata_t, void *);
36 1.1 bad static void mainbus_attach(device_t, device_t, void *);
37 1.1 bad static int mainbus_search(device_t, cfdata_t, const int *, void *);
38 1.1 bad
39 1.1 bad struct mainbus_softc {
40 1.1 bad int mb_nada;
41 1.1 bad };
42 1.1 bad
43 1.1 bad /*
44 1.1 bad * Initial lists as required by autoconf(9). The data from ioconf.c
45 1.1 bad * is patched in by rump_mainbus_init().
46 1.1 bad */
47 1.1 bad const struct cfattachinit cfattachinit[] = {
48 1.1 bad { NULL, NULL },
49 1.1 bad };
50 1.1 bad struct cfdata cfdata[] = {
51 1.1 bad { NULL, NULL, 0, FSTATE_NOTFOUND, NULL, 0, NULL}, /* replaced by init */
52 1.1 bad { NULL, NULL, 0, FSTATE_NOTFOUND, NULL, 0, NULL},
53 1.1 bad };
54 1.1 bad struct cfdriver * const cfdriver_list_initial[] = {
55 1.1 bad NULL,
56 1.1 bad };
57 1.1 bad
58 1.1 bad #include "ioconf.c"
59 1.1 bad
60 1.1 bad CFATTACH_DECL_NEW(mainbus, sizeof(struct mainbus_softc),
61 1.1 bad mainbus_match, mainbus_attach, NULL, NULL);
62 1.1 bad
63 1.1 bad const short cfroots[] = {
64 1.1 bad 0, /* mainbus */
65 1.1 bad -1
66 1.1 bad };
67 1.1 bad
68 1.1 bad /* actually used */
69 1.1 bad #define MAXPDEVS 256
70 1.1 bad struct pdevinit pdevinit[MAXPDEVS] = {{NULL,0}, }; /* XXX: static limit */
71 1.1 bad static int pdev_total = 0;
72 1.1 bad
73 1.1 bad #include <rump-sys/dev.h>
74 1.1 bad
75 1.1 bad void
76 1.1 bad rump_pdev_add(void (*pdev_attach)(int), int pdev_count)
77 1.1 bad {
78 1.1 bad struct pdevinit *pdev_new;
79 1.1 bad
80 1.1 bad KASSERT(cold);
81 1.1 bad
82 1.1 bad pdev_new = &pdevinit[pdev_total];
83 1.1 bad pdev_new->pdev_attach = pdev_attach;
84 1.1 bad pdev_new->pdev_count = pdev_count;
85 1.1 bad
86 1.1 bad pdev_total++;
87 1.1 bad KASSERT(pdev_total < MAXPDEVS);
88 1.1 bad }
89 1.1 bad
90 1.1 bad void
91 1.1 bad rump_pdev_finalize()
92 1.1 bad {
93 1.1 bad
94 1.1 bad rump_pdev_add(NULL, 0);
95 1.1 bad }
96 1.1 bad
97 1.1 bad static int
98 1.1 bad mainbus_match(device_t parent, cfdata_t match, void *aux)
99 1.1 bad {
100 1.1 bad
101 1.1 bad return 1;
102 1.1 bad }
103 1.1 bad
104 1.1 bad static void
105 1.1 bad mainbus_attach(device_t parent, device_t self, void *aux)
106 1.1 bad {
107 1.1 bad
108 1.1 bad aprint_normal("\n");
109 1.2 thorpej config_search(self, NULL,
110 1.2 thorpej CFARG_SEARCH, mainbus_search,
111 1.2 thorpej CFARG_IATTR, "mainbus",
112 1.2 thorpej CFARG_EOL);
113 1.1 bad }
114 1.1 bad
115 1.1 bad static int
116 1.1 bad mainbus_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
117 1.1 bad {
118 1.1 bad struct mainbus_attach_args maa;
119 1.1 bad
120 1.1 bad maa.maa_unit = cf->cf_unit;
121 1.2 thorpej if (config_probe(parent, cf, &maa))
122 1.2 thorpej config_attach(parent, cf, &maa, NULL, CFARG_EOL);
123 1.1 bad
124 1.1 bad return 0;
125 1.1 bad }
126 1.1 bad
127 1.1 bad void
128 1.1 bad rump_mainbus_init(void)
129 1.1 bad {
130 1.1 bad
131 1.1 bad /* replace cfdata[0] to a state expected by autoconf(9) */
132 1.1 bad memcpy(&cfdata[0], &cfdata_ioconf_mainbus[0], sizeof(cfdata[0]));
133 1.1 bad }
134 1.1 bad
135 1.1 bad void
136 1.1 bad rump_mainbus_attach(void)
137 1.1 bad {
138 1.1 bad const struct cfattachinit *cfai = &cfattach_ioconf_mainbus[0];
139 1.1 bad
140 1.1 bad config_cfdata_attach(cfdata, 0);
141 1.1 bad config_cfdriver_attach(cfdriver_ioconf_mainbus[0]);
142 1.1 bad config_cfattach_attach(cfai->cfai_name, cfai->cfai_list[0]);
143 1.1 bad }
144