Home | History | Annotate | Line # | Download | only in oea
ofw_autoconf.c revision 1.2.4.2
      1  1.2.4.2  bouyer /* $NetBSD: ofw_autoconf.c,v 1.2.4.2 2007/11/13 15:59:07 bouyer Exp $ */
      2  1.2.4.2  bouyer /*
      3  1.2.4.2  bouyer  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      4  1.2.4.2  bouyer  * Copyright (C) 1995, 1996 TooLs GmbH.
      5  1.2.4.2  bouyer  * All rights reserved.
      6  1.2.4.2  bouyer  *
      7  1.2.4.2  bouyer  * Redistribution and use in source and binary forms, with or without
      8  1.2.4.2  bouyer  * modification, are permitted provided that the following conditions
      9  1.2.4.2  bouyer  * are met:
     10  1.2.4.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     11  1.2.4.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     12  1.2.4.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.2.4.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     14  1.2.4.2  bouyer  *    documentation and/or other materials provided with the distribution.
     15  1.2.4.2  bouyer  * 3. All advertising materials mentioning features or use of this software
     16  1.2.4.2  bouyer  *    must display the following acknowledgement:
     17  1.2.4.2  bouyer  *      This product includes software developed by TooLs GmbH.
     18  1.2.4.2  bouyer  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     19  1.2.4.2  bouyer  *    derived from this software without specific prior written permission.
     20  1.2.4.2  bouyer  *
     21  1.2.4.2  bouyer  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     22  1.2.4.2  bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.2.4.2  bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.2.4.2  bouyer  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     25  1.2.4.2  bouyer  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26  1.2.4.2  bouyer  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     27  1.2.4.2  bouyer  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     28  1.2.4.2  bouyer  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     29  1.2.4.2  bouyer  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     30  1.2.4.2  bouyer  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.2.4.2  bouyer  */
     32  1.2.4.2  bouyer 
     33  1.2.4.2  bouyer #include <sys/cdefs.h>
     34  1.2.4.2  bouyer __KERNEL_RCSID(0, "$NetBSD: ofw_autoconf.c,v 1.2.4.2 2007/11/13 15:59:07 bouyer Exp $");
     35  1.2.4.2  bouyer 
     36  1.2.4.2  bouyer #include <sys/param.h>
     37  1.2.4.2  bouyer #include <sys/conf.h>
     38  1.2.4.2  bouyer #include <sys/device.h>
     39  1.2.4.2  bouyer #include <sys/reboot.h>
     40  1.2.4.2  bouyer #include <sys/systm.h>
     41  1.2.4.2  bouyer 
     42  1.2.4.2  bouyer #include <uvm/uvm_extern.h>
     43  1.2.4.2  bouyer 
     44  1.2.4.2  bouyer #include <machine/autoconf.h>
     45  1.2.4.2  bouyer #include <machine/bus.h>
     46  1.2.4.2  bouyer #include <machine/stdarg.h>
     47  1.2.4.2  bouyer 
     48  1.2.4.2  bouyer #include <dev/ofw/openfirm.h>
     49  1.2.4.2  bouyer #include <dev/pci/pcivar.h>
     50  1.2.4.2  bouyer #include <dev/scsipi/scsi_all.h>
     51  1.2.4.2  bouyer #include <dev/scsipi/scsipi_all.h>
     52  1.2.4.2  bouyer #include <dev/scsipi/scsiconf.h>
     53  1.2.4.2  bouyer #include <dev/ata/atavar.h>
     54  1.2.4.2  bouyer #include <dev/ic/wdcvar.h>
     55  1.2.4.2  bouyer #include <dev/wsfb/genfbvar.h>
     56  1.2.4.2  bouyer 
     57  1.2.4.2  bouyer extern char bootpath[256];
     58  1.2.4.2  bouyer char cbootpath[256];
     59  1.2.4.2  bouyer int console_node = 0, console_instance = 0;
     60  1.2.4.2  bouyer 
     61  1.2.4.2  bouyer #ifdef macppc
     62  1.2.4.2  bouyer volatile uint32_t *heathrow_FCR = NULL;
     63  1.2.4.2  bouyer #endif
     64  1.2.4.2  bouyer 
     65  1.2.4.2  bouyer struct genfb_colormap_callback gfb_cb;
     66  1.2.4.2  bouyer static void of_set_palette(void *, int, int, int, int);
     67  1.2.4.2  bouyer static void add_model_specifics(prop_dictionary_t);
     68  1.2.4.2  bouyer static void copyprops(int, prop_dictionary_t);
     69  1.2.4.2  bouyer static void canonicalize_bootpath(void);
     70  1.2.4.2  bouyer 
     71  1.2.4.2  bouyer /*
     72  1.2.4.2  bouyer  * Determine device configuration for a machine.
     73  1.2.4.2  bouyer  */
     74  1.2.4.2  bouyer void
     75  1.2.4.2  bouyer cpu_configure(void)
     76  1.2.4.2  bouyer {
     77  1.2.4.2  bouyer 	init_interrupt();
     78  1.2.4.2  bouyer 	canonicalize_bootpath();
     79  1.2.4.2  bouyer 
     80  1.2.4.2  bouyer 	if (config_rootfound("mainbus", NULL) == NULL)
     81  1.2.4.2  bouyer 		panic("configure: mainbus not configured");
     82  1.2.4.2  bouyer 
     83  1.2.4.2  bouyer 	genppc_cpu_configure();
     84  1.2.4.2  bouyer }
     85  1.2.4.2  bouyer 
     86  1.2.4.2  bouyer static void
     87  1.2.4.2  bouyer canonicalize_bootpath(void)
     88  1.2.4.2  bouyer {
     89  1.2.4.2  bouyer 	int node;
     90  1.2.4.2  bouyer 	char *p, *lastp;
     91  1.2.4.2  bouyer 	char last[32];
     92  1.2.4.2  bouyer 
     93  1.2.4.2  bouyer 	/*
     94  1.2.4.2  bouyer 	 * If the bootpath doesn't start with a / then it isn't
     95  1.2.4.2  bouyer 	 * an OFW path and probably is an alias, so look up the alias
     96  1.2.4.2  bouyer 	 * and regenerate the full bootpath so device_register will work.
     97  1.2.4.2  bouyer 	 */
     98  1.2.4.2  bouyer 	if (bootpath[0] != '/' && bootpath[0] != '\0') {
     99  1.2.4.2  bouyer 		int aliases = OF_finddevice("/aliases");
    100  1.2.4.2  bouyer 		char tmpbuf[100];
    101  1.2.4.2  bouyer 		char aliasbuf[256];
    102  1.2.4.2  bouyer 		if (aliases != 0) {
    103  1.2.4.2  bouyer 			char *cp1, *cp2, *cp;
    104  1.2.4.2  bouyer 			char saved_ch = '\0';
    105  1.2.4.2  bouyer 			int len;
    106  1.2.4.2  bouyer 			cp1 = strchr(bootpath, ':');
    107  1.2.4.2  bouyer 			cp2 = strchr(bootpath, ',');
    108  1.2.4.2  bouyer 			cp = cp1;
    109  1.2.4.2  bouyer 			if (cp1 == NULL || (cp2 != NULL && cp2 < cp1))
    110  1.2.4.2  bouyer 				cp = cp2;
    111  1.2.4.2  bouyer 			tmpbuf[0] = '\0';
    112  1.2.4.2  bouyer 			if (cp != NULL) {
    113  1.2.4.2  bouyer 				strcpy(tmpbuf, cp);
    114  1.2.4.2  bouyer 				saved_ch = *cp;
    115  1.2.4.2  bouyer 				*cp = '\0';
    116  1.2.4.2  bouyer 			}
    117  1.2.4.2  bouyer 			len = OF_getprop(aliases, bootpath, aliasbuf,
    118  1.2.4.2  bouyer 			    sizeof(aliasbuf));
    119  1.2.4.2  bouyer 			if (len > 0) {
    120  1.2.4.2  bouyer 				if (aliasbuf[len-1] == '\0')
    121  1.2.4.2  bouyer 					len--;
    122  1.2.4.2  bouyer 				memcpy(bootpath, aliasbuf, len);
    123  1.2.4.2  bouyer 				strcpy(&bootpath[len], tmpbuf);
    124  1.2.4.2  bouyer 			} else {
    125  1.2.4.2  bouyer 				*cp = saved_ch;
    126  1.2.4.2  bouyer 			}
    127  1.2.4.2  bouyer 		}
    128  1.2.4.2  bouyer 	}
    129  1.2.4.2  bouyer 
    130  1.2.4.2  bouyer 	/*
    131  1.2.4.2  bouyer 	 * Strip kernel name.  bootpath contains "OF-path"/"kernel".
    132  1.2.4.2  bouyer 	 *
    133  1.2.4.2  bouyer 	 * for example:
    134  1.2.4.2  bouyer 	 *   /bandit@F2000000/gc@10/53c94@10000/sd@0,0/netbsd	(OF-1.x)
    135  1.2.4.2  bouyer 	 *   /pci/mac-io/ata-3@2000/disk@0:0/netbsd.new		(OF-3.x)
    136  1.2.4.2  bouyer 	 */
    137  1.2.4.2  bouyer 	strcpy(cbootpath, bootpath);
    138  1.2.4.2  bouyer 	while ((node = OF_finddevice(cbootpath)) == -1) {
    139  1.2.4.2  bouyer 		if ((p = strrchr(cbootpath, '/')) == NULL)
    140  1.2.4.2  bouyer 			break;
    141  1.2.4.2  bouyer 		*p = '\0';
    142  1.2.4.2  bouyer 	}
    143  1.2.4.2  bouyer 
    144  1.2.4.2  bouyer 	if (node == -1) {
    145  1.2.4.2  bouyer 		/* Cannot canonicalize... use bootpath anyway. */
    146  1.2.4.2  bouyer 		strcpy(cbootpath, bootpath);
    147  1.2.4.2  bouyer 
    148  1.2.4.2  bouyer 		return;
    149  1.2.4.2  bouyer 	}
    150  1.2.4.2  bouyer 
    151  1.2.4.2  bouyer 	/*
    152  1.2.4.2  bouyer 	 * cbootpath is a valid OF path.  Use package-to-path to
    153  1.2.4.2  bouyer 	 * canonicalize pathname.
    154  1.2.4.2  bouyer 	 */
    155  1.2.4.2  bouyer 
    156  1.2.4.2  bouyer 	/* Back up the last component for later use. */
    157  1.2.4.2  bouyer 	if ((p = strrchr(cbootpath, '/')) != NULL)
    158  1.2.4.2  bouyer 		strcpy(last, p + 1);
    159  1.2.4.2  bouyer 	else
    160  1.2.4.2  bouyer 		last[0] = '\0';
    161  1.2.4.2  bouyer 
    162  1.2.4.2  bouyer 	memset(cbootpath, 0, sizeof(cbootpath));
    163  1.2.4.2  bouyer 	OF_package_to_path(node, cbootpath, sizeof(cbootpath) - 1);
    164  1.2.4.2  bouyer 
    165  1.2.4.2  bouyer 	/*
    166  1.2.4.2  bouyer 	 * OF_1.x (at least) always returns addr == 0 for
    167  1.2.4.2  bouyer 	 * SCSI disks (i.e. "/bandit (at) .../.../sd@0,0").
    168  1.2.4.2  bouyer 	 */
    169  1.2.4.2  bouyer 	lastp = strrchr(cbootpath, '/');
    170  1.2.4.2  bouyer 	if (lastp != NULL) {
    171  1.2.4.2  bouyer 		lastp++;
    172  1.2.4.2  bouyer 		if (strncmp(lastp, "sd@", 3) == 0
    173  1.2.4.2  bouyer 		    && strncmp(last, "sd@", 3) == 0)
    174  1.2.4.2  bouyer 			strcpy(lastp, last);
    175  1.2.4.2  bouyer 	} else {
    176  1.2.4.2  bouyer 		lastp = cbootpath;
    177  1.2.4.2  bouyer 	}
    178  1.2.4.2  bouyer 
    179  1.2.4.2  bouyer 	/*
    180  1.2.4.2  bouyer 	 * At this point, cbootpath contains like:
    181  1.2.4.2  bouyer 	 * "/pci@80000000/mac-io@10/ata-3@20000/disk"
    182  1.2.4.2  bouyer 	 *
    183  1.2.4.2  bouyer 	 * The last component may have no address... so append it.
    184  1.2.4.2  bouyer 	 */
    185  1.2.4.2  bouyer 	if (strchr(lastp, '@') == NULL) {
    186  1.2.4.2  bouyer 		/* Append it. */
    187  1.2.4.2  bouyer 		if ((p = strrchr(last, '@')) != NULL)
    188  1.2.4.2  bouyer 			strcat(cbootpath, p);
    189  1.2.4.2  bouyer 	}
    190  1.2.4.2  bouyer 
    191  1.2.4.2  bouyer 	if ((p = strrchr(lastp, ':')) != NULL) {
    192  1.2.4.2  bouyer 		*p++ = '\0';
    193  1.2.4.2  bouyer 		/* booted_partition = *p - '0';		XXX correct? */
    194  1.2.4.2  bouyer 	}
    195  1.2.4.2  bouyer 
    196  1.2.4.2  bouyer 	/* XXX Does this belong here, or device_register()? */
    197  1.2.4.2  bouyer 	if ((p = strrchr(lastp, ',')) != NULL)
    198  1.2.4.2  bouyer 		*p = '\0';
    199  1.2.4.2  bouyer }
    200  1.2.4.2  bouyer 
    201  1.2.4.2  bouyer /*
    202  1.2.4.2  bouyer  * device_register is called from config_attach as each device is
    203  1.2.4.2  bouyer  * attached. We use it to find the NetBSD device corresponding to the
    204  1.2.4.2  bouyer  * known OF boot device.
    205  1.2.4.2  bouyer  */
    206  1.2.4.2  bouyer void
    207  1.2.4.2  bouyer device_register(dev, aux)
    208  1.2.4.2  bouyer 	struct device *dev;
    209  1.2.4.2  bouyer 	void *aux;
    210  1.2.4.2  bouyer {
    211  1.2.4.2  bouyer 	static struct device *parent;
    212  1.2.4.2  bouyer 	static char *bp = bootpath + 1, *cp = cbootpath;
    213  1.2.4.2  bouyer 	unsigned long addr;
    214  1.2.4.2  bouyer 	char *p;
    215  1.2.4.2  bouyer 
    216  1.2.4.2  bouyer 	if (booted_device)
    217  1.2.4.2  bouyer 		return;
    218  1.2.4.2  bouyer 
    219  1.2.4.2  bouyer 	/* Skip over devices not represented in the OF tree. */
    220  1.2.4.2  bouyer 	if (device_is_a(dev, "mainbus")) {
    221  1.2.4.2  bouyer 		parent = dev;
    222  1.2.4.2  bouyer 		return;
    223  1.2.4.2  bouyer 	}
    224  1.2.4.2  bouyer 	if (device_is_a(dev, "atapibus") || device_is_a(dev, "pci") ||
    225  1.2.4.2  bouyer 	    device_is_a(dev, "scsibus") || device_is_a(dev, "atabus"))
    226  1.2.4.2  bouyer 		return;
    227  1.2.4.2  bouyer 
    228  1.2.4.2  bouyer 	if (device_is_a(device_parent(dev), "pci")) {
    229  1.2.4.2  bouyer 		/* see if this is going to be console */
    230  1.2.4.2  bouyer 		struct pci_attach_args *pa = aux;
    231  1.2.4.2  bouyer 		prop_dictionary_t dict;
    232  1.2.4.2  bouyer 		int node, sub;
    233  1.2.4.2  bouyer 		int console = 0;
    234  1.2.4.2  bouyer 
    235  1.2.4.2  bouyer 		dict = device_properties(dev);
    236  1.2.4.2  bouyer 		node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
    237  1.2.4.2  bouyer 		prop_dictionary_set_uint32(dict, "device_node", node);
    238  1.2.4.2  bouyer 
    239  1.2.4.2  bouyer 		console = (node == console_node);
    240  1.2.4.2  bouyer 
    241  1.2.4.2  bouyer 		if (!console) {
    242  1.2.4.2  bouyer 			/*
    243  1.2.4.2  bouyer 			 * see if any child matches since OF attaches nodes for
    244  1.2.4.2  bouyer 			 * each head and /chosen/stdout points to the head
    245  1.2.4.2  bouyer 			 * rather than the device itself in this case
    246  1.2.4.2  bouyer 			 */
    247  1.2.4.2  bouyer 			sub = OF_child(node);
    248  1.2.4.2  bouyer 			while ((sub != 0) && (sub != console_node)) {
    249  1.2.4.2  bouyer 				sub = OF_peer(sub);
    250  1.2.4.2  bouyer 			}
    251  1.2.4.2  bouyer 			if (sub == console_node) {
    252  1.2.4.2  bouyer 				console = true;
    253  1.2.4.2  bouyer 			}
    254  1.2.4.2  bouyer 		}
    255  1.2.4.2  bouyer 
    256  1.2.4.2  bouyer 		if (console) {
    257  1.2.4.2  bouyer 			uint64_t cmap_cb;
    258  1.2.4.2  bouyer 
    259  1.2.4.2  bouyer 			prop_dictionary_set_uint32(dict, "instance_handle",
    260  1.2.4.2  bouyer 			    console_instance);
    261  1.2.4.2  bouyer 			copyprops(console_node, dict);
    262  1.2.4.2  bouyer 
    263  1.2.4.2  bouyer 			gfb_cb.gcc_cookie = (void *)console_instance;
    264  1.2.4.2  bouyer 			gfb_cb.gcc_set_mapreg = of_set_palette;
    265  1.2.4.2  bouyer 			cmap_cb = (uint64_t)&gfb_cb;
    266  1.2.4.2  bouyer 			prop_dictionary_set_uint64(dict, "cmap_callback",
    267  1.2.4.2  bouyer 			    cmap_cb);
    268  1.2.4.2  bouyer 		}
    269  1.2.4.2  bouyer 	}
    270  1.2.4.2  bouyer 
    271  1.2.4.2  bouyer 	if (device_is_a(device_parent(dev), "atapibus") ||
    272  1.2.4.2  bouyer 	    device_is_a(device_parent(dev), "atabus") ||
    273  1.2.4.2  bouyer 	    device_is_a(device_parent(dev), "pci") ||
    274  1.2.4.2  bouyer 	    device_is_a(device_parent(dev), "scsibus")) {
    275  1.2.4.2  bouyer 		if (device_parent(device_parent(dev)) != parent)
    276  1.2.4.2  bouyer 			return;
    277  1.2.4.2  bouyer 	} else {
    278  1.2.4.2  bouyer 		if (device_parent(dev) != parent)
    279  1.2.4.2  bouyer 			return;
    280  1.2.4.2  bouyer 	}
    281  1.2.4.2  bouyer 
    282  1.2.4.2  bouyer 	/* Get the address part of the current path component. The
    283  1.2.4.2  bouyer 	 * last component of the canonical bootpath may have no
    284  1.2.4.2  bouyer 	 * address (eg, "disk"), in which case we need to get the
    285  1.2.4.2  bouyer 	 * address from the original bootpath instead.
    286  1.2.4.2  bouyer 	 */
    287  1.2.4.2  bouyer 	p = strchr(cp, '@');
    288  1.2.4.2  bouyer 	if (!p) {
    289  1.2.4.2  bouyer 		if (bp)
    290  1.2.4.2  bouyer 			p = strchr(bp, '@');
    291  1.2.4.2  bouyer 		if (!p)
    292  1.2.4.2  bouyer 			addr = 0;
    293  1.2.4.2  bouyer 		else {
    294  1.2.4.2  bouyer 			addr = strtoul(p + 1, NULL, 16);
    295  1.2.4.2  bouyer 			p = NULL;
    296  1.2.4.2  bouyer 		}
    297  1.2.4.2  bouyer 	} else
    298  1.2.4.2  bouyer 		addr = strtoul(p + 1, &p, 16);
    299  1.2.4.2  bouyer 
    300  1.2.4.2  bouyer 	if (device_is_a(device_parent(dev), "mainbus")) {
    301  1.2.4.2  bouyer 		struct confargs *ca = aux;
    302  1.2.4.2  bouyer 
    303  1.2.4.2  bouyer 		if (strcmp(ca->ca_name, "ofw") == 0)		/* XXX */
    304  1.2.4.2  bouyer 			return;
    305  1.2.4.2  bouyer 		if (addr != ca->ca_reg[0])
    306  1.2.4.2  bouyer 			return;
    307  1.2.4.2  bouyer 	} else if (device_is_a(device_parent(dev), "pci")) {
    308  1.2.4.2  bouyer 		struct pci_attach_args *pa = aux;
    309  1.2.4.2  bouyer 
    310  1.2.4.2  bouyer 		if (addr != pa->pa_device)
    311  1.2.4.2  bouyer 			return;
    312  1.2.4.2  bouyer 	} else if (device_is_a(device_parent(dev), "obio")) {
    313  1.2.4.2  bouyer 		struct confargs *ca = aux;
    314  1.2.4.2  bouyer 
    315  1.2.4.2  bouyer 		if (addr != ca->ca_reg[0])
    316  1.2.4.2  bouyer 			return;
    317  1.2.4.2  bouyer 	} else if (device_is_a(device_parent(dev), "scsibus") ||
    318  1.2.4.2  bouyer 		   device_is_a(device_parent(dev), "atapibus")) {
    319  1.2.4.2  bouyer 		struct scsipibus_attach_args *sa = aux;
    320  1.2.4.2  bouyer 
    321  1.2.4.2  bouyer 		/* periph_target is target for scsi, drive # for atapi */
    322  1.2.4.2  bouyer 		if (addr != sa->sa_periph->periph_target)
    323  1.2.4.2  bouyer 			return;
    324  1.2.4.2  bouyer 	} else if (device_is_a(device_parent(device_parent(dev)), "pciide")) {
    325  1.2.4.2  bouyer 		struct ata_device *adev = aux;
    326  1.2.4.2  bouyer 
    327  1.2.4.2  bouyer 		if (addr != adev->adev_drv_data->drive)
    328  1.2.4.2  bouyer 			return;
    329  1.2.4.2  bouyer 
    330  1.2.4.2  bouyer 		/*
    331  1.2.4.2  bouyer 		 * OF splits channel and drive into separate path
    332  1.2.4.2  bouyer 		 * components, so check the addr part of the next
    333  1.2.4.2  bouyer 		 * component. (Ignore bp, because the canonical path
    334  1.2.4.2  bouyer 		 * will be complete in the pciide case.)
    335  1.2.4.2  bouyer 		 */
    336  1.2.4.2  bouyer 		p = strchr(p, '@');
    337  1.2.4.2  bouyer 		if (!p++)
    338  1.2.4.2  bouyer 			return;
    339  1.2.4.2  bouyer 		if (strtoul(p, &p, 16) != adev->adev_drv_data->drive)
    340  1.2.4.2  bouyer 			return;
    341  1.2.4.2  bouyer 	} else if (device_is_a(device_parent(device_parent(dev)), "wdc")) {
    342  1.2.4.2  bouyer 		struct ata_device *adev = aux;
    343  1.2.4.2  bouyer 
    344  1.2.4.2  bouyer 		if (addr != adev->adev_drv_data->drive)
    345  1.2.4.2  bouyer 			return;
    346  1.2.4.2  bouyer 	} else
    347  1.2.4.2  bouyer 		return;
    348  1.2.4.2  bouyer 
    349  1.2.4.2  bouyer 	/* If we reach this point, then dev is a match for the current
    350  1.2.4.2  bouyer 	 * path component.
    351  1.2.4.2  bouyer 	 */
    352  1.2.4.2  bouyer 
    353  1.2.4.2  bouyer 	if (p && *p) {
    354  1.2.4.2  bouyer 		parent = dev;
    355  1.2.4.2  bouyer 		cp = p;
    356  1.2.4.2  bouyer 		bp = strchr(bp, '/');
    357  1.2.4.2  bouyer 		if (bp)
    358  1.2.4.2  bouyer 			bp++;
    359  1.2.4.2  bouyer 		return;
    360  1.2.4.2  bouyer 	} else {
    361  1.2.4.2  bouyer 		booted_device = dev;
    362  1.2.4.2  bouyer 		booted_partition = 0; /* XXX -- should be extracted from bootpath */
    363  1.2.4.2  bouyer 		return;
    364  1.2.4.2  bouyer 	}
    365  1.2.4.2  bouyer }
    366  1.2.4.2  bouyer 
    367  1.2.4.2  bouyer /*
    368  1.2.4.2  bouyer  * Setup root device.
    369  1.2.4.2  bouyer  * Configure swap area.
    370  1.2.4.2  bouyer  */
    371  1.2.4.2  bouyer void
    372  1.2.4.2  bouyer cpu_rootconf()
    373  1.2.4.2  bouyer {
    374  1.2.4.2  bouyer 	printf("boot device: %s\n",
    375  1.2.4.2  bouyer 	    booted_device ? booted_device->dv_xname : "<unknown>");
    376  1.2.4.2  bouyer 
    377  1.2.4.2  bouyer 	setroot(booted_device, booted_partition);
    378  1.2.4.2  bouyer }
    379  1.2.4.2  bouyer 
    380  1.2.4.2  bouyer /*
    381  1.2.4.2  bouyer  * Find OF-device corresponding to the PCI device.
    382  1.2.4.2  bouyer  */
    383  1.2.4.2  bouyer int
    384  1.2.4.2  bouyer pcidev_to_ofdev(pci_chipset_tag_t pc, pcitag_t tag)
    385  1.2.4.2  bouyer {
    386  1.2.4.2  bouyer 	int bus, dev, func;
    387  1.2.4.2  bouyer 	u_int reg[5];
    388  1.2.4.2  bouyer 	int p, q;
    389  1.2.4.2  bouyer 	int l, b, d, f;
    390  1.2.4.2  bouyer 
    391  1.2.4.2  bouyer 	pci_decompose_tag(pc, tag, &bus, &dev, &func);
    392  1.2.4.2  bouyer 
    393  1.2.4.2  bouyer 	for (q = OF_peer(0); q; q = p) {
    394  1.2.4.2  bouyer 		l = OF_getprop(q, "assigned-addresses", reg, sizeof(reg));
    395  1.2.4.2  bouyer 		if (l > 4) {
    396  1.2.4.2  bouyer 			b = (reg[0] >> 16) & 0xff;
    397  1.2.4.2  bouyer 			d = (reg[0] >> 11) & 0x1f;
    398  1.2.4.2  bouyer 			f = (reg[0] >> 8) & 0x07;
    399  1.2.4.2  bouyer 
    400  1.2.4.2  bouyer 			if (b == bus && d == dev && f == func)
    401  1.2.4.2  bouyer 				return q;
    402  1.2.4.2  bouyer 		}
    403  1.2.4.2  bouyer 		if ((p = OF_child(q)))
    404  1.2.4.2  bouyer 			continue;
    405  1.2.4.2  bouyer 		while (q) {
    406  1.2.4.2  bouyer 			if ((p = OF_peer(q)))
    407  1.2.4.2  bouyer 				break;
    408  1.2.4.2  bouyer 			q = OF_parent(q);
    409  1.2.4.2  bouyer 		}
    410  1.2.4.2  bouyer 	}
    411  1.2.4.2  bouyer 	return 0;
    412  1.2.4.2  bouyer }
    413  1.2.4.2  bouyer 
    414  1.2.4.2  bouyer static void
    415  1.2.4.2  bouyer add_model_specifics(prop_dictionary_t dict)
    416  1.2.4.2  bouyer {
    417  1.2.4.2  bouyer 	const char *bl_rev_models[] = {
    418  1.2.4.2  bouyer 		"PowerBook4,3", "PowerBook6,3", "PowerBook6,5", NULL};
    419  1.2.4.2  bouyer 	int node;
    420  1.2.4.2  bouyer 
    421  1.2.4.2  bouyer 	node = OF_finddevice("/");
    422  1.2.4.2  bouyer 
    423  1.2.4.2  bouyer 	if (of_compatible(node, bl_rev_models) != -1) {
    424  1.2.4.2  bouyer 		prop_dictionary_set_bool(dict, "backlight_level_reverted", 1);
    425  1.2.4.2  bouyer 	}
    426  1.2.4.2  bouyer }
    427  1.2.4.2  bouyer 
    428  1.2.4.2  bouyer static void
    429  1.2.4.2  bouyer copyprops(int node, prop_dictionary_t dict)
    430  1.2.4.2  bouyer {
    431  1.2.4.2  bouyer 	uint32_t temp;
    432  1.2.4.2  bouyer 
    433  1.2.4.2  bouyer 	prop_dictionary_set_bool(dict, "is_console", 1);
    434  1.2.4.2  bouyer 	if (!of_to_uint32_prop(dict, node, "width", "width")) {
    435  1.2.4.2  bouyer 
    436  1.2.4.2  bouyer 		OF_interpret("screen-width", 0, 1, &temp);
    437  1.2.4.2  bouyer 		prop_dictionary_set_uint32(dict, "width", temp);
    438  1.2.4.2  bouyer 	}
    439  1.2.4.2  bouyer 	if (!of_to_uint32_prop(dict, console_node, "height", "height")) {
    440  1.2.4.2  bouyer 
    441  1.2.4.2  bouyer 		OF_interpret("screen-height", 0, 1, &temp);
    442  1.2.4.2  bouyer 		prop_dictionary_set_uint32(dict, "height", temp);
    443  1.2.4.2  bouyer 	}
    444  1.2.4.2  bouyer 	of_to_uint32_prop(dict, console_node, "linebytes", "linebytes");
    445  1.2.4.2  bouyer 	if (!of_to_uint32_prop(dict, console_node, "depth", "depth")) {
    446  1.2.4.2  bouyer 		/*
    447  1.2.4.2  bouyer 		 * XXX we should check linebytes vs. width but those
    448  1.2.4.2  bouyer 		 * FBs that don't have a depth property ( /chaos/control... )
    449  1.2.4.2  bouyer 		 * won't have linebytes either
    450  1.2.4.2  bouyer 		 */
    451  1.2.4.2  bouyer 		prop_dictionary_set_uint32(dict, "depth", 8);
    452  1.2.4.2  bouyer 	}
    453  1.2.4.2  bouyer 	if (!of_to_uint32_prop(dict, console_node, "address", "address")) {
    454  1.2.4.2  bouyer 		uint32_t fbaddr = 0;
    455  1.2.4.2  bouyer 			OF_interpret("frame-buffer-adr", 0, 1, &fbaddr);
    456  1.2.4.2  bouyer 		if (fbaddr != 0)
    457  1.2.4.2  bouyer 			prop_dictionary_set_uint32(dict, "address", fbaddr);
    458  1.2.4.2  bouyer 	}
    459  1.2.4.2  bouyer 	of_to_dataprop(dict, console_node, "EDID", "EDID");
    460  1.2.4.2  bouyer 	add_model_specifics(dict);
    461  1.2.4.2  bouyer 
    462  1.2.4.2  bouyer 	temp = 0;
    463  1.2.4.2  bouyer 	if (OF_getprop(console_node, "ATY,RefCLK", &temp, sizeof(temp)) != 4) {
    464  1.2.4.2  bouyer 
    465  1.2.4.2  bouyer 		OF_getprop(OF_parent(console_node), "ATY,RefCLK", &temp,
    466  1.2.4.2  bouyer 		    sizeof(temp));
    467  1.2.4.2  bouyer 	}
    468  1.2.4.2  bouyer 	if (temp != 0)
    469  1.2.4.2  bouyer 		prop_dictionary_set_uint32(dict, "refclk", temp / 10);
    470  1.2.4.2  bouyer }
    471  1.2.4.2  bouyer 
    472  1.2.4.2  bouyer static void
    473  1.2.4.2  bouyer of_set_palette(void *cookie, int index, int r, int g, int b)
    474  1.2.4.2  bouyer {
    475  1.2.4.2  bouyer 	int ih = (int)cookie;
    476  1.2.4.2  bouyer 
    477  1.2.4.2  bouyer 	OF_call_method_1("color!", ih, 4, r, g, b, index);
    478  1.2.4.2  bouyer }
    479