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