ofw_autoconf.c revision 1.2.8.2 1 1.2.8.2 mjf /* $NetBSD: ofw_autoconf.c,v 1.2.8.2 2007/11/19 00:46:45 mjf Exp $ */
2 1.2.8.2 mjf /*
3 1.2.8.2 mjf * Copyright (C) 1995, 1996 Wolfgang Solfrank.
4 1.2.8.2 mjf * Copyright (C) 1995, 1996 TooLs GmbH.
5 1.2.8.2 mjf * All rights reserved.
6 1.2.8.2 mjf *
7 1.2.8.2 mjf * Redistribution and use in source and binary forms, with or without
8 1.2.8.2 mjf * modification, are permitted provided that the following conditions
9 1.2.8.2 mjf * are met:
10 1.2.8.2 mjf * 1. Redistributions of source code must retain the above copyright
11 1.2.8.2 mjf * notice, this list of conditions and the following disclaimer.
12 1.2.8.2 mjf * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.8.2 mjf * notice, this list of conditions and the following disclaimer in the
14 1.2.8.2 mjf * documentation and/or other materials provided with the distribution.
15 1.2.8.2 mjf * 3. All advertising materials mentioning features or use of this software
16 1.2.8.2 mjf * must display the following acknowledgement:
17 1.2.8.2 mjf * This product includes software developed by TooLs GmbH.
18 1.2.8.2 mjf * 4. The name of TooLs GmbH may not be used to endorse or promote products
19 1.2.8.2 mjf * derived from this software without specific prior written permission.
20 1.2.8.2 mjf *
21 1.2.8.2 mjf * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
22 1.2.8.2 mjf * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.2.8.2 mjf * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.2.8.2 mjf * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 1.2.8.2 mjf * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 1.2.8.2 mjf * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 1.2.8.2 mjf * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 1.2.8.2 mjf * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 1.2.8.2 mjf * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 1.2.8.2 mjf * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.2.8.2 mjf */
32 1.2.8.2 mjf
33 1.2.8.2 mjf #include <sys/cdefs.h>
34 1.2.8.2 mjf __KERNEL_RCSID(0, "$NetBSD: ofw_autoconf.c,v 1.2.8.2 2007/11/19 00:46:45 mjf Exp $");
35 1.2.8.2 mjf
36 1.2.8.2 mjf #include <sys/param.h>
37 1.2.8.2 mjf #include <sys/conf.h>
38 1.2.8.2 mjf #include <sys/device.h>
39 1.2.8.2 mjf #include <sys/reboot.h>
40 1.2.8.2 mjf #include <sys/systm.h>
41 1.2.8.2 mjf
42 1.2.8.2 mjf #include <uvm/uvm_extern.h>
43 1.2.8.2 mjf
44 1.2.8.2 mjf #include <machine/autoconf.h>
45 1.2.8.2 mjf #include <machine/bus.h>
46 1.2.8.2 mjf #include <machine/stdarg.h>
47 1.2.8.2 mjf
48 1.2.8.2 mjf #include <dev/ofw/openfirm.h>
49 1.2.8.2 mjf #include <dev/pci/pcivar.h>
50 1.2.8.2 mjf #include <dev/scsipi/scsi_all.h>
51 1.2.8.2 mjf #include <dev/scsipi/scsipi_all.h>
52 1.2.8.2 mjf #include <dev/scsipi/scsiconf.h>
53 1.2.8.2 mjf #include <dev/ata/atavar.h>
54 1.2.8.2 mjf #include <dev/ic/wdcvar.h>
55 1.2.8.2 mjf #include <dev/wsfb/genfbvar.h>
56 1.2.8.2 mjf
57 1.2.8.2 mjf extern char bootpath[256];
58 1.2.8.2 mjf char cbootpath[256];
59 1.2.8.2 mjf int console_node = 0, console_instance = 0;
60 1.2.8.2 mjf
61 1.2.8.2 mjf #ifdef macppc
62 1.2.8.2 mjf volatile uint32_t *heathrow_FCR = NULL;
63 1.2.8.2 mjf #endif
64 1.2.8.2 mjf
65 1.2.8.2 mjf struct genfb_colormap_callback gfb_cb;
66 1.2.8.2 mjf static void of_set_palette(void *, int, int, int, int);
67 1.2.8.2 mjf static void add_model_specifics(prop_dictionary_t);
68 1.2.8.2 mjf static void copyprops(int, prop_dictionary_t);
69 1.2.8.2 mjf static void canonicalize_bootpath(void);
70 1.2.8.2 mjf
71 1.2.8.2 mjf /*
72 1.2.8.2 mjf * Determine device configuration for a machine.
73 1.2.8.2 mjf */
74 1.2.8.2 mjf void
75 1.2.8.2 mjf cpu_configure(void)
76 1.2.8.2 mjf {
77 1.2.8.2 mjf init_interrupt();
78 1.2.8.2 mjf canonicalize_bootpath();
79 1.2.8.2 mjf
80 1.2.8.2 mjf if (config_rootfound("mainbus", NULL) == NULL)
81 1.2.8.2 mjf panic("configure: mainbus not configured");
82 1.2.8.2 mjf
83 1.2.8.2 mjf genppc_cpu_configure();
84 1.2.8.2 mjf }
85 1.2.8.2 mjf
86 1.2.8.2 mjf static void
87 1.2.8.2 mjf canonicalize_bootpath(void)
88 1.2.8.2 mjf {
89 1.2.8.2 mjf int node;
90 1.2.8.2 mjf char *p, *lastp;
91 1.2.8.2 mjf char last[32];
92 1.2.8.2 mjf
93 1.2.8.2 mjf /*
94 1.2.8.2 mjf * If the bootpath doesn't start with a / then it isn't
95 1.2.8.2 mjf * an OFW path and probably is an alias, so look up the alias
96 1.2.8.2 mjf * and regenerate the full bootpath so device_register will work.
97 1.2.8.2 mjf */
98 1.2.8.2 mjf if (bootpath[0] != '/' && bootpath[0] != '\0') {
99 1.2.8.2 mjf int aliases = OF_finddevice("/aliases");
100 1.2.8.2 mjf char tmpbuf[100];
101 1.2.8.2 mjf char aliasbuf[256];
102 1.2.8.2 mjf if (aliases != 0) {
103 1.2.8.2 mjf char *cp1, *cp2, *cp;
104 1.2.8.2 mjf char saved_ch = '\0';
105 1.2.8.2 mjf int len;
106 1.2.8.2 mjf cp1 = strchr(bootpath, ':');
107 1.2.8.2 mjf cp2 = strchr(bootpath, ',');
108 1.2.8.2 mjf cp = cp1;
109 1.2.8.2 mjf if (cp1 == NULL || (cp2 != NULL && cp2 < cp1))
110 1.2.8.2 mjf cp = cp2;
111 1.2.8.2 mjf tmpbuf[0] = '\0';
112 1.2.8.2 mjf if (cp != NULL) {
113 1.2.8.2 mjf strcpy(tmpbuf, cp);
114 1.2.8.2 mjf saved_ch = *cp;
115 1.2.8.2 mjf *cp = '\0';
116 1.2.8.2 mjf }
117 1.2.8.2 mjf len = OF_getprop(aliases, bootpath, aliasbuf,
118 1.2.8.2 mjf sizeof(aliasbuf));
119 1.2.8.2 mjf if (len > 0) {
120 1.2.8.2 mjf if (aliasbuf[len-1] == '\0')
121 1.2.8.2 mjf len--;
122 1.2.8.2 mjf memcpy(bootpath, aliasbuf, len);
123 1.2.8.2 mjf strcpy(&bootpath[len], tmpbuf);
124 1.2.8.2 mjf } else {
125 1.2.8.2 mjf *cp = saved_ch;
126 1.2.8.2 mjf }
127 1.2.8.2 mjf }
128 1.2.8.2 mjf }
129 1.2.8.2 mjf
130 1.2.8.2 mjf /*
131 1.2.8.2 mjf * Strip kernel name. bootpath contains "OF-path"/"kernel".
132 1.2.8.2 mjf *
133 1.2.8.2 mjf * for example:
134 1.2.8.2 mjf * /bandit@F2000000/gc@10/53c94@10000/sd@0,0/netbsd (OF-1.x)
135 1.2.8.2 mjf * /pci/mac-io/ata-3@2000/disk@0:0/netbsd.new (OF-3.x)
136 1.2.8.2 mjf */
137 1.2.8.2 mjf strcpy(cbootpath, bootpath);
138 1.2.8.2 mjf while ((node = OF_finddevice(cbootpath)) == -1) {
139 1.2.8.2 mjf if ((p = strrchr(cbootpath, '/')) == NULL)
140 1.2.8.2 mjf break;
141 1.2.8.2 mjf *p = '\0';
142 1.2.8.2 mjf }
143 1.2.8.2 mjf
144 1.2.8.2 mjf if (node == -1) {
145 1.2.8.2 mjf /* Cannot canonicalize... use bootpath anyway. */
146 1.2.8.2 mjf strcpy(cbootpath, bootpath);
147 1.2.8.2 mjf
148 1.2.8.2 mjf return;
149 1.2.8.2 mjf }
150 1.2.8.2 mjf
151 1.2.8.2 mjf /*
152 1.2.8.2 mjf * cbootpath is a valid OF path. Use package-to-path to
153 1.2.8.2 mjf * canonicalize pathname.
154 1.2.8.2 mjf */
155 1.2.8.2 mjf
156 1.2.8.2 mjf /* Back up the last component for later use. */
157 1.2.8.2 mjf if ((p = strrchr(cbootpath, '/')) != NULL)
158 1.2.8.2 mjf strcpy(last, p + 1);
159 1.2.8.2 mjf else
160 1.2.8.2 mjf last[0] = '\0';
161 1.2.8.2 mjf
162 1.2.8.2 mjf memset(cbootpath, 0, sizeof(cbootpath));
163 1.2.8.2 mjf OF_package_to_path(node, cbootpath, sizeof(cbootpath) - 1);
164 1.2.8.2 mjf
165 1.2.8.2 mjf /*
166 1.2.8.2 mjf * OF_1.x (at least) always returns addr == 0 for
167 1.2.8.2 mjf * SCSI disks (i.e. "/bandit (at) .../.../sd@0,0").
168 1.2.8.2 mjf */
169 1.2.8.2 mjf lastp = strrchr(cbootpath, '/');
170 1.2.8.2 mjf if (lastp != NULL) {
171 1.2.8.2 mjf lastp++;
172 1.2.8.2 mjf if (strncmp(lastp, "sd@", 3) == 0
173 1.2.8.2 mjf && strncmp(last, "sd@", 3) == 0)
174 1.2.8.2 mjf strcpy(lastp, last);
175 1.2.8.2 mjf } else {
176 1.2.8.2 mjf lastp = cbootpath;
177 1.2.8.2 mjf }
178 1.2.8.2 mjf
179 1.2.8.2 mjf /*
180 1.2.8.2 mjf * At this point, cbootpath contains like:
181 1.2.8.2 mjf * "/pci@80000000/mac-io@10/ata-3@20000/disk"
182 1.2.8.2 mjf *
183 1.2.8.2 mjf * The last component may have no address... so append it.
184 1.2.8.2 mjf */
185 1.2.8.2 mjf if (strchr(lastp, '@') == NULL) {
186 1.2.8.2 mjf /* Append it. */
187 1.2.8.2 mjf if ((p = strrchr(last, '@')) != NULL)
188 1.2.8.2 mjf strcat(cbootpath, p);
189 1.2.8.2 mjf }
190 1.2.8.2 mjf
191 1.2.8.2 mjf if ((p = strrchr(lastp, ':')) != NULL) {
192 1.2.8.2 mjf *p++ = '\0';
193 1.2.8.2 mjf /* booted_partition = *p - '0'; XXX correct? */
194 1.2.8.2 mjf }
195 1.2.8.2 mjf
196 1.2.8.2 mjf /* XXX Does this belong here, or device_register()? */
197 1.2.8.2 mjf if ((p = strrchr(lastp, ',')) != NULL)
198 1.2.8.2 mjf *p = '\0';
199 1.2.8.2 mjf }
200 1.2.8.2 mjf
201 1.2.8.2 mjf /*
202 1.2.8.2 mjf * device_register is called from config_attach as each device is
203 1.2.8.2 mjf * attached. We use it to find the NetBSD device corresponding to the
204 1.2.8.2 mjf * known OF boot device.
205 1.2.8.2 mjf */
206 1.2.8.2 mjf void
207 1.2.8.2 mjf device_register(dev, aux)
208 1.2.8.2 mjf struct device *dev;
209 1.2.8.2 mjf void *aux;
210 1.2.8.2 mjf {
211 1.2.8.2 mjf static struct device *parent;
212 1.2.8.2 mjf static char *bp = bootpath + 1, *cp = cbootpath;
213 1.2.8.2 mjf unsigned long addr;
214 1.2.8.2 mjf char *p;
215 1.2.8.2 mjf
216 1.2.8.2 mjf if (booted_device)
217 1.2.8.2 mjf return;
218 1.2.8.2 mjf
219 1.2.8.2 mjf /* Skip over devices not represented in the OF tree. */
220 1.2.8.2 mjf if (device_is_a(dev, "mainbus")) {
221 1.2.8.2 mjf parent = dev;
222 1.2.8.2 mjf return;
223 1.2.8.2 mjf }
224 1.2.8.2 mjf if (device_is_a(dev, "atapibus") || device_is_a(dev, "pci") ||
225 1.2.8.2 mjf device_is_a(dev, "scsibus") || device_is_a(dev, "atabus"))
226 1.2.8.2 mjf return;
227 1.2.8.2 mjf
228 1.2.8.2 mjf if (device_is_a(device_parent(dev), "pci")) {
229 1.2.8.2 mjf /* see if this is going to be console */
230 1.2.8.2 mjf struct pci_attach_args *pa = aux;
231 1.2.8.2 mjf prop_dictionary_t dict;
232 1.2.8.2 mjf int node, sub;
233 1.2.8.2 mjf int console = 0;
234 1.2.8.2 mjf
235 1.2.8.2 mjf dict = device_properties(dev);
236 1.2.8.2 mjf node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
237 1.2.8.2 mjf prop_dictionary_set_uint32(dict, "device_node", node);
238 1.2.8.2 mjf
239 1.2.8.2 mjf console = (node == console_node);
240 1.2.8.2 mjf
241 1.2.8.2 mjf if (!console) {
242 1.2.8.2 mjf /*
243 1.2.8.2 mjf * see if any child matches since OF attaches nodes for
244 1.2.8.2 mjf * each head and /chosen/stdout points to the head
245 1.2.8.2 mjf * rather than the device itself in this case
246 1.2.8.2 mjf */
247 1.2.8.2 mjf sub = OF_child(node);
248 1.2.8.2 mjf while ((sub != 0) && (sub != console_node)) {
249 1.2.8.2 mjf sub = OF_peer(sub);
250 1.2.8.2 mjf }
251 1.2.8.2 mjf if (sub == console_node) {
252 1.2.8.2 mjf console = true;
253 1.2.8.2 mjf }
254 1.2.8.2 mjf }
255 1.2.8.2 mjf
256 1.2.8.2 mjf if (console) {
257 1.2.8.2 mjf uint64_t cmap_cb;
258 1.2.8.2 mjf
259 1.2.8.2 mjf prop_dictionary_set_uint32(dict, "instance_handle",
260 1.2.8.2 mjf console_instance);
261 1.2.8.2 mjf copyprops(console_node, dict);
262 1.2.8.2 mjf
263 1.2.8.2 mjf gfb_cb.gcc_cookie = (void *)console_instance;
264 1.2.8.2 mjf gfb_cb.gcc_set_mapreg = of_set_palette;
265 1.2.8.2 mjf cmap_cb = (uint64_t)&gfb_cb;
266 1.2.8.2 mjf prop_dictionary_set_uint64(dict, "cmap_callback",
267 1.2.8.2 mjf cmap_cb);
268 1.2.8.2 mjf }
269 1.2.8.2 mjf }
270 1.2.8.2 mjf
271 1.2.8.2 mjf if (device_is_a(device_parent(dev), "atapibus") ||
272 1.2.8.2 mjf device_is_a(device_parent(dev), "atabus") ||
273 1.2.8.2 mjf device_is_a(device_parent(dev), "pci") ||
274 1.2.8.2 mjf device_is_a(device_parent(dev), "scsibus")) {
275 1.2.8.2 mjf if (device_parent(device_parent(dev)) != parent)
276 1.2.8.2 mjf return;
277 1.2.8.2 mjf } else {
278 1.2.8.2 mjf if (device_parent(dev) != parent)
279 1.2.8.2 mjf return;
280 1.2.8.2 mjf }
281 1.2.8.2 mjf
282 1.2.8.2 mjf /* Get the address part of the current path component. The
283 1.2.8.2 mjf * last component of the canonical bootpath may have no
284 1.2.8.2 mjf * address (eg, "disk"), in which case we need to get the
285 1.2.8.2 mjf * address from the original bootpath instead.
286 1.2.8.2 mjf */
287 1.2.8.2 mjf p = strchr(cp, '@');
288 1.2.8.2 mjf if (!p) {
289 1.2.8.2 mjf if (bp)
290 1.2.8.2 mjf p = strchr(bp, '@');
291 1.2.8.2 mjf if (!p)
292 1.2.8.2 mjf addr = 0;
293 1.2.8.2 mjf else {
294 1.2.8.2 mjf addr = strtoul(p + 1, NULL, 16);
295 1.2.8.2 mjf p = NULL;
296 1.2.8.2 mjf }
297 1.2.8.2 mjf } else
298 1.2.8.2 mjf addr = strtoul(p + 1, &p, 16);
299 1.2.8.2 mjf
300 1.2.8.2 mjf if (device_is_a(device_parent(dev), "mainbus")) {
301 1.2.8.2 mjf struct confargs *ca = aux;
302 1.2.8.2 mjf
303 1.2.8.2 mjf if (strcmp(ca->ca_name, "ofw") == 0) /* XXX */
304 1.2.8.2 mjf return;
305 1.2.8.2 mjf if (addr != ca->ca_reg[0])
306 1.2.8.2 mjf return;
307 1.2.8.2 mjf } else if (device_is_a(device_parent(dev), "pci")) {
308 1.2.8.2 mjf struct pci_attach_args *pa = aux;
309 1.2.8.2 mjf
310 1.2.8.2 mjf if (addr != pa->pa_device)
311 1.2.8.2 mjf return;
312 1.2.8.2 mjf } else if (device_is_a(device_parent(dev), "obio")) {
313 1.2.8.2 mjf struct confargs *ca = aux;
314 1.2.8.2 mjf
315 1.2.8.2 mjf if (addr != ca->ca_reg[0])
316 1.2.8.2 mjf return;
317 1.2.8.2 mjf } else if (device_is_a(device_parent(dev), "scsibus") ||
318 1.2.8.2 mjf device_is_a(device_parent(dev), "atapibus")) {
319 1.2.8.2 mjf struct scsipibus_attach_args *sa = aux;
320 1.2.8.2 mjf
321 1.2.8.2 mjf /* periph_target is target for scsi, drive # for atapi */
322 1.2.8.2 mjf if (addr != sa->sa_periph->periph_target)
323 1.2.8.2 mjf return;
324 1.2.8.2 mjf } else if (device_is_a(device_parent(device_parent(dev)), "pciide")) {
325 1.2.8.2 mjf struct ata_device *adev = aux;
326 1.2.8.2 mjf
327 1.2.8.2 mjf if (addr != adev->adev_drv_data->drive)
328 1.2.8.2 mjf return;
329 1.2.8.2 mjf
330 1.2.8.2 mjf /*
331 1.2.8.2 mjf * OF splits channel and drive into separate path
332 1.2.8.2 mjf * components, so check the addr part of the next
333 1.2.8.2 mjf * component. (Ignore bp, because the canonical path
334 1.2.8.2 mjf * will be complete in the pciide case.)
335 1.2.8.2 mjf */
336 1.2.8.2 mjf p = strchr(p, '@');
337 1.2.8.2 mjf if (!p++)
338 1.2.8.2 mjf return;
339 1.2.8.2 mjf if (strtoul(p, &p, 16) != adev->adev_drv_data->drive)
340 1.2.8.2 mjf return;
341 1.2.8.2 mjf } else if (device_is_a(device_parent(device_parent(dev)), "wdc")) {
342 1.2.8.2 mjf struct ata_device *adev = aux;
343 1.2.8.2 mjf
344 1.2.8.2 mjf if (addr != adev->adev_drv_data->drive)
345 1.2.8.2 mjf return;
346 1.2.8.2 mjf } else
347 1.2.8.2 mjf return;
348 1.2.8.2 mjf
349 1.2.8.2 mjf /* If we reach this point, then dev is a match for the current
350 1.2.8.2 mjf * path component.
351 1.2.8.2 mjf */
352 1.2.8.2 mjf
353 1.2.8.2 mjf if (p && *p) {
354 1.2.8.2 mjf parent = dev;
355 1.2.8.2 mjf cp = p;
356 1.2.8.2 mjf bp = strchr(bp, '/');
357 1.2.8.2 mjf if (bp)
358 1.2.8.2 mjf bp++;
359 1.2.8.2 mjf return;
360 1.2.8.2 mjf } else {
361 1.2.8.2 mjf booted_device = dev;
362 1.2.8.2 mjf booted_partition = 0; /* XXX -- should be extracted from bootpath */
363 1.2.8.2 mjf return;
364 1.2.8.2 mjf }
365 1.2.8.2 mjf }
366 1.2.8.2 mjf
367 1.2.8.2 mjf /*
368 1.2.8.2 mjf * Setup root device.
369 1.2.8.2 mjf * Configure swap area.
370 1.2.8.2 mjf */
371 1.2.8.2 mjf void
372 1.2.8.2 mjf cpu_rootconf()
373 1.2.8.2 mjf {
374 1.2.8.2 mjf printf("boot device: %s\n",
375 1.2.8.2 mjf booted_device ? booted_device->dv_xname : "<unknown>");
376 1.2.8.2 mjf
377 1.2.8.2 mjf setroot(booted_device, booted_partition);
378 1.2.8.2 mjf }
379 1.2.8.2 mjf
380 1.2.8.2 mjf /*
381 1.2.8.2 mjf * Find OF-device corresponding to the PCI device.
382 1.2.8.2 mjf */
383 1.2.8.2 mjf int
384 1.2.8.2 mjf pcidev_to_ofdev(pci_chipset_tag_t pc, pcitag_t tag)
385 1.2.8.2 mjf {
386 1.2.8.2 mjf int bus, dev, func;
387 1.2.8.2 mjf u_int reg[5];
388 1.2.8.2 mjf int p, q;
389 1.2.8.2 mjf int l, b, d, f;
390 1.2.8.2 mjf
391 1.2.8.2 mjf pci_decompose_tag(pc, tag, &bus, &dev, &func);
392 1.2.8.2 mjf
393 1.2.8.2 mjf for (q = OF_peer(0); q; q = p) {
394 1.2.8.2 mjf l = OF_getprop(q, "assigned-addresses", reg, sizeof(reg));
395 1.2.8.2 mjf if (l > 4) {
396 1.2.8.2 mjf b = (reg[0] >> 16) & 0xff;
397 1.2.8.2 mjf d = (reg[0] >> 11) & 0x1f;
398 1.2.8.2 mjf f = (reg[0] >> 8) & 0x07;
399 1.2.8.2 mjf
400 1.2.8.2 mjf if (b == bus && d == dev && f == func)
401 1.2.8.2 mjf return q;
402 1.2.8.2 mjf }
403 1.2.8.2 mjf if ((p = OF_child(q)))
404 1.2.8.2 mjf continue;
405 1.2.8.2 mjf while (q) {
406 1.2.8.2 mjf if ((p = OF_peer(q)))
407 1.2.8.2 mjf break;
408 1.2.8.2 mjf q = OF_parent(q);
409 1.2.8.2 mjf }
410 1.2.8.2 mjf }
411 1.2.8.2 mjf return 0;
412 1.2.8.2 mjf }
413 1.2.8.2 mjf
414 1.2.8.2 mjf static void
415 1.2.8.2 mjf add_model_specifics(prop_dictionary_t dict)
416 1.2.8.2 mjf {
417 1.2.8.2 mjf const char *bl_rev_models[] = {
418 1.2.8.2 mjf "PowerBook4,3", "PowerBook6,3", "PowerBook6,5", NULL};
419 1.2.8.2 mjf int node;
420 1.2.8.2 mjf
421 1.2.8.2 mjf node = OF_finddevice("/");
422 1.2.8.2 mjf
423 1.2.8.2 mjf if (of_compatible(node, bl_rev_models) != -1) {
424 1.2.8.2 mjf prop_dictionary_set_bool(dict, "backlight_level_reverted", 1);
425 1.2.8.2 mjf }
426 1.2.8.2 mjf }
427 1.2.8.2 mjf
428 1.2.8.2 mjf static void
429 1.2.8.2 mjf copyprops(int node, prop_dictionary_t dict)
430 1.2.8.2 mjf {
431 1.2.8.2 mjf uint32_t temp;
432 1.2.8.2 mjf
433 1.2.8.2 mjf prop_dictionary_set_bool(dict, "is_console", 1);
434 1.2.8.2 mjf if (!of_to_uint32_prop(dict, node, "width", "width")) {
435 1.2.8.2 mjf
436 1.2.8.2 mjf OF_interpret("screen-width", 0, 1, &temp);
437 1.2.8.2 mjf prop_dictionary_set_uint32(dict, "width", temp);
438 1.2.8.2 mjf }
439 1.2.8.2 mjf if (!of_to_uint32_prop(dict, console_node, "height", "height")) {
440 1.2.8.2 mjf
441 1.2.8.2 mjf OF_interpret("screen-height", 0, 1, &temp);
442 1.2.8.2 mjf prop_dictionary_set_uint32(dict, "height", temp);
443 1.2.8.2 mjf }
444 1.2.8.2 mjf of_to_uint32_prop(dict, console_node, "linebytes", "linebytes");
445 1.2.8.2 mjf if (!of_to_uint32_prop(dict, console_node, "depth", "depth")) {
446 1.2.8.2 mjf /*
447 1.2.8.2 mjf * XXX we should check linebytes vs. width but those
448 1.2.8.2 mjf * FBs that don't have a depth property ( /chaos/control... )
449 1.2.8.2 mjf * won't have linebytes either
450 1.2.8.2 mjf */
451 1.2.8.2 mjf prop_dictionary_set_uint32(dict, "depth", 8);
452 1.2.8.2 mjf }
453 1.2.8.2 mjf if (!of_to_uint32_prop(dict, console_node, "address", "address")) {
454 1.2.8.2 mjf uint32_t fbaddr = 0;
455 1.2.8.2 mjf OF_interpret("frame-buffer-adr", 0, 1, &fbaddr);
456 1.2.8.2 mjf if (fbaddr != 0)
457 1.2.8.2 mjf prop_dictionary_set_uint32(dict, "address", fbaddr);
458 1.2.8.2 mjf }
459 1.2.8.2 mjf of_to_dataprop(dict, console_node, "EDID", "EDID");
460 1.2.8.2 mjf add_model_specifics(dict);
461 1.2.8.2 mjf
462 1.2.8.2 mjf temp = 0;
463 1.2.8.2 mjf if (OF_getprop(console_node, "ATY,RefCLK", &temp, sizeof(temp)) != 4) {
464 1.2.8.2 mjf
465 1.2.8.2 mjf OF_getprop(OF_parent(console_node), "ATY,RefCLK", &temp,
466 1.2.8.2 mjf sizeof(temp));
467 1.2.8.2 mjf }
468 1.2.8.2 mjf if (temp != 0)
469 1.2.8.2 mjf prop_dictionary_set_uint32(dict, "refclk", temp / 10);
470 1.2.8.2 mjf }
471 1.2.8.2 mjf
472 1.2.8.2 mjf static void
473 1.2.8.2 mjf of_set_palette(void *cookie, int index, int r, int g, int b)
474 1.2.8.2 mjf {
475 1.2.8.2 mjf int ih = (int)cookie;
476 1.2.8.2 mjf
477 1.2.8.2 mjf OF_call_method_1("color!", ih, 4, r, g, b, index);
478 1.2.8.2 mjf }
479