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