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