1 /* $NetBSD: rump_autoconf.c,v 1.3 2021/08/07 16:19:18 thorpej 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.3 2021/08/07 16:19:18 thorpej 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(self, NULL, 110 CFARGS(.search = mainbus_search, 111 .iattr = "mainbus")); 112 } 113 114 static int 115 mainbus_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux) 116 { 117 struct mainbus_attach_args maa; 118 119 maa.maa_unit = cf->cf_unit; 120 if (config_probe(parent, cf, &maa)) 121 config_attach(parent, cf, &maa, NULL, CFARGS_NONE); 122 123 return 0; 124 } 125 126 void 127 rump_mainbus_init(void) 128 { 129 130 /* replace cfdata[0] to a state expected by autoconf(9) */ 131 memcpy(&cfdata[0], &cfdata_ioconf_mainbus[0], sizeof(cfdata[0])); 132 } 133 134 void 135 rump_mainbus_attach(void) 136 { 137 const struct cfattachinit *cfai = &cfattach_ioconf_mainbus[0]; 138 139 config_cfdata_attach(cfdata, 0); 140 config_cfdriver_attach(cfdriver_ioconf_mainbus[0]); 141 config_cfattach_attach(cfai->cfai_name, cfai->cfai_list[0]); 142 } 143