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