Home | History | Annotate | Line # | Download | only in ofw
ofbus.c revision 1.6
      1 /*	$NetBSD: ofbus.c,v 1.6 1998/01/26 21:48:07 cgd Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5  * Copyright (C) 1995, 1996 TooLs GmbH.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by TooLs GmbH.
     19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/param.h>
     35 #include <sys/device.h>
     36 
     37 #include <dev/ofw/openfirm.h>
     38 
     39 int ofbprobe __P((struct device *, struct cfdata *, void *));
     40 void ofbattach __P((struct device *, struct device *, void *));
     41 static int ofbprint __P((void *, const char *));
     42 
     43 struct cfattach ofbus_ca = {
     44 	sizeof(struct device), ofbprobe, ofbattach
     45 };
     46 
     47 struct cfattach ofroot_ca = {
     48 	sizeof(struct device), ofbprobe, ofbattach
     49 };
     50 
     51 static int
     52 ofbprint(aux, name)
     53 	void *aux;
     54 	const char *name;
     55 {
     56 	struct ofprobe *ofp = aux;
     57 	char child[64];
     58 	int l;
     59 
     60 	if ((l = OF_getprop(ofp->phandle, "name", child, sizeof child - 1)) < 0)
     61 		panic("device without name?");
     62 	if (l >= sizeof child)
     63 		l = sizeof child - 1;
     64 	child[l] = 0;
     65 
     66 	if (name)
     67 		printf("%s at %s", child, name);
     68 	else
     69 		printf(" (%s)", child);
     70 	return UNCONF;
     71 }
     72 
     73 int
     74 ofbprobe(parent, cf, aux)
     75 	struct device *parent;
     76 	struct cfdata *cf;
     77 	void *aux;
     78 {
     79 	struct ofprobe *ofp = aux;
     80 
     81 	if (!OF_child(ofp->phandle))
     82 		return 0;
     83 	return 1;
     84 }
     85 
     86 void
     87 ofbattach(parent, dev, aux)
     88 	struct device *parent, *dev;
     89 	void *aux;
     90 {
     91 	int child;
     92 	char name[5];
     93 	struct ofprobe *ofp = aux;
     94 	struct ofprobe probe;
     95 	int units;
     96 
     97 	if (!parent)
     98 		ofbprint(aux, 0);
     99 
    100 	printf("\n");
    101 
    102 	/*
    103 	 * This is a hack to make the probe work on the scsi (and ide) bus.
    104 	 * YES, I THINK IT IS A BUG IN THE OPENFIRMWARE TO NOT PROBE ALL
    105 	 * DEVICES ON THESE BUSSES.
    106 	 */
    107 	units = 1;
    108 	if (OF_getprop(ofp->phandle, "name", name, sizeof name) > 0) {
    109 		if (!strcmp(name, "scsi"))
    110 			units = 7; /* What about wide or hostid != 7?	XXX */
    111 		else if (!strcmp(name, "ide"))
    112 			units = 2;
    113 	}
    114 
    115 	for (child = OF_child(ofp->phandle); child; child = OF_peer(child)) {
    116 		/*
    117 		 * This is a hack to skip all the entries in the tree
    118 		 * that aren't devices (packages, openfirmware etc.).
    119 		 */
    120 		if (OF_getprop(child, "device_type", name, sizeof name) < 0 &&
    121 		    OF_getprop(child, "compatible", name, sizeof name) < 0)
    122 			continue;
    123 		probe.phandle = child;
    124 		for (probe.unit = 0; probe.unit < units; probe.unit++)
    125 			config_found(dev, &probe, ofbprint);
    126 	}
    127 }
    128