Home | History | Annotate | Line # | Download | only in hb68k
      1 /*	$NetBSD: autoconf.c,v 1.1 2026/07/19 01:48:21 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988 University of Utah.
      5  * Copyright (c) 1982, 1986, 1990, 1993
      6  * 	The Regents of the University of California. All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * the Systems Programming Group of the University of Utah Computer
     10  * Science Department.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  * from: Utah $Hdr: autoconf.c 1.36 92/12/20$
     37  *
     38  *	@(#)autoconf.c  8.2 (Berkeley) 1/12/94
     39  */
     40 
     41 /*
     42  * Setup the system to run on the current machine.
     43  *
     44  * Configure() is called at boot time.
     45  */
     46 
     47 #include <sys/cdefs.h>
     48 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.1 2026/07/19 01:48:21 thorpej Exp $");
     49 
     50 #include <sys/param.h>
     51 #include <sys/systm.h>
     52 #include <sys/buf.h>
     53 #include <sys/conf.h>
     54 #include <sys/cpu.h>
     55 #include <sys/reboot.h>
     56 #include <sys/device.h>
     57 
     58 #include <dev/fdt/fdtvar.h>
     59 #include <dev/fdt/fdt_boot.h>
     60 #include <dev/fdt/fdt_platform.h>
     61 
     62 #include <dev/ofw/openfirm.h>
     63 
     64 #include <machine/intr.h>
     65 
     66 /*
     67  * Determine mass storage and memory configuration for a machine.
     68  */
     69 void
     70 cpu_configure(void)
     71 {
     72 
     73 	booted_device = NULL;	/* set by device drivers (if found) */
     74 
     75 	if (config_rootfound("fdtroot", NULL) == NULL)
     76 		panic("autoconfig failed, no root");
     77 
     78 	spl0();
     79 }
     80 
     81 /*
     82  * This is our "private" copy of booted_device; we'll use it if other
     83  * mechanisms don't work out.
     84  */
     85 device_t machine_booted_device;
     86 
     87 /* Maximum size is NAME=wedgename\0 */
     88 #define	MAX_BOOTSPEC	(128 + 6)
     89 static char bootspec_buf[MAX_BOOTSPEC + 1];
     90 
     91 const char *
     92 machine_set_bootspec(const char *cp)
     93 {
     94 	int i;
     95 
     96 	for (i = 0; i < MAX_BOOTSPEC; i++) {
     97 		if (*cp == '\0' || *cp == ' ' || *cp == '\t') {
     98 			break;
     99 		}
    100 		bootspec_buf[i] = *cp++;
    101 	}
    102 	bootspec_buf[i] = '\0';
    103 	bootspec = bootspec_buf;
    104 	while (! (*cp == '\0' || *cp == ' ' || *cp == '\t')) {
    105 		cp++;
    106 	}
    107 	return cp;
    108 }
    109 
    110 void
    111 cpu_rootconf(void)
    112 {
    113 #if 0
    114 	bootinfo_setup_initrd();
    115 #endif
    116 
    117 	/*
    118 	 * See if we can determine the boot device from generic
    119 	 * properties in the device tree.  If we can't figure it
    120 	 * out that way, then we'll use what device_register()
    121 	 * was able to find.
    122 	 */
    123 	fdt_cpu_rootconf();
    124 	if (booted_device == NULL) {
    125 		booted_device = machine_booted_device;
    126 	}
    127 
    128 	if (booted_device != NULL && machine_booted_device != NULL &&
    129 	    booted_device != machine_booted_device) {
    130 		aprint_normal("boot device: %s (%s)\n",
    131 		    device_xname(booted_device),
    132 		    device_xname(machine_booted_device));
    133 	} else {
    134 		aprint_normal("boot device: %s\n",
    135 		    booted_device != NULL ? device_xname(booted_device)
    136 					  : "<unknown>");
    137 	}
    138 	rootconf();
    139 }
    140 
    141 void
    142 device_register(device_t dev, void *aux)
    143 {
    144 	const struct fdt_platform *plat = machine_platform();
    145 
    146 	if (plat->fp_device_register != NULL) {
    147 		(*plat->fp_device_register)(dev, aux);
    148 	}
    149 }
    150