11.1Sjmcneill/*	$NetBSD: autoconf.c,v 1.1 2026/01/09 22:54:28 jmcneill Exp $	*/
21.1Sjmcneill
31.1Sjmcneill/*-
41.1Sjmcneill * Copyright (c) 1990 The Regents of the University of California.
51.1Sjmcneill * All rights reserved.
61.1Sjmcneill *
71.1Sjmcneill * This code is derived from software contributed to Berkeley by
81.1Sjmcneill * William Jolitz.
91.1Sjmcneill *
101.1Sjmcneill * Redistribution and use in source and binary forms, with or without
111.1Sjmcneill * modification, are permitted provided that the following conditions
121.1Sjmcneill * are met:
131.1Sjmcneill * 1. Redistributions of source code must retain the above copyright
141.1Sjmcneill *    notice, this list of conditions and the following disclaimer.
151.1Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright
161.1Sjmcneill *    notice, this list of conditions and the following disclaimer in the
171.1Sjmcneill *    documentation and/or other materials provided with the distribution.
181.1Sjmcneill * 3. Neither the name of the University nor the names of its contributors
191.1Sjmcneill *    may be used to endorse or promote products derived from this software
201.1Sjmcneill *    without specific prior written permission.
211.1Sjmcneill *
221.1Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231.1Sjmcneill * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.1Sjmcneill * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.1Sjmcneill * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261.1Sjmcneill * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.1Sjmcneill * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.1Sjmcneill * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.1Sjmcneill * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.1Sjmcneill * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.1Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Sjmcneill * SUCH DAMAGE.
331.1Sjmcneill *
341.1Sjmcneill *	@(#)autoconf.c	7.1 (Berkeley) 5/9/91
351.1Sjmcneill */
361.1Sjmcneill
371.1Sjmcneill/*
381.1Sjmcneill * Setup the system to run on the current machine.
391.1Sjmcneill *
401.1Sjmcneill * Configure() is called at boot time and initializes the vba
411.1Sjmcneill * device tables and the memory controller monitoring.  Available
421.1Sjmcneill * devices are determined (from possibilities mentioned in ioconf.c),
431.1Sjmcneill * and the drivers are initialized.
441.1Sjmcneill */
451.1Sjmcneill
461.1Sjmcneill#include <sys/cdefs.h>
471.1Sjmcneill__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.1 2026/01/09 22:54:28 jmcneill Exp $");
481.1Sjmcneill
491.1Sjmcneill#include <sys/param.h>
501.1Sjmcneill#include <sys/systm.h>
511.1Sjmcneill#include <sys/buf.h>
521.1Sjmcneill#include <sys/disklabel.h>
531.1Sjmcneill#include <sys/conf.h>
541.1Sjmcneill#include <sys/reboot.h>
551.1Sjmcneill#include <sys/device.h>
561.1Sjmcneill#include <sys/boot_flag.h>
571.1Sjmcneill
581.1Sjmcneill#include <powerpc/pte.h>
591.1Sjmcneill
601.1Sjmcneill#include <machine/wii.h>
611.1Sjmcneill#include <machine/wiiu.h>
621.1Sjmcneill
631.1Sjmcneillvoid findroot(void);
641.1Sjmcneillvoid disable_intr(void);
651.1Sjmcneillvoid enable_intr(void);
661.1Sjmcneill
671.1Sjmcneillstatic void parse_cmdline(void);
681.1Sjmcneillconst char *get_cmdline(const char *);
691.1Sjmcneill
701.1Sjmcneill/*
711.1Sjmcneill * Determine i/o configuration for a machine.
721.1Sjmcneill */
731.1Sjmcneillvoid
741.1Sjmcneillcpu_configure(void)
751.1Sjmcneill{
761.1Sjmcneill	parse_cmdline();
771.1Sjmcneill
781.1Sjmcneill	if (config_rootfound("mainbus", NULL) == NULL)
791.1Sjmcneill		panic("configure: mainbus not configured");
801.1Sjmcneill
811.1Sjmcneill	genppc_cpu_configure();
821.1Sjmcneill
831.1Sjmcneill	if (!wiiu_plat) {
841.1Sjmcneill		wii_slot_led(false);
851.1Sjmcneill	}
861.1Sjmcneill}
871.1Sjmcneill
881.1Sjmcneillvoid
891.1Sjmcneillcpu_rootconf(void)
901.1Sjmcneill{
911.1Sjmcneill	findroot();
921.1Sjmcneill
931.1Sjmcneill	printf("boot device: %s\n",
941.1Sjmcneill	    booted_device ? device_xname(booted_device) : "<unknown>");
951.1Sjmcneill
961.1Sjmcneill	rootconf();
971.1Sjmcneill}
981.1Sjmcneill
991.1Sjmcneillvoid
1001.1Sjmcneillfindroot(void)
1011.1Sjmcneill{
1021.1Sjmcneill}
1031.1Sjmcneill
1041.1Sjmcneillvoid
1051.1Sjmcneilldevice_register(device_t dev, void *aux)
1061.1Sjmcneill{
1071.1Sjmcneill	if (bootspec != NULL && strcmp(device_xname(dev), bootspec) == 0) {
1081.1Sjmcneill		booted_device = dev;
1091.1Sjmcneill		booted_partition = 0;
1101.1Sjmcneill	}
1111.1Sjmcneill}
1121.1Sjmcneill
1131.1Sjmcneillstatic void
1141.1Sjmcneillparse_cmdline(void)
1151.1Sjmcneill{
1161.1Sjmcneill	static char bootspec_buf[64];
1171.1Sjmcneill	extern char wii_cmdline[];
1181.1Sjmcneill	const char *cmdline = wii_cmdline;
1191.1Sjmcneill
1201.1Sjmcneill	while (*cmdline != '\0') {
1211.1Sjmcneill		const char *cp = cmdline;
1221.1Sjmcneill
1231.1Sjmcneill		if (*cp == '-') {
1241.1Sjmcneill			for (cp++; *cp != '\0'; cp++) {
1251.1Sjmcneill				BOOT_FLAG(*cp, boothowto);
1261.1Sjmcneill			}
1271.1Sjmcneill		} else if (strncmp(cp, "root=", 5) == 0) {
1281.1Sjmcneill			snprintf(bootspec_buf, sizeof(bootspec_buf), "%s",
1291.1Sjmcneill			    cp + 5);
1301.1Sjmcneill			if (bootspec_buf[0] != '\0') {
1311.1Sjmcneill				bootspec = bootspec_buf;
1321.1Sjmcneill				booted_method = "bootinfo/rootdevice";
1331.1Sjmcneill			}
1341.1Sjmcneill		}
1351.1Sjmcneill
1361.1Sjmcneill		cmdline += strlen(cmdline) + 1;
1371.1Sjmcneill	}
1381.1Sjmcneill}
139