Home | History | Annotate | Line # | Download | only in ibmnws
      1 /*	$NetBSD: autoconf.c,v 1.13 2025/10/13 14:12:13 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1990 The Regents of the University of California.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * William Jolitz.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the University of
     21  *	California, Berkeley and its contributors.
     22  * 4. Neither the name of the University nor the names of its contributors
     23  *    may be used to endorse or promote products derived from this software
     24  *    without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  * SUCH DAMAGE.
     37  *
     38  *	@(#)autoconf.c	7.1 (Berkeley) 5/9/91
     39  */
     40 
     41 /*
     42  * Setup the system to run on the current machine.
     43  *
     44  * Configure() is called at boot time and initializes the vba
     45  * device tables and the memory controller monitoring.  Available
     46  * devices are determined (from possibilities mentioned in ioconf.c),
     47  * and the drivers are initialized.
     48  */
     49 #include <sys/param.h>
     50 #include <sys/systm.h>
     51 #include <sys/buf.h>
     52 #include <sys/dkstat.h>
     53 #include <sys/disklabel.h>
     54 #include <sys/conf.h>
     55 #include <sys/reboot.h>
     56 #include <sys/device.h>
     57 
     58 #include <dev/pci/pcivar.h>
     59 
     60 #include <machine/pte.h>
     61 #include <machine/intr.h>
     62 
     63 static void findroot(void);
     64 
     65 /*
     66  * Determine i/o configuration for a machine.
     67  */
     68 void
     69 cpu_configure(void)
     70 {
     71 
     72 	if (config_rootfound("mainbus", NULL) == NULL)
     73 		panic("configure: mainbus not configured");
     74 
     75 	genppc_cpu_configure();
     76 }
     77 
     78 void
     79 cpu_rootconf(void)
     80 {
     81 	findroot();
     82 
     83 	aprint_normal("boot device: %s\n",
     84 	    booted_device ? device_xname(booted_device) : "<unknown>");
     85 
     86 	rootconf();
     87 }
     88 
     89 u_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
     90 
     91 /*
     92  * Attempt to find the device from which we were booted.
     93  * If we can do so, and not instructed not to do so,
     94  * change rootdev to correspond to the load device.
     95  */
     96 void
     97 findroot(void)
     98 {
     99 	int unit, part;
    100 	device_t dv;
    101 	const char *name;
    102 
    103 #if 0
    104 	aprint_normal("howto %x bootdev %x ", boothowto, bootdev);
    105 #endif
    106 
    107 	if ((bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
    108 		return;
    109 
    110 	name = devsw_blk2name((bootdev >> B_TYPESHIFT) & B_TYPEMASK);
    111 	if (name == NULL)
    112 		return;
    113 
    114 	part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
    115 	unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
    116 
    117 	if ((dv = device_find_by_driver_unit(name, unit)) != NULL) {
    118 		booted_device = dv;
    119 		booted_partition = part;
    120 	}
    121 }
    122 
    123 #define	BUILTIN_ETHERNET_P(pa)						\
    124 	((pa)->pa_bus == 0 && (pa)->pa_device == 2 && (pa)->pa_function == 0)
    125 
    126 #define	BUILTIN_VIDEO_P(pa)						\
    127 	((pa)->pa_bus == 0 && (pa)->pa_device == 4 && (pa)->pa_function == 0)
    128 
    129 void
    130 device_register(device_t dev, void *aux)
    131 {
    132 	device_t pdev;
    133 	prop_dictionary_t dict;
    134 
    135 	if ((pdev = device_parent(dev)) != NULL && device_is_a(pdev, "pci")) {
    136 		struct pci_attach_args *pa = aux;
    137 
    138 		dict = device_properties(dev);
    139 		if (BUILTIN_ETHERNET_P(pa)) {
    140 			if (! device_setprop_bool(dev, "am79c970-no-eeprom",
    141 						  true)) {
    142 				aprint_normal("WARNING: unable to set "
    143 				       "am79c970-no-eeprom property for %s\n",
    144 				       device_xname(dev));
    145 			}
    146 		}
    147 
    148 		if (BUILTIN_VIDEO_P(pa)) {
    149 			if (! prop_dictionary_set_uint32(dict,  "width", 1024)) {
    150 				aprint_normal("WARNING: unable to set "
    151 					      "width property for %s\n",
    152 					      device_xname(dev));
    153 			}
    154 			if (! prop_dictionary_set_uint32(dict,  "height", 768)) {
    155 				aprint_normal("WARNING: unable to set "
    156 					      "height property for %s\n",
    157 					      device_xname(dev));
    158 			}
    159 			if (! prop_dictionary_set_uint32(dict,  "depth", 8)) {
    160 				aprint_normal("WARNING: unable to set "
    161 					      "depth property for %s\n",
    162 					      device_xname(dev));
    163 			}
    164 			if (! prop_dictionary_set_uint32(dict,  "address", 0)) {
    165 				aprint_normal("WARNING: unable to set "
    166 					      "address property for %s\n",
    167 					      device_xname(dev));
    168 			}
    169 			if (! device_setprop_bool(dev, "is_console", true)) {
    170 				aprint_normal("WARNING: unable to set "
    171 					      "is_console property for %s\n",
    172 					      device_xname(dev));
    173 			}
    174 
    175 		}
    176 	}
    177 }
    178