ofbus.c revision 1.7 1 /* $NetBSD: ofbus.c,v 1.7 1998/02/02 22:00: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/systm.h>
36 #include <sys/device.h>
37
38 #include <dev/ofw/openfirm.h>
39
40 int ofbprobe __P((struct device *, struct cfdata *, void *));
41 void ofbattach __P((struct device *, struct device *, void *));
42 static int ofbprint __P((void *, const char *));
43
44 struct cfattach ofbus_ca = {
45 sizeof(struct device), ofbprobe, ofbattach
46 };
47
48 struct cfattach ofroot_ca = {
49 sizeof(struct device), ofbprobe, ofbattach
50 };
51
52 static int
53 ofbprint(aux, pnp)
54 void *aux;
55 const char *pnp;
56 {
57 struct ofprobe *ofp = aux;
58 char name[64];
59
60 (void)of_nodename(ofp->phandle, name, sizeof name);
61 if (pnp)
62 printf("%s at %s", name, pnp);
63 else
64 printf(" (%s)", name);
65 return UNCONF;
66 }
67
68 int
69 ofbprobe(parent, cf, aux)
70 struct device *parent;
71 struct cfdata *cf;
72 void *aux;
73 {
74 struct ofprobe *ofp = aux;
75
76 if (!OF_child(ofp->phandle))
77 return 0;
78 return 1;
79 }
80
81 void
82 ofbattach(parent, dev, aux)
83 struct device *parent, *dev;
84 void *aux;
85 {
86 int child;
87 char name[5];
88 struct ofprobe *ofp = aux;
89 struct ofprobe probe;
90 int units;
91
92 if (!parent)
93 ofbprint(aux, 0);
94
95 printf("\n");
96
97 /*
98 * This is a hack to make the probe work on the scsi (and ide) bus.
99 * YES, I THINK IT IS A BUG IN THE OPENFIRMWARE TO NOT PROBE ALL
100 * DEVICES ON THESE BUSSES.
101 */
102 units = 1;
103 if (OF_getprop(ofp->phandle, "name", name, sizeof name) > 0) {
104 if (!strcmp(name, "scsi"))
105 units = 7; /* What about wide or hostid != 7? XXX */
106 else if (!strcmp(name, "ide"))
107 units = 2;
108 }
109
110 for (child = OF_child(ofp->phandle); child; child = OF_peer(child)) {
111 /*
112 * This is a hack to skip all the entries in the tree
113 * that aren't devices (packages, openfirmware etc.).
114 */
115 if (OF_getprop(child, "device_type", name, sizeof name) < 0 &&
116 OF_getprop(child, "compatible", name, sizeof name) < 0)
117 continue;
118 probe.phandle = child;
119 for (probe.unit = 0; probe.unit < units; probe.unit++)
120 config_found(dev, &probe, ofbprint);
121 }
122 }
123