Home | History | Annotate | Line # | Download | only in ofw
ofbus.c revision 1.11
      1  1.11   thorpej /*	$NetBSD: ofbus.c,v 1.11 2001/10/22 14:36:55 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.7       cgd #include <sys/systm.h>
     36   1.1        ws #include <sys/device.h>
     37   1.1        ws 
     38   1.1        ws #include <dev/ofw/openfirm.h>
     39   1.1        ws 
     40  1.10   mycroft int ofbus_match __P((struct device *, struct cfdata *, void *));
     41  1.10   mycroft void ofbus_attach __P((struct device *, struct device *, void *));
     42  1.10   mycroft static int ofbus_print __P((void *, const char *));
     43   1.1        ws 
     44   1.1        ws struct cfattach ofbus_ca = {
     45  1.10   mycroft 	sizeof(struct device), ofbus_match, ofbus_attach
     46   1.1        ws };
     47   1.1        ws 
     48   1.1        ws static int
     49  1.10   mycroft ofbus_print(aux, pnp)
     50   1.1        ws 	void *aux;
     51   1.7       cgd 	const char *pnp;
     52   1.1        ws {
     53  1.10   mycroft 	struct ofbus_attach_args *oba = aux;
     54   1.7       cgd 	char name[64];
     55   1.7       cgd 
     56  1.10   mycroft 	(void)of_packagename(oba->oba_phandle, name, sizeof name);
     57   1.7       cgd 	if (pnp)
     58   1.7       cgd 		printf("%s at %s", name, pnp);
     59   1.1        ws 	else
     60   1.7       cgd 		printf(" (%s)", name);
     61   1.1        ws 	return UNCONF;
     62   1.1        ws }
     63   1.1        ws 
     64   1.1        ws int
     65  1.10   mycroft ofbus_match(parent, cf, aux)
     66   1.1        ws 	struct device *parent;
     67   1.4   thorpej 	struct cfdata *cf;
     68   1.4   thorpej 	void *aux;
     69   1.1        ws {
     70  1.10   mycroft 	struct ofbus_attach_args *oba = aux;
     71  1.10   mycroft 
     72  1.10   mycroft 	if (strcmp(oba->oba_busname, "ofw"))
     73  1.10   mycroft 		return (0);
     74  1.10   mycroft 	if (!OF_child(oba->oba_phandle))
     75  1.10   mycroft 		return (0);
     76  1.10   mycroft 	return (1);
     77   1.1        ws }
     78   1.1        ws 
     79   1.1        ws void
     80  1.10   mycroft ofbus_attach(parent, dev, aux)
     81   1.1        ws 	struct device *parent, *dev;
     82   1.1        ws 	void *aux;
     83   1.1        ws {
     84   1.1        ws 	int child;
     85   1.1        ws 	char name[5];
     86  1.10   mycroft 	struct ofbus_attach_args *oba = aux;
     87  1.10   mycroft 	struct ofbus_attach_args oba2;
     88   1.1        ws 	int units;
     89   1.7       cgd 
     90   1.3  christos 	printf("\n");
     91   1.1        ws 
     92   1.1        ws 	/*
     93   1.1        ws 	 * This is a hack to make the probe work on the scsi (and ide) bus.
     94   1.1        ws 	 * YES, I THINK IT IS A BUG IN THE OPENFIRMWARE TO NOT PROBE ALL
     95   1.1        ws 	 * DEVICES ON THESE BUSSES.
     96   1.1        ws 	 */
     97   1.1        ws 	units = 1;
     98  1.10   mycroft 	if (OF_getprop(oba->oba_phandle, "name", name, sizeof name) > 0) {
     99   1.1        ws 		if (!strcmp(name, "scsi"))
    100   1.1        ws 			units = 7; /* What about wide or hostid != 7?	XXX */
    101   1.1        ws 		else if (!strcmp(name, "ide"))
    102   1.1        ws 			units = 2;
    103   1.1        ws 	}
    104   1.6       cgd 
    105  1.11   thorpej 	for (child = OF_child(oba->oba_phandle); child != 0;
    106  1.11   thorpej 	     child = OF_peer(child)) {
    107  1.10   mycroft 		oba2.oba_busname = "ofw";
    108  1.10   mycroft 		oba2.oba_phandle = child;
    109  1.10   mycroft 		for (oba2.oba_unit = 0; oba2.oba_unit < units; oba2.oba_unit++)
    110  1.10   mycroft 			config_found(dev, &oba2, ofbus_print);
    111   1.1        ws 	}
    112   1.1        ws }
    113