1*c7fb772bSthorpej /* $NetBSD: mainbus.c,v 1.12 2021/08/07 16:19:07 thorpej Exp $ */
238365ca3Sjmcneill
338365ca3Sjmcneill /*-
438365ca3Sjmcneill * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
538365ca3Sjmcneill * All rights reserved.
638365ca3Sjmcneill *
738365ca3Sjmcneill * Redistribution and use in source and binary forms, with or without
838365ca3Sjmcneill * modification, are permitted provided that the following conditions
938365ca3Sjmcneill * are met:
1038365ca3Sjmcneill * 1. Redistributions of source code must retain the above copyright
1138365ca3Sjmcneill * notice, this list of conditions and the following disclaimer.
1238365ca3Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright
1338365ca3Sjmcneill * notice, this list of conditions and the following disclaimer in the
1438365ca3Sjmcneill * documentation and/or other materials provided with the distribution.
1538365ca3Sjmcneill *
1638365ca3Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1738365ca3Sjmcneill * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1838365ca3Sjmcneill * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1938365ca3Sjmcneill * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2038365ca3Sjmcneill * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2138365ca3Sjmcneill * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2238365ca3Sjmcneill * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2338365ca3Sjmcneill * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2438365ca3Sjmcneill * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2538365ca3Sjmcneill * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2638365ca3Sjmcneill * POSSIBILITY OF SUCH DAMAGE.
2738365ca3Sjmcneill */
2838365ca3Sjmcneill
2938365ca3Sjmcneill #include <sys/cdefs.h>
30*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.12 2021/08/07 16:19:07 thorpej Exp $");
3138365ca3Sjmcneill
3238365ca3Sjmcneill #include <sys/param.h>
3338365ca3Sjmcneill #include <sys/proc.h>
3438365ca3Sjmcneill #include <sys/systm.h>
3538365ca3Sjmcneill #include <sys/device.h>
3638365ca3Sjmcneill
3738365ca3Sjmcneill #include <dev/cons.h>
3838365ca3Sjmcneill
3938365ca3Sjmcneill #include <machine/mainbus.h>
4038365ca3Sjmcneill
4138365ca3Sjmcneill static int mainbus_match(device_t, cfdata_t, void *);
4238365ca3Sjmcneill static void mainbus_attach(device_t, device_t, void *);
4338365ca3Sjmcneill
4438365ca3Sjmcneill static int mainbus_print(void *, const char *);
4538365ca3Sjmcneill
4638365ca3Sjmcneill typedef struct mainbus_softc {
4738365ca3Sjmcneill device_t sc_dev;
4838365ca3Sjmcneill } mainbus_softc_t;
4938365ca3Sjmcneill
5038365ca3Sjmcneill CFATTACH_DECL_NEW(mainbus, sizeof(mainbus_softc_t),
5138365ca3Sjmcneill mainbus_match, mainbus_attach, NULL, NULL);
5238365ca3Sjmcneill
5301a67a2dSjmcneill extern char *usermode_disk_image_path[];
5401a67a2dSjmcneill extern int usermode_disk_image_path_count;
55efbd3dcdSreinoud extern int usermode_vdev_type[];
56efbd3dcdSreinoud extern char *usermode_vdev_path[];
57efbd3dcdSreinoud extern int usermode_vdev_count;
5889596f3bSjmcneill extern char *usermode_tap_device;
5989596f3bSjmcneill extern char *usermode_tap_eaddr;
6051fb3691Sjmcneill extern char *usermode_audio_device;
614f5a27acSjmcneill extern int usermode_vnc_width, usermode_vnc_height, usermode_vnc_port;
62ce6e29d2Sjmcneill
6338365ca3Sjmcneill static int
mainbus_match(device_t parent,cfdata_t match,void * opaque)6438365ca3Sjmcneill mainbus_match(device_t parent, cfdata_t match, void *opaque)
6538365ca3Sjmcneill {
6638365ca3Sjmcneill
6738365ca3Sjmcneill return 1;
6838365ca3Sjmcneill }
6938365ca3Sjmcneill
7038365ca3Sjmcneill static void
mainbus_attach(device_t parent,device_t self,void * opaque)7138365ca3Sjmcneill mainbus_attach(device_t parent, device_t self, void *opaque)
7238365ca3Sjmcneill {
7338365ca3Sjmcneill mainbus_softc_t *sc = device_private(self);
7438365ca3Sjmcneill struct thunkbus_attach_args taa;
7501a67a2dSjmcneill int i;
7638365ca3Sjmcneill
7738365ca3Sjmcneill aprint_naive("\n");
7838365ca3Sjmcneill aprint_normal("\n");
7938365ca3Sjmcneill
8038365ca3Sjmcneill sc->sc_dev = self;
8138365ca3Sjmcneill
8238365ca3Sjmcneill taa.taa_type = THUNKBUS_TYPE_CPU;
83*c7fb772bSthorpej config_found(self, &taa, mainbus_print, CFARGS_NONE);
84e753c7b9Sjmcneill
854f5a27acSjmcneill taa.taa_type = THUNKBUS_TYPE_TTYCONS;
86*c7fb772bSthorpej config_found(self, &taa, mainbus_print, CFARGS_NONE);
874f5a27acSjmcneill
884f5a27acSjmcneill if (usermode_vnc_port > 0 && usermode_vnc_port < 65536) {
894f5a27acSjmcneill taa.taa_type = THUNKBUS_TYPE_VNCFB;
904f5a27acSjmcneill taa.u.vnc.width = usermode_vnc_width;
914f5a27acSjmcneill taa.u.vnc.height = usermode_vnc_height;
924f5a27acSjmcneill taa.u.vnc.port = usermode_vnc_port;
93*c7fb772bSthorpej config_found(self, &taa, mainbus_print, CFARGS_NONE);
944f5a27acSjmcneill }
95e753c7b9Sjmcneill
9638365ca3Sjmcneill taa.taa_type = THUNKBUS_TYPE_CLOCK;
97*c7fb772bSthorpej config_found(self, &taa, mainbus_print, CFARGS_NONE);
98e753c7b9Sjmcneill
9989596f3bSjmcneill if (usermode_tap_device) {
10089596f3bSjmcneill taa.taa_type = THUNKBUS_TYPE_VETH;
10189596f3bSjmcneill taa.u.veth.device = usermode_tap_device;
10289596f3bSjmcneill taa.u.veth.eaddr = usermode_tap_eaddr;
103*c7fb772bSthorpej config_found(self, &taa, mainbus_print, CFARGS_NONE);
10489596f3bSjmcneill }
10589596f3bSjmcneill
10651fb3691Sjmcneill if (usermode_audio_device) {
10751fb3691Sjmcneill taa.taa_type = THUNKBUS_TYPE_VAUDIO;
10851fb3691Sjmcneill taa.u.vaudio.device = usermode_audio_device;
109*c7fb772bSthorpej config_found(self, &taa, mainbus_print, CFARGS_NONE);
11051fb3691Sjmcneill }
11151fb3691Sjmcneill
11201a67a2dSjmcneill for (i = 0; i < usermode_disk_image_path_count; i++) {
113ce6e29d2Sjmcneill taa.taa_type = THUNKBUS_TYPE_DISKIMAGE;
11401a67a2dSjmcneill taa.u.diskimage.path = usermode_disk_image_path[i];
115*c7fb772bSthorpej config_found(self, &taa, mainbus_print, CFARGS_NONE);
116ce6e29d2Sjmcneill }
117efbd3dcdSreinoud
118efbd3dcdSreinoud for (i = 0; i < usermode_vdev_count; i++) {
119efbd3dcdSreinoud taa.taa_type = usermode_vdev_type[i];
120efbd3dcdSreinoud taa.u.vdev.path = usermode_vdev_path[i];
121*c7fb772bSthorpej config_found(self, &taa, mainbus_print, CFARGS_NONE);
122efbd3dcdSreinoud }
12338365ca3Sjmcneill }
12438365ca3Sjmcneill
12538365ca3Sjmcneill static int
mainbus_print(void * opaque,const char * pnp)12638365ca3Sjmcneill mainbus_print(void *opaque, const char *pnp)
12738365ca3Sjmcneill {
12838365ca3Sjmcneill if (pnp)
12938365ca3Sjmcneill aprint_normal("%s", pnp);
13038365ca3Sjmcneill return UNCONF;
13138365ca3Sjmcneill }
132