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