ofbus.c revision 1.1 1 /* $NetBSD: ofbus.c,v 1.1 1996/09/30 16:35:06 ws 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 *, void *, 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 cfdriver ofbus_cd = {
48 NULL, "ofbus", DV_DULL
49 };
50
51 struct cfattach ofroot_ca = {
52 sizeof(struct device), ofbprobe, ofbattach
53 };
54
55 struct cfdriver ofroot_cd = {
56 NULL, "ofroot", DV_DULL
57 };
58
59 static int
60 ofbprint(aux, name)
61 void *aux;
62 const char *name;
63 {
64 struct ofprobe *ofp = aux;
65 char child[64];
66 int l;
67
68 if ((l = OF_getprop(ofp->phandle, "name", child, sizeof child - 1)) < 0)
69 panic("device without name?");
70 if (l >= sizeof child)
71 l = sizeof child - 1;
72 child[l] = 0;
73
74 if (name)
75 printf("%s at %s", child, name);
76 else
77 printf(" (%s)", child);
78 return UNCONF;
79 }
80
81 int
82 ofbprobe(parent, cf, aux)
83 struct device *parent;
84 void *cf, *aux;
85 {
86 struct ofprobe *ofp = aux;
87
88 if (!OF_child(ofp->phandle))
89 return 0;
90 return 1;
91 }
92
93 void
94 ofbattach(parent, dev, aux)
95 struct device *parent, *dev;
96 void *aux;
97 {
98 int child;
99 char name[5];
100 struct ofprobe *ofp = aux;
101 struct ofprobe probe;
102 int units;
103
104 if (!parent)
105 ofbprint(aux, 0);
106
107 printf("\n");
108
109 /*
110 * This is a hack to make the probe work on the scsi (and ide) bus.
111 * YES, I THINK IT IS A BUG IN THE OPENFIRMWARE TO NOT PROBE ALL
112 * DEVICES ON THESE BUSSES.
113 */
114 units = 1;
115 if (OF_getprop(ofp->phandle, "name", name, sizeof name) > 0) {
116 if (!strcmp(name, "scsi"))
117 units = 7; /* What about wide or hostid != 7? XXX */
118 else if (!strcmp(name, "ide"))
119 units = 2;
120 }
121 for (child = OF_child(ofp->phandle); child; child = OF_peer(child)) {
122 /*
123 * This is a hack to skip all the entries in the tree
124 * that aren't devices (packages, openfirmware etc.).
125 */
126 if (OF_getprop(child, "device_type", name, sizeof name) < 0)
127 continue;
128 probe.phandle = child;
129 for (probe.unit = 0; probe.unit < units; probe.unit++)
130 config_found(dev, &probe, ofbprint);
131 }
132 }
133
134 /*
135 * Name matching routine for OpenFirmware
136 */
137 int
138 ofnmmatch(cp1, cp2)
139 char *cp1, *cp2;
140 {
141 int i;
142
143 for (i = 0; *cp2; i++)
144 if (*cp1++ != *cp2++)
145 return 0;
146 return i;
147 }
148