Home | History | Annotate | Line # | Download | only in oea
ofw_autoconf.c revision 1.11.2.1
      1  1.11.2.1  uebayasi /* $NetBSD: ofw_autoconf.c,v 1.11.2.1 2010/08/17 06:45:03 uebayasi Exp $ */
      2       1.1   garbled /*
      3       1.1   garbled  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      4       1.1   garbled  * Copyright (C) 1995, 1996 TooLs GmbH.
      5       1.1   garbled  * All rights reserved.
      6       1.1   garbled  *
      7       1.1   garbled  * Redistribution and use in source and binary forms, with or without
      8       1.1   garbled  * modification, are permitted provided that the following conditions
      9       1.1   garbled  * are met:
     10       1.1   garbled  * 1. Redistributions of source code must retain the above copyright
     11       1.1   garbled  *    notice, this list of conditions and the following disclaimer.
     12       1.1   garbled  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1   garbled  *    notice, this list of conditions and the following disclaimer in the
     14       1.1   garbled  *    documentation and/or other materials provided with the distribution.
     15       1.1   garbled  * 3. All advertising materials mentioning features or use of this software
     16       1.1   garbled  *    must display the following acknowledgement:
     17       1.1   garbled  *      This product includes software developed by TooLs GmbH.
     18       1.1   garbled  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     19       1.1   garbled  *    derived from this software without specific prior written permission.
     20       1.1   garbled  *
     21       1.1   garbled  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     22       1.1   garbled  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23       1.1   garbled  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24       1.1   garbled  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     25       1.1   garbled  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26       1.1   garbled  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     27       1.1   garbled  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     28       1.1   garbled  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     29       1.1   garbled  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     30       1.1   garbled  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31       1.1   garbled  */
     32       1.1   garbled 
     33       1.1   garbled #include <sys/cdefs.h>
     34  1.11.2.1  uebayasi __KERNEL_RCSID(0, "$NetBSD: ofw_autoconf.c,v 1.11.2.1 2010/08/17 06:45:03 uebayasi Exp $");
     35  1.11.2.1  uebayasi 
     36  1.11.2.1  uebayasi #ifdef ofppc
     37  1.11.2.1  uebayasi #include "gtpci.h"
     38  1.11.2.1  uebayasi #endif
     39       1.1   garbled 
     40       1.1   garbled #include <sys/param.h>
     41       1.1   garbled #include <sys/conf.h>
     42       1.1   garbled #include <sys/device.h>
     43       1.1   garbled #include <sys/reboot.h>
     44       1.1   garbled #include <sys/systm.h>
     45       1.1   garbled 
     46       1.1   garbled #include <uvm/uvm_extern.h>
     47       1.1   garbled 
     48       1.1   garbled #include <machine/autoconf.h>
     49       1.1   garbled #include <machine/bus.h>
     50       1.1   garbled #include <machine/stdarg.h>
     51       1.1   garbled 
     52       1.1   garbled #include <dev/ofw/openfirm.h>
     53  1.11.2.1  uebayasi #include <dev/marvell/marvellvar.h>
     54       1.6   aymeric #include <dev/pci/pcireg.h>
     55       1.1   garbled #include <dev/pci/pcivar.h>
     56  1.11.2.1  uebayasi #if NGTPCI > 0
     57  1.11.2.1  uebayasi #include <dev/marvell/gtpcivar.h>
     58  1.11.2.1  uebayasi #endif
     59       1.1   garbled #include <dev/scsipi/scsi_all.h>
     60       1.1   garbled #include <dev/scsipi/scsipi_all.h>
     61       1.1   garbled #include <dev/scsipi/scsiconf.h>
     62       1.1   garbled #include <dev/ata/atavar.h>
     63       1.1   garbled #include <dev/ic/wdcvar.h>
     64       1.1   garbled 
     65  1.11.2.1  uebayasi #include <machine/pci_machdep.h>
     66  1.11.2.1  uebayasi 
     67  1.11.2.1  uebayasi #include <prop/proplib.h>
     68  1.11.2.1  uebayasi 
     69       1.1   garbled extern char bootpath[256];
     70       1.1   garbled char cbootpath[256];
     71       1.1   garbled int console_node = 0, console_instance = 0;
     72       1.1   garbled 
     73       1.1   garbled static void canonicalize_bootpath(void);
     74       1.1   garbled 
     75       1.1   garbled /*
     76       1.1   garbled  * Determine device configuration for a machine.
     77       1.1   garbled  */
     78       1.1   garbled void
     79       1.1   garbled cpu_configure(void)
     80       1.1   garbled {
     81       1.1   garbled 	init_interrupt();
     82       1.1   garbled 	canonicalize_bootpath();
     83       1.1   garbled 
     84       1.1   garbled 	if (config_rootfound("mainbus", NULL) == NULL)
     85       1.1   garbled 		panic("configure: mainbus not configured");
     86       1.1   garbled 
     87       1.1   garbled 	genppc_cpu_configure();
     88       1.1   garbled }
     89       1.1   garbled 
     90       1.1   garbled static void
     91       1.1   garbled canonicalize_bootpath(void)
     92       1.1   garbled {
     93       1.1   garbled 	int node;
     94       1.1   garbled 	char *p, *lastp;
     95       1.1   garbled 	char last[32];
     96       1.1   garbled 
     97       1.1   garbled 	/*
     98       1.1   garbled 	 * If the bootpath doesn't start with a / then it isn't
     99       1.1   garbled 	 * an OFW path and probably is an alias, so look up the alias
    100       1.1   garbled 	 * and regenerate the full bootpath so device_register will work.
    101       1.1   garbled 	 */
    102       1.1   garbled 	if (bootpath[0] != '/' && bootpath[0] != '\0') {
    103       1.1   garbled 		int aliases = OF_finddevice("/aliases");
    104       1.1   garbled 		char tmpbuf[100];
    105       1.1   garbled 		char aliasbuf[256];
    106       1.1   garbled 		if (aliases != 0) {
    107       1.1   garbled 			char *cp1, *cp2, *cp;
    108       1.1   garbled 			char saved_ch = '\0';
    109       1.1   garbled 			int len;
    110       1.1   garbled 			cp1 = strchr(bootpath, ':');
    111       1.1   garbled 			cp2 = strchr(bootpath, ',');
    112       1.1   garbled 			cp = cp1;
    113       1.1   garbled 			if (cp1 == NULL || (cp2 != NULL && cp2 < cp1))
    114       1.1   garbled 				cp = cp2;
    115       1.1   garbled 			tmpbuf[0] = '\0';
    116       1.1   garbled 			if (cp != NULL) {
    117       1.1   garbled 				strcpy(tmpbuf, cp);
    118       1.1   garbled 				saved_ch = *cp;
    119       1.1   garbled 				*cp = '\0';
    120       1.1   garbled 			}
    121       1.1   garbled 			len = OF_getprop(aliases, bootpath, aliasbuf,
    122       1.1   garbled 			    sizeof(aliasbuf));
    123       1.1   garbled 			if (len > 0) {
    124       1.1   garbled 				if (aliasbuf[len-1] == '\0')
    125       1.1   garbled 					len--;
    126       1.1   garbled 				memcpy(bootpath, aliasbuf, len);
    127       1.1   garbled 				strcpy(&bootpath[len], tmpbuf);
    128       1.1   garbled 			} else {
    129       1.1   garbled 				*cp = saved_ch;
    130       1.1   garbled 			}
    131       1.1   garbled 		}
    132       1.1   garbled 	}
    133       1.1   garbled 
    134       1.1   garbled 	/*
    135       1.1   garbled 	 * Strip kernel name.  bootpath contains "OF-path"/"kernel".
    136       1.1   garbled 	 *
    137       1.1   garbled 	 * for example:
    138       1.1   garbled 	 *   /bandit@F2000000/gc@10/53c94@10000/sd@0,0/netbsd	(OF-1.x)
    139       1.1   garbled 	 *   /pci/mac-io/ata-3@2000/disk@0:0/netbsd.new		(OF-3.x)
    140       1.1   garbled 	 */
    141       1.1   garbled 	strcpy(cbootpath, bootpath);
    142       1.1   garbled 	while ((node = OF_finddevice(cbootpath)) == -1) {
    143       1.1   garbled 		if ((p = strrchr(cbootpath, '/')) == NULL)
    144       1.1   garbled 			break;
    145       1.1   garbled 		*p = '\0';
    146       1.1   garbled 	}
    147       1.1   garbled 
    148       1.7       mrg 	printf("bootpath: %s\n", bootpath);
    149       1.1   garbled 	if (node == -1) {
    150       1.1   garbled 		/* Cannot canonicalize... use bootpath anyway. */
    151       1.1   garbled 		strcpy(cbootpath, bootpath);
    152       1.1   garbled 
    153       1.1   garbled 		return;
    154       1.1   garbled 	}
    155       1.1   garbled 
    156       1.1   garbled 	/*
    157       1.1   garbled 	 * cbootpath is a valid OF path.  Use package-to-path to
    158       1.1   garbled 	 * canonicalize pathname.
    159       1.1   garbled 	 */
    160       1.1   garbled 
    161       1.1   garbled 	/* Back up the last component for later use. */
    162       1.1   garbled 	if ((p = strrchr(cbootpath, '/')) != NULL)
    163       1.1   garbled 		strcpy(last, p + 1);
    164       1.1   garbled 	else
    165       1.1   garbled 		last[0] = '\0';
    166       1.1   garbled 
    167       1.1   garbled 	memset(cbootpath, 0, sizeof(cbootpath));
    168       1.1   garbled 	OF_package_to_path(node, cbootpath, sizeof(cbootpath) - 1);
    169       1.1   garbled 
    170       1.1   garbled 	/*
    171       1.1   garbled 	 * OF_1.x (at least) always returns addr == 0 for
    172       1.1   garbled 	 * SCSI disks (i.e. "/bandit (at) .../.../sd@0,0").
    173       1.1   garbled 	 */
    174       1.1   garbled 	lastp = strrchr(cbootpath, '/');
    175       1.1   garbled 	if (lastp != NULL) {
    176       1.1   garbled 		lastp++;
    177       1.1   garbled 		if (strncmp(lastp, "sd@", 3) == 0
    178       1.1   garbled 		    && strncmp(last, "sd@", 3) == 0)
    179       1.1   garbled 			strcpy(lastp, last);
    180       1.1   garbled 	} else {
    181       1.1   garbled 		lastp = cbootpath;
    182       1.1   garbled 	}
    183       1.1   garbled 
    184       1.1   garbled 	/*
    185       1.1   garbled 	 * At this point, cbootpath contains like:
    186       1.1   garbled 	 * "/pci@80000000/mac-io@10/ata-3@20000/disk"
    187       1.1   garbled 	 *
    188       1.1   garbled 	 * The last component may have no address... so append it.
    189       1.1   garbled 	 */
    190       1.1   garbled 	if (strchr(lastp, '@') == NULL) {
    191       1.1   garbled 		/* Append it. */
    192       1.1   garbled 		if ((p = strrchr(last, '@')) != NULL)
    193       1.1   garbled 			strcat(cbootpath, p);
    194       1.1   garbled 	}
    195       1.1   garbled 
    196       1.1   garbled 	if ((p = strrchr(lastp, ':')) != NULL) {
    197       1.1   garbled 		*p++ = '\0';
    198       1.1   garbled 		/* booted_partition = *p - '0';		XXX correct? */
    199       1.1   garbled 	}
    200       1.1   garbled }
    201       1.1   garbled 
    202       1.1   garbled /*
    203       1.1   garbled  * device_register is called from config_attach as each device is
    204       1.1   garbled  * attached. We use it to find the NetBSD device corresponding to the
    205       1.1   garbled  * known OF boot device.
    206       1.1   garbled  */
    207       1.1   garbled void
    208       1.9       dsl device_register(struct device *dev, void *aux)
    209       1.1   garbled {
    210       1.1   garbled 	static struct device *parent;
    211       1.1   garbled 	static char *bp = bootpath + 1, *cp = cbootpath;
    212       1.7       mrg 	unsigned long addr, addr2;
    213       1.1   garbled 	char *p;
    214  1.11.2.1  uebayasi #if NGTPCI > 0
    215  1.11.2.1  uebayasi 	struct powerpc_bus_space *gtpci_mem_bs_tag = NULL;
    216  1.11.2.1  uebayasi #endif
    217       1.1   garbled 
    218       1.1   garbled 	/* Skip over devices not represented in the OF tree. */
    219       1.1   garbled 	if (device_is_a(dev, "mainbus")) {
    220       1.1   garbled 		parent = dev;
    221       1.1   garbled 		return;
    222       1.1   garbled 	}
    223  1.11.2.1  uebayasi #if NGTPCI > 0
    224  1.11.2.1  uebayasi 	if (device_is_a(dev, "gtpci")) {
    225  1.11.2.1  uebayasi 		extern struct gtpci_prot gtpci0_prot, gtpci1_prot;
    226  1.11.2.1  uebayasi 		extern struct powerpc_bus_space
    227  1.11.2.1  uebayasi 		    gtpci0_io_bs_tag, gtpci0_mem_bs_tag,
    228  1.11.2.1  uebayasi 		    gtpci1_io_bs_tag, gtpci1_mem_bs_tag;
    229  1.11.2.1  uebayasi 		extern struct genppc_pci_chipset
    230  1.11.2.1  uebayasi 		    genppc_gtpci0_chipset, genppc_gtpci1_chipset;
    231  1.11.2.1  uebayasi 
    232  1.11.2.1  uebayasi 		struct marvell_attach_args *mva = aux;
    233  1.11.2.1  uebayasi 		struct gtpci_prot *gtpci_prot;
    234  1.11.2.1  uebayasi 		struct powerpc_bus_space *gtpci_io_bs_tag;
    235  1.11.2.1  uebayasi 		struct genppc_pci_chipset *genppc_gtpci_chipset;
    236  1.11.2.1  uebayasi 		prop_dictionary_t dict = device_properties(dev);
    237  1.11.2.1  uebayasi 		prop_data_t prot, io_bs_tag, mem_bs_tag, pc;
    238  1.11.2.1  uebayasi 		int iostart, ioend;
    239  1.11.2.1  uebayasi 
    240  1.11.2.1  uebayasi 		if (mva->mva_unit == 0) {
    241  1.11.2.1  uebayasi 			gtpci_prot = &gtpci0_prot;
    242  1.11.2.1  uebayasi 			gtpci_io_bs_tag = &gtpci0_io_bs_tag;
    243  1.11.2.1  uebayasi 			gtpci_mem_bs_tag = &gtpci0_mem_bs_tag;
    244  1.11.2.1  uebayasi 			genppc_gtpci_chipset = &genppc_gtpci0_chipset;
    245  1.11.2.1  uebayasi 			iostart = 0;
    246  1.11.2.1  uebayasi 			ioend = 0;
    247  1.11.2.1  uebayasi 		} else {
    248  1.11.2.1  uebayasi 			gtpci_prot = &gtpci1_prot;
    249  1.11.2.1  uebayasi 			gtpci_io_bs_tag = &gtpci1_io_bs_tag;
    250  1.11.2.1  uebayasi 			gtpci_mem_bs_tag = &gtpci1_mem_bs_tag;
    251  1.11.2.1  uebayasi 			genppc_gtpci_chipset = &genppc_gtpci1_chipset;
    252  1.11.2.1  uebayasi 			iostart = 0x1400;
    253  1.11.2.1  uebayasi 			ioend = 0xffff;
    254  1.11.2.1  uebayasi 		}
    255  1.11.2.1  uebayasi 
    256  1.11.2.1  uebayasi 		prot = prop_data_create_data_nocopy(
    257  1.11.2.1  uebayasi 		    gtpci_prot, sizeof(struct gtpci_prot));
    258  1.11.2.1  uebayasi 		KASSERT(prot != NULL);
    259  1.11.2.1  uebayasi 		prop_dictionary_set(dict, "prot", prot);
    260  1.11.2.1  uebayasi 		prop_object_release(prot);
    261  1.11.2.1  uebayasi 
    262  1.11.2.1  uebayasi 		io_bs_tag = prop_data_create_data_nocopy(
    263  1.11.2.1  uebayasi 		    gtpci_io_bs_tag, sizeof(struct powerpc_bus_space));
    264  1.11.2.1  uebayasi 		KASSERT(io_bs_tag != NULL);
    265  1.11.2.1  uebayasi 		prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
    266  1.11.2.1  uebayasi 		prop_object_release(io_bs_tag);
    267  1.11.2.1  uebayasi 		mem_bs_tag = prop_data_create_data_nocopy(
    268  1.11.2.1  uebayasi 		    gtpci_mem_bs_tag, sizeof(struct powerpc_bus_space));
    269  1.11.2.1  uebayasi 		KASSERT(mem_bs_tag != NULL);
    270  1.11.2.1  uebayasi 		prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
    271  1.11.2.1  uebayasi 		prop_object_release(mem_bs_tag);
    272  1.11.2.1  uebayasi 
    273  1.11.2.1  uebayasi 		genppc_gtpci_chipset->pc_conf_v = device_private(dev);
    274  1.11.2.1  uebayasi 		pc = prop_data_create_data_nocopy(genppc_gtpci_chipset,
    275  1.11.2.1  uebayasi 		    sizeof(struct genppc_pci_chipset));
    276  1.11.2.1  uebayasi 		KASSERT(pc != NULL);
    277  1.11.2.1  uebayasi 		prop_dictionary_set(dict, "pci-chipset", pc);
    278  1.11.2.1  uebayasi 		prop_object_release(pc);
    279  1.11.2.1  uebayasi 
    280  1.11.2.1  uebayasi 		prop_dictionary_set_uint64(dict, "iostart", iostart);
    281  1.11.2.1  uebayasi 		prop_dictionary_set_uint64(dict, "ioend", ioend);
    282  1.11.2.1  uebayasi 		prop_dictionary_set_uint64(dict, "memstart",
    283  1.11.2.1  uebayasi 		    gtpci_mem_bs_tag->pbs_base);
    284  1.11.2.1  uebayasi 		prop_dictionary_set_uint64(dict, "memend",
    285  1.11.2.1  uebayasi 		    gtpci_mem_bs_tag->pbs_limit - 1);
    286  1.11.2.1  uebayasi 		prop_dictionary_set_uint32(dict, "cache-line-size",
    287  1.11.2.1  uebayasi 		    CACHELINESIZE);
    288  1.11.2.1  uebayasi 	}
    289  1.11.2.1  uebayasi #endif
    290       1.1   garbled 	if (device_is_a(dev, "atapibus") || device_is_a(dev, "pci") ||
    291       1.1   garbled 	    device_is_a(dev, "scsibus") || device_is_a(dev, "atabus"))
    292       1.1   garbled 		return;
    293       1.1   garbled 
    294       1.1   garbled 	if (device_is_a(device_parent(dev), "pci")) {
    295       1.1   garbled 		struct pci_attach_args *pa = aux;
    296       1.1   garbled 		prop_dictionary_t dict;
    297       1.5       phx 		prop_bool_t b;
    298       1.3   garbled 		int node;
    299       1.3   garbled 		char name[32];
    300       1.1   garbled 
    301       1.1   garbled 		dict = device_properties(dev);
    302       1.1   garbled 		node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
    303       1.1   garbled 
    304       1.5       phx 		/* enable configuration of irq 14/15 for VIA native IDE */
    305       1.5       phx 		if (device_is_a(dev, "viaide") &&
    306       1.5       phx 		    strncmp(model_name, "Pegasos", 7) == 0) {
    307       1.5       phx 			b = prop_bool_create(true);
    308       1.5       phx 			KASSERT(b != NULL);
    309       1.5       phx 			(void)prop_dictionary_set(dict,
    310       1.5       phx 			    "use-compat-native-irq", b);
    311       1.5       phx 			prop_object_release(b);
    312       1.5       phx 		}
    313       1.5       phx 
    314       1.4  macallan 		if (node != 0) {
    315       1.6   aymeric 			int pci_class = 0;
    316       1.6   aymeric 
    317       1.3   garbled 			prop_dictionary_set_uint32(dict, "device_node", node);
    318       1.1   garbled 
    319       1.5       phx 			/* see if this is going to be console */
    320       1.3   garbled 			memset(name, 0, sizeof(name));
    321       1.3   garbled 			OF_getprop(node, "device_type", name, sizeof(name));
    322       1.6   aymeric 
    323       1.6   aymeric 			OF_getprop(node, "class-code", &pci_class,
    324       1.6   aymeric 				sizeof pci_class);
    325       1.6   aymeric 			pci_class = (pci_class >> 16) & 0xff;
    326       1.6   aymeric 
    327       1.6   aymeric 			if (strcmp(name, "display") == 0 ||
    328       1.8  macallan 			    strcmp(name, "ATY,DDParent") == 0 ||
    329       1.8  macallan 			    pci_class == PCI_CLASS_DISPLAY) {
    330       1.3   garbled 				/* setup display properties for fb driver */
    331       1.3   garbled 				prop_dictionary_set_bool(dict, "is_console", 0);
    332       1.3   garbled 				copy_disp_props(dev, node, dict);
    333       1.1   garbled 			}
    334      1.11  macallan 			if (pci_class == PCI_CLASS_NETWORK) {
    335      1.11  macallan 				of_to_dataprop(dict, node, "local-mac-address",
    336      1.11  macallan 				    "mac-address");
    337      1.11  macallan 				of_to_dataprop(dict, node, "shared-pins",
    338      1.11  macallan 				    "shared-pins");
    339      1.11  macallan 			}
    340       1.1   garbled 		}
    341       1.3   garbled 	}
    342       1.1   garbled 
    343       1.3   garbled 	if (booted_device)
    344       1.3   garbled 		return;
    345       1.1   garbled 
    346       1.7       mrg 	/*
    347       1.7       mrg 	 * Skip over devices that are really just layers of NetBSD
    348       1.7       mrg 	 * autoconf(9) we should just skip as they do not have any
    349       1.7       mrg 	 * OFW devices.
    350       1.7       mrg 	 */
    351       1.1   garbled 	if (device_is_a(device_parent(dev), "atapibus") ||
    352       1.1   garbled 	    device_is_a(device_parent(dev), "atabus") ||
    353       1.1   garbled 	    device_is_a(device_parent(dev), "pci") ||
    354       1.1   garbled 	    device_is_a(device_parent(dev), "scsibus")) {
    355       1.1   garbled 		if (device_parent(device_parent(dev)) != parent)
    356       1.1   garbled 			return;
    357       1.1   garbled 	} else {
    358       1.1   garbled 		if (device_parent(dev) != parent)
    359       1.1   garbled 			return;
    360       1.1   garbled 	}
    361       1.1   garbled 
    362       1.7       mrg 	/*
    363       1.7       mrg 	 * Get the address part of the current path component. The
    364       1.1   garbled 	 * last component of the canonical bootpath may have no
    365       1.1   garbled 	 * address (eg, "disk"), in which case we need to get the
    366       1.1   garbled 	 * address from the original bootpath instead.
    367       1.1   garbled 	 */
    368       1.1   garbled 	p = strchr(cp, '@');
    369       1.1   garbled 	if (!p) {
    370       1.1   garbled 		if (bp)
    371       1.1   garbled 			p = strchr(bp, '@');
    372       1.1   garbled 		if (!p)
    373       1.1   garbled 			addr = 0;
    374       1.7       mrg 		else
    375       1.7       mrg 			addr = strtoul(p + 1, &p, 16);
    376       1.1   garbled 	} else
    377       1.1   garbled 		addr = strtoul(p + 1, &p, 16);
    378       1.1   garbled 
    379       1.7       mrg 	/* if the current path has more address, grab that too */
    380       1.7       mrg 	if (p && *p == ',')
    381       1.7       mrg 		addr2 = strtoul(p + 1, &p, 16);
    382       1.7       mrg 	else
    383       1.7       mrg 		addr2 = 0;
    384       1.7       mrg 
    385       1.1   garbled 	if (device_is_a(device_parent(dev), "mainbus")) {
    386       1.1   garbled 		struct confargs *ca = aux;
    387       1.1   garbled 
    388       1.1   garbled 		if (strcmp(ca->ca_name, "ofw") == 0)		/* XXX */
    389       1.1   garbled 			return;
    390  1.11.2.1  uebayasi 		if (strcmp(ca->ca_name, "gt") == 0)
    391  1.11.2.1  uebayasi 			parent = dev;
    392       1.1   garbled 		if (addr != ca->ca_reg[0])
    393       1.1   garbled 			return;
    394  1.11.2.1  uebayasi 	} else if (device_is_a(device_parent(dev), "gt")) {
    395  1.11.2.1  uebayasi 		/*
    396  1.11.2.1  uebayasi 		 * Special handle for MV64361 on PegasosII(ofppc).
    397  1.11.2.1  uebayasi 		 */
    398  1.11.2.1  uebayasi 		if (device_is_a(dev, "mvgbec")) {
    399  1.11.2.1  uebayasi 			/*
    400  1.11.2.1  uebayasi 			 * Fix cp to /port@N from /ethernet/portN. (N is 0...2)
    401  1.11.2.1  uebayasi 			 */
    402  1.11.2.1  uebayasi 			static char fix_cp[8] = "/port@N";
    403  1.11.2.1  uebayasi 
    404  1.11.2.1  uebayasi 			if (strlen(cp) != 15 ||
    405  1.11.2.1  uebayasi 			    strncmp(cp, "/ethernet/port", 14) != 0)
    406  1.11.2.1  uebayasi 				return;
    407  1.11.2.1  uebayasi 			fix_cp[7] = *(cp + 15);
    408  1.11.2.1  uebayasi 			p = fix_cp;
    409  1.11.2.1  uebayasi #if NGTPCI > 0
    410  1.11.2.1  uebayasi 		} else if (device_is_a(dev, "gtpci")) {
    411  1.11.2.1  uebayasi 			if (gtpci_mem_bs_tag != NULL &&
    412  1.11.2.1  uebayasi 			    addr != gtpci_mem_bs_tag->pbs_base)
    413  1.11.2.1  uebayasi 				return;
    414  1.11.2.1  uebayasi #endif
    415  1.11.2.1  uebayasi 		} else
    416  1.11.2.1  uebayasi 			return;
    417       1.1   garbled 	} else if (device_is_a(device_parent(dev), "pci")) {
    418       1.1   garbled 		struct pci_attach_args *pa = aux;
    419       1.1   garbled 
    420       1.7       mrg 		if (addr != pa->pa_device ||
    421       1.7       mrg 		    addr2 != pa->pa_function)
    422       1.1   garbled 			return;
    423       1.1   garbled 	} else if (device_is_a(device_parent(dev), "obio")) {
    424       1.1   garbled 		struct confargs *ca = aux;
    425       1.1   garbled 
    426       1.1   garbled 		if (addr != ca->ca_reg[0])
    427       1.1   garbled 			return;
    428       1.1   garbled 	} else if (device_is_a(device_parent(dev), "scsibus") ||
    429       1.1   garbled 		   device_is_a(device_parent(dev), "atapibus")) {
    430       1.1   garbled 		struct scsipibus_attach_args *sa = aux;
    431       1.1   garbled 
    432       1.1   garbled 		/* periph_target is target for scsi, drive # for atapi */
    433       1.1   garbled 		if (addr != sa->sa_periph->periph_target)
    434       1.1   garbled 			return;
    435       1.7       mrg 	} else if (device_is_a(device_parent(device_parent(dev)), "pciide") ||
    436       1.7       mrg 		   device_is_a(device_parent(device_parent(dev)), "viaide") ||
    437       1.7       mrg 		   device_is_a(device_parent(device_parent(dev)), "slide")) {
    438       1.1   garbled 		struct ata_device *adev = aux;
    439       1.1   garbled 
    440       1.7       mrg 		if (addr != adev->adev_channel ||
    441       1.7       mrg 		    addr2 != adev->adev_drv_data->drive)
    442       1.1   garbled 			return;
    443       1.1   garbled 	} else if (device_is_a(device_parent(device_parent(dev)), "wdc")) {
    444       1.1   garbled 		struct ata_device *adev = aux;
    445       1.1   garbled 
    446       1.1   garbled 		if (addr != adev->adev_drv_data->drive)
    447       1.1   garbled 			return;
    448       1.1   garbled 	} else
    449       1.1   garbled 		return;
    450       1.1   garbled 
    451       1.1   garbled 	/* If we reach this point, then dev is a match for the current
    452       1.1   garbled 	 * path component.
    453       1.1   garbled 	 */
    454       1.1   garbled 
    455       1.1   garbled 	if (p && *p) {
    456       1.1   garbled 		parent = dev;
    457       1.1   garbled 		cp = p;
    458       1.1   garbled 		bp = strchr(bp, '/');
    459       1.1   garbled 		if (bp)
    460       1.1   garbled 			bp++;
    461       1.1   garbled 		return;
    462       1.1   garbled 	} else {
    463       1.1   garbled 		booted_device = dev;
    464       1.1   garbled 		booted_partition = 0; /* XXX -- should be extracted from bootpath */
    465       1.1   garbled 		return;
    466       1.1   garbled 	}
    467       1.1   garbled }
    468       1.1   garbled 
    469       1.1   garbled /*
    470       1.1   garbled  * Setup root device.
    471       1.1   garbled  * Configure swap area.
    472       1.1   garbled  */
    473       1.1   garbled void
    474      1.10    cegger cpu_rootconf(void)
    475       1.1   garbled {
    476       1.1   garbled 	printf("boot device: %s\n",
    477       1.1   garbled 	    booted_device ? booted_device->dv_xname : "<unknown>");
    478       1.1   garbled 
    479       1.1   garbled 	setroot(booted_device, booted_partition);
    480       1.1   garbled }
    481       1.1   garbled 
    482       1.1   garbled /*
    483       1.1   garbled  * Find OF-device corresponding to the PCI device.
    484       1.1   garbled  */
    485       1.1   garbled int
    486       1.1   garbled pcidev_to_ofdev(pci_chipset_tag_t pc, pcitag_t tag)
    487       1.1   garbled {
    488       1.1   garbled 	int bus, dev, func;
    489       1.1   garbled 	u_int reg[5];
    490       1.1   garbled 	int p, q;
    491       1.1   garbled 	int l, b, d, f;
    492       1.1   garbled 
    493       1.1   garbled 	pci_decompose_tag(pc, tag, &bus, &dev, &func);
    494       1.1   garbled 
    495       1.1   garbled 	for (q = OF_peer(0); q; q = p) {
    496       1.1   garbled 		l = OF_getprop(q, "assigned-addresses", reg, sizeof(reg));
    497       1.1   garbled 		if (l > 4) {
    498       1.1   garbled 			b = (reg[0] >> 16) & 0xff;
    499       1.1   garbled 			d = (reg[0] >> 11) & 0x1f;
    500       1.1   garbled 			f = (reg[0] >> 8) & 0x07;
    501       1.1   garbled 
    502       1.1   garbled 			if (b == bus && d == dev && f == func)
    503       1.1   garbled 				return q;
    504       1.1   garbled 		}
    505       1.1   garbled 		if ((p = OF_child(q)))
    506       1.1   garbled 			continue;
    507       1.1   garbled 		while (q) {
    508       1.1   garbled 			if ((p = OF_peer(q)))
    509       1.1   garbled 				break;
    510       1.1   garbled 			q = OF_parent(q);
    511       1.1   garbled 		}
    512       1.1   garbled 	}
    513       1.1   garbled 	return 0;
    514       1.1   garbled }
    515