ofw_autoconf.c revision 1.20.22.2 1 1.20.22.2 martin /* $NetBSD: ofw_autoconf.c,v 1.20.22.2 2019/12/07 08:46:48 martin Exp $ */
2 1.1 garbled /*
3 1.1 garbled * Copyright (C) 1995, 1996 Wolfgang Solfrank.
4 1.1 garbled * Copyright (C) 1995, 1996 TooLs GmbH.
5 1.1 garbled * All rights reserved.
6 1.1 garbled *
7 1.1 garbled * Redistribution and use in source and binary forms, with or without
8 1.1 garbled * modification, are permitted provided that the following conditions
9 1.1 garbled * are met:
10 1.1 garbled * 1. Redistributions of source code must retain the above copyright
11 1.1 garbled * notice, this list of conditions and the following disclaimer.
12 1.1 garbled * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 garbled * notice, this list of conditions and the following disclaimer in the
14 1.1 garbled * documentation and/or other materials provided with the distribution.
15 1.1 garbled * 3. All advertising materials mentioning features or use of this software
16 1.1 garbled * must display the following acknowledgement:
17 1.1 garbled * This product includes software developed by TooLs GmbH.
18 1.1 garbled * 4. The name of TooLs GmbH may not be used to endorse or promote products
19 1.1 garbled * derived from this software without specific prior written permission.
20 1.1 garbled *
21 1.1 garbled * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
22 1.1 garbled * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 garbled * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 garbled * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 1.1 garbled * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 1.1 garbled * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 1.1 garbled * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 1.1 garbled * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 1.1 garbled * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 1.1 garbled * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 garbled */
32 1.1 garbled
33 1.1 garbled #include <sys/cdefs.h>
34 1.20.22.2 martin __KERNEL_RCSID(0, "$NetBSD: ofw_autoconf.c,v 1.20.22.2 2019/12/07 08:46:48 martin Exp $");
35 1.12 kiyohara
36 1.12 kiyohara #ifdef ofppc
37 1.12 kiyohara #include "gtpci.h"
38 1.12 kiyohara #endif
39 1.1 garbled
40 1.1 garbled #include <sys/param.h>
41 1.1 garbled #include <sys/conf.h>
42 1.1 garbled #include <sys/device.h>
43 1.1 garbled #include <sys/reboot.h>
44 1.1 garbled #include <sys/systm.h>
45 1.1 garbled
46 1.1 garbled #include <uvm/uvm_extern.h>
47 1.1 garbled
48 1.1 garbled #include <machine/autoconf.h>
49 1.14 dyoung #include <sys/bus.h>
50 1.1 garbled
51 1.1 garbled #include <dev/ofw/openfirm.h>
52 1.12 kiyohara #include <dev/marvell/marvellvar.h>
53 1.6 aymeric #include <dev/pci/pcireg.h>
54 1.1 garbled #include <dev/pci/pcivar.h>
55 1.12 kiyohara #if NGTPCI > 0
56 1.12 kiyohara #include <dev/marvell/gtpcivar.h>
57 1.12 kiyohara #endif
58 1.1 garbled #include <dev/scsipi/scsi_all.h>
59 1.1 garbled #include <dev/scsipi/scsipi_all.h>
60 1.1 garbled #include <dev/scsipi/scsiconf.h>
61 1.1 garbled #include <dev/ata/atavar.h>
62 1.1 garbled #include <dev/ic/wdcvar.h>
63 1.1 garbled
64 1.12 kiyohara #include <machine/pci_machdep.h>
65 1.12 kiyohara
66 1.12 kiyohara #include <prop/proplib.h>
67 1.12 kiyohara
68 1.1 garbled extern char bootpath[256];
69 1.1 garbled char cbootpath[256];
70 1.1 garbled
71 1.1 garbled static void canonicalize_bootpath(void);
72 1.1 garbled
73 1.1 garbled /*
74 1.1 garbled * Determine device configuration for a machine.
75 1.1 garbled */
76 1.1 garbled void
77 1.1 garbled cpu_configure(void)
78 1.1 garbled {
79 1.1 garbled init_interrupt();
80 1.1 garbled canonicalize_bootpath();
81 1.1 garbled
82 1.1 garbled if (config_rootfound("mainbus", NULL) == NULL)
83 1.1 garbled panic("configure: mainbus not configured");
84 1.1 garbled
85 1.1 garbled genppc_cpu_configure();
86 1.1 garbled }
87 1.1 garbled
88 1.1 garbled static void
89 1.1 garbled canonicalize_bootpath(void)
90 1.1 garbled {
91 1.1 garbled int node;
92 1.1 garbled char *p, *lastp;
93 1.20.22.2 martin char last[32], type[32];
94 1.1 garbled
95 1.1 garbled /*
96 1.1 garbled * If the bootpath doesn't start with a / then it isn't
97 1.1 garbled * an OFW path and probably is an alias, so look up the alias
98 1.1 garbled * and regenerate the full bootpath so device_register will work.
99 1.1 garbled */
100 1.1 garbled if (bootpath[0] != '/' && bootpath[0] != '\0') {
101 1.1 garbled int aliases = OF_finddevice("/aliases");
102 1.1 garbled char tmpbuf[100];
103 1.1 garbled char aliasbuf[256];
104 1.1 garbled if (aliases != 0) {
105 1.1 garbled char *cp1, *cp2, *cp;
106 1.1 garbled char saved_ch = '\0';
107 1.1 garbled int len;
108 1.1 garbled cp1 = strchr(bootpath, ':');
109 1.1 garbled cp2 = strchr(bootpath, ',');
110 1.1 garbled cp = cp1;
111 1.1 garbled if (cp1 == NULL || (cp2 != NULL && cp2 < cp1))
112 1.1 garbled cp = cp2;
113 1.1 garbled tmpbuf[0] = '\0';
114 1.1 garbled if (cp != NULL) {
115 1.1 garbled strcpy(tmpbuf, cp);
116 1.1 garbled saved_ch = *cp;
117 1.1 garbled *cp = '\0';
118 1.1 garbled }
119 1.1 garbled len = OF_getprop(aliases, bootpath, aliasbuf,
120 1.1 garbled sizeof(aliasbuf));
121 1.1 garbled if (len > 0) {
122 1.1 garbled if (aliasbuf[len-1] == '\0')
123 1.1 garbled len--;
124 1.1 garbled memcpy(bootpath, aliasbuf, len);
125 1.1 garbled strcpy(&bootpath[len], tmpbuf);
126 1.1 garbled } else {
127 1.1 garbled *cp = saved_ch;
128 1.1 garbled }
129 1.1 garbled }
130 1.1 garbled }
131 1.1 garbled
132 1.1 garbled /*
133 1.1 garbled * Strip kernel name. bootpath contains "OF-path"/"kernel".
134 1.1 garbled *
135 1.1 garbled * for example:
136 1.1 garbled * /bandit@F2000000/gc@10/53c94@10000/sd@0,0/netbsd (OF-1.x)
137 1.1 garbled * /pci/mac-io/ata-3@2000/disk@0:0/netbsd.new (OF-3.x)
138 1.1 garbled */
139 1.1 garbled strcpy(cbootpath, bootpath);
140 1.20.22.1 bouyer
141 1.20.22.1 bouyer if ((node = OF_finddevice("/options")) == -1 ||
142 1.20.22.1 bouyer OF_getprop(node, "qemu_boot_hack", type, sizeof(type) - 1) == -1 ||
143 1.20.22.1 bouyer type[0] != 'y') {
144 1.20.22.1 bouyer while ((node = OF_finddevice(cbootpath)) == -1) {
145 1.20.22.1 bouyer if ((p = strrchr(cbootpath, '/')) == NULL)
146 1.20.22.1 bouyer break;
147 1.20.22.1 bouyer *p = '\0';
148 1.20.22.1 bouyer }
149 1.20.22.1 bouyer } else {
150 1.20.22.1 bouyer node = -1;
151 1.1 garbled }
152 1.1 garbled
153 1.7 mrg printf("bootpath: %s\n", bootpath);
154 1.1 garbled if (node == -1) {
155 1.1 garbled /* Cannot canonicalize... use bootpath anyway. */
156 1.1 garbled strcpy(cbootpath, bootpath);
157 1.1 garbled
158 1.1 garbled return;
159 1.1 garbled }
160 1.1 garbled
161 1.1 garbled /*
162 1.1 garbled * cbootpath is a valid OF path. Use package-to-path to
163 1.1 garbled * canonicalize pathname.
164 1.1 garbled */
165 1.1 garbled
166 1.1 garbled /* Back up the last component for later use. */
167 1.1 garbled if ((p = strrchr(cbootpath, '/')) != NULL)
168 1.1 garbled strcpy(last, p + 1);
169 1.1 garbled else
170 1.1 garbled last[0] = '\0';
171 1.1 garbled
172 1.1 garbled memset(cbootpath, 0, sizeof(cbootpath));
173 1.1 garbled OF_package_to_path(node, cbootpath, sizeof(cbootpath) - 1);
174 1.1 garbled
175 1.1 garbled /*
176 1.1 garbled * OF_1.x (at least) always returns addr == 0 for
177 1.1 garbled * SCSI disks (i.e. "/bandit (at) .../.../sd@0,0").
178 1.20 macallan * also check for .../disk@ which some Adaptec firmware uses
179 1.1 garbled */
180 1.1 garbled lastp = strrchr(cbootpath, '/');
181 1.1 garbled if (lastp != NULL) {
182 1.1 garbled lastp++;
183 1.20 macallan if ((strncmp(lastp, "sd@", 3) == 0
184 1.20 macallan && strncmp(last, "sd@", 3) == 0) ||
185 1.20 macallan (strncmp(lastp, "disk@", 5) == 0
186 1.20 macallan && strncmp(last, "disk@", 5) == 0))
187 1.1 garbled strcpy(lastp, last);
188 1.1 garbled } else {
189 1.1 garbled lastp = cbootpath;
190 1.1 garbled }
191 1.1 garbled
192 1.1 garbled /*
193 1.1 garbled * At this point, cbootpath contains like:
194 1.1 garbled * "/pci@80000000/mac-io@10/ata-3@20000/disk"
195 1.1 garbled *
196 1.1 garbled * The last component may have no address... so append it.
197 1.1 garbled */
198 1.1 garbled if (strchr(lastp, '@') == NULL) {
199 1.1 garbled /* Append it. */
200 1.1 garbled if ((p = strrchr(last, '@')) != NULL)
201 1.1 garbled strcat(cbootpath, p);
202 1.1 garbled }
203 1.1 garbled
204 1.1 garbled if ((p = strrchr(lastp, ':')) != NULL) {
205 1.1 garbled *p++ = '\0';
206 1.1 garbled /* booted_partition = *p - '0'; XXX correct? */
207 1.1 garbled }
208 1.1 garbled }
209 1.1 garbled
210 1.1 garbled /*
211 1.1 garbled * device_register is called from config_attach as each device is
212 1.1 garbled * attached. We use it to find the NetBSD device corresponding to the
213 1.1 garbled * known OF boot device.
214 1.1 garbled */
215 1.1 garbled void
216 1.13 matt device_register(device_t dev, void *aux)
217 1.1 garbled {
218 1.13 matt static device_t parent;
219 1.1 garbled static char *bp = bootpath + 1, *cp = cbootpath;
220 1.7 mrg unsigned long addr, addr2;
221 1.1 garbled char *p;
222 1.12 kiyohara #if NGTPCI > 0
223 1.12 kiyohara struct powerpc_bus_space *gtpci_mem_bs_tag = NULL;
224 1.12 kiyohara #endif
225 1.1 garbled
226 1.1 garbled /* Skip over devices not represented in the OF tree. */
227 1.1 garbled if (device_is_a(dev, "mainbus")) {
228 1.1 garbled parent = dev;
229 1.1 garbled return;
230 1.1 garbled }
231 1.16 macallan
232 1.16 macallan if (device_is_a(dev, "valkyriefb")) {
233 1.16 macallan struct confargs *ca = aux;
234 1.16 macallan prop_dictionary_t dict;
235 1.16 macallan
236 1.16 macallan dict = device_properties(dev);
237 1.16 macallan copy_disp_props(dev, ca->ca_node, dict);
238 1.16 macallan }
239 1.16 macallan
240 1.12 kiyohara #if NGTPCI > 0
241 1.12 kiyohara if (device_is_a(dev, "gtpci")) {
242 1.12 kiyohara extern struct gtpci_prot gtpci0_prot, gtpci1_prot;
243 1.12 kiyohara extern struct powerpc_bus_space
244 1.12 kiyohara gtpci0_io_bs_tag, gtpci0_mem_bs_tag,
245 1.12 kiyohara gtpci1_io_bs_tag, gtpci1_mem_bs_tag;
246 1.12 kiyohara extern struct genppc_pci_chipset
247 1.12 kiyohara genppc_gtpci0_chipset, genppc_gtpci1_chipset;
248 1.12 kiyohara
249 1.12 kiyohara struct marvell_attach_args *mva = aux;
250 1.12 kiyohara struct gtpci_prot *gtpci_prot;
251 1.12 kiyohara struct powerpc_bus_space *gtpci_io_bs_tag;
252 1.12 kiyohara struct genppc_pci_chipset *genppc_gtpci_chipset;
253 1.12 kiyohara prop_dictionary_t dict = device_properties(dev);
254 1.12 kiyohara prop_data_t prot, io_bs_tag, mem_bs_tag, pc;
255 1.12 kiyohara int iostart, ioend;
256 1.12 kiyohara
257 1.12 kiyohara if (mva->mva_unit == 0) {
258 1.12 kiyohara gtpci_prot = >pci0_prot;
259 1.12 kiyohara gtpci_io_bs_tag = >pci0_io_bs_tag;
260 1.12 kiyohara gtpci_mem_bs_tag = >pci0_mem_bs_tag;
261 1.12 kiyohara genppc_gtpci_chipset = &genppc_gtpci0_chipset;
262 1.12 kiyohara iostart = 0;
263 1.12 kiyohara ioend = 0;
264 1.12 kiyohara } else {
265 1.12 kiyohara gtpci_prot = >pci1_prot;
266 1.12 kiyohara gtpci_io_bs_tag = >pci1_io_bs_tag;
267 1.12 kiyohara gtpci_mem_bs_tag = >pci1_mem_bs_tag;
268 1.12 kiyohara genppc_gtpci_chipset = &genppc_gtpci1_chipset;
269 1.12 kiyohara iostart = 0x1400;
270 1.12 kiyohara ioend = 0xffff;
271 1.12 kiyohara }
272 1.12 kiyohara
273 1.12 kiyohara prot = prop_data_create_data_nocopy(
274 1.12 kiyohara gtpci_prot, sizeof(struct gtpci_prot));
275 1.12 kiyohara KASSERT(prot != NULL);
276 1.12 kiyohara prop_dictionary_set(dict, "prot", prot);
277 1.12 kiyohara prop_object_release(prot);
278 1.12 kiyohara
279 1.12 kiyohara io_bs_tag = prop_data_create_data_nocopy(
280 1.12 kiyohara gtpci_io_bs_tag, sizeof(struct powerpc_bus_space));
281 1.12 kiyohara KASSERT(io_bs_tag != NULL);
282 1.12 kiyohara prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
283 1.12 kiyohara prop_object_release(io_bs_tag);
284 1.12 kiyohara mem_bs_tag = prop_data_create_data_nocopy(
285 1.12 kiyohara gtpci_mem_bs_tag, sizeof(struct powerpc_bus_space));
286 1.12 kiyohara KASSERT(mem_bs_tag != NULL);
287 1.12 kiyohara prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
288 1.12 kiyohara prop_object_release(mem_bs_tag);
289 1.12 kiyohara
290 1.12 kiyohara genppc_gtpci_chipset->pc_conf_v = device_private(dev);
291 1.12 kiyohara pc = prop_data_create_data_nocopy(genppc_gtpci_chipset,
292 1.12 kiyohara sizeof(struct genppc_pci_chipset));
293 1.12 kiyohara KASSERT(pc != NULL);
294 1.12 kiyohara prop_dictionary_set(dict, "pci-chipset", pc);
295 1.12 kiyohara prop_object_release(pc);
296 1.12 kiyohara
297 1.12 kiyohara prop_dictionary_set_uint64(dict, "iostart", iostart);
298 1.12 kiyohara prop_dictionary_set_uint64(dict, "ioend", ioend);
299 1.12 kiyohara prop_dictionary_set_uint64(dict, "memstart",
300 1.12 kiyohara gtpci_mem_bs_tag->pbs_base);
301 1.12 kiyohara prop_dictionary_set_uint64(dict, "memend",
302 1.12 kiyohara gtpci_mem_bs_tag->pbs_limit - 1);
303 1.12 kiyohara prop_dictionary_set_uint32(dict, "cache-line-size",
304 1.12 kiyohara CACHELINESIZE);
305 1.12 kiyohara }
306 1.12 kiyohara #endif
307 1.1 garbled if (device_is_a(dev, "atapibus") || device_is_a(dev, "pci") ||
308 1.1 garbled device_is_a(dev, "scsibus") || device_is_a(dev, "atabus"))
309 1.1 garbled return;
310 1.1 garbled
311 1.1 garbled if (device_is_a(device_parent(dev), "pci")) {
312 1.1 garbled struct pci_attach_args *pa = aux;
313 1.1 garbled prop_dictionary_t dict;
314 1.5 phx prop_bool_t b;
315 1.3 garbled int node;
316 1.3 garbled char name[32];
317 1.1 garbled
318 1.1 garbled dict = device_properties(dev);
319 1.1 garbled node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
320 1.1 garbled
321 1.5 phx /* enable configuration of irq 14/15 for VIA native IDE */
322 1.5 phx if (device_is_a(dev, "viaide") &&
323 1.5 phx strncmp(model_name, "Pegasos", 7) == 0) {
324 1.5 phx b = prop_bool_create(true);
325 1.5 phx KASSERT(b != NULL);
326 1.5 phx (void)prop_dictionary_set(dict,
327 1.5 phx "use-compat-native-irq", b);
328 1.5 phx prop_object_release(b);
329 1.5 phx }
330 1.5 phx
331 1.4 macallan if (node != 0) {
332 1.6 aymeric int pci_class = 0;
333 1.6 aymeric
334 1.3 garbled prop_dictionary_set_uint32(dict, "device_node", node);
335 1.1 garbled
336 1.5 phx /* see if this is going to be console */
337 1.3 garbled memset(name, 0, sizeof(name));
338 1.3 garbled OF_getprop(node, "device_type", name, sizeof(name));
339 1.6 aymeric
340 1.6 aymeric OF_getprop(node, "class-code", &pci_class,
341 1.6 aymeric sizeof pci_class);
342 1.6 aymeric pci_class = (pci_class >> 16) & 0xff;
343 1.6 aymeric
344 1.6 aymeric if (strcmp(name, "display") == 0 ||
345 1.8 macallan strcmp(name, "ATY,DDParent") == 0 ||
346 1.8 macallan pci_class == PCI_CLASS_DISPLAY) {
347 1.3 garbled /* setup display properties for fb driver */
348 1.3 garbled prop_dictionary_set_bool(dict, "is_console", 0);
349 1.3 garbled copy_disp_props(dev, node, dict);
350 1.1 garbled }
351 1.11 macallan if (pci_class == PCI_CLASS_NETWORK) {
352 1.11 macallan of_to_dataprop(dict, node, "local-mac-address",
353 1.11 macallan "mac-address");
354 1.11 macallan of_to_dataprop(dict, node, "shared-pins",
355 1.11 macallan "shared-pins");
356 1.11 macallan }
357 1.1 garbled }
358 1.18 macallan #ifdef macppc
359 1.18 macallan /*
360 1.18 macallan * XXX
361 1.18 macallan * some macppc boxes have onboard devices where parts or all of
362 1.18 macallan * the PCI_INTERRUPT register are hardwired to 0
363 1.18 macallan */
364 1.18 macallan if (pa->pa_intrpin == 0)
365 1.18 macallan pa->pa_intrpin = 1;
366 1.18 macallan #endif
367 1.3 garbled }
368 1.1 garbled
369 1.3 garbled if (booted_device)
370 1.3 garbled return;
371 1.1 garbled
372 1.7 mrg /*
373 1.7 mrg * Skip over devices that are really just layers of NetBSD
374 1.7 mrg * autoconf(9) we should just skip as they do not have any
375 1.7 mrg * OFW devices.
376 1.7 mrg */
377 1.1 garbled if (device_is_a(device_parent(dev), "atapibus") ||
378 1.1 garbled device_is_a(device_parent(dev), "atabus") ||
379 1.1 garbled device_is_a(device_parent(dev), "pci") ||
380 1.1 garbled device_is_a(device_parent(dev), "scsibus")) {
381 1.1 garbled if (device_parent(device_parent(dev)) != parent)
382 1.1 garbled return;
383 1.1 garbled } else {
384 1.1 garbled if (device_parent(dev) != parent)
385 1.1 garbled return;
386 1.1 garbled }
387 1.1 garbled
388 1.7 mrg /*
389 1.7 mrg * Get the address part of the current path component. The
390 1.1 garbled * last component of the canonical bootpath may have no
391 1.1 garbled * address (eg, "disk"), in which case we need to get the
392 1.1 garbled * address from the original bootpath instead.
393 1.1 garbled */
394 1.1 garbled p = strchr(cp, '@');
395 1.1 garbled if (!p) {
396 1.1 garbled if (bp)
397 1.1 garbled p = strchr(bp, '@');
398 1.1 garbled if (!p)
399 1.1 garbled addr = 0;
400 1.7 mrg else
401 1.7 mrg addr = strtoul(p + 1, &p, 16);
402 1.1 garbled } else
403 1.1 garbled addr = strtoul(p + 1, &p, 16);
404 1.1 garbled
405 1.7 mrg /* if the current path has more address, grab that too */
406 1.7 mrg if (p && *p == ',')
407 1.7 mrg addr2 = strtoul(p + 1, &p, 16);
408 1.7 mrg else
409 1.7 mrg addr2 = 0;
410 1.7 mrg
411 1.1 garbled if (device_is_a(device_parent(dev), "mainbus")) {
412 1.1 garbled struct confargs *ca = aux;
413 1.1 garbled
414 1.1 garbled if (strcmp(ca->ca_name, "ofw") == 0) /* XXX */
415 1.1 garbled return;
416 1.12 kiyohara if (strcmp(ca->ca_name, "gt") == 0)
417 1.12 kiyohara parent = dev;
418 1.1 garbled if (addr != ca->ca_reg[0])
419 1.1 garbled return;
420 1.12 kiyohara } else if (device_is_a(device_parent(dev), "gt")) {
421 1.12 kiyohara /*
422 1.12 kiyohara * Special handle for MV64361 on PegasosII(ofppc).
423 1.12 kiyohara */
424 1.12 kiyohara if (device_is_a(dev, "mvgbec")) {
425 1.12 kiyohara /*
426 1.12 kiyohara * Fix cp to /port@N from /ethernet/portN. (N is 0...2)
427 1.12 kiyohara */
428 1.12 kiyohara static char fix_cp[8] = "/port@N";
429 1.12 kiyohara
430 1.12 kiyohara if (strlen(cp) != 15 ||
431 1.12 kiyohara strncmp(cp, "/ethernet/port", 14) != 0)
432 1.12 kiyohara return;
433 1.12 kiyohara fix_cp[7] = *(cp + 15);
434 1.12 kiyohara p = fix_cp;
435 1.12 kiyohara #if NGTPCI > 0
436 1.12 kiyohara } else if (device_is_a(dev, "gtpci")) {
437 1.12 kiyohara if (gtpci_mem_bs_tag != NULL &&
438 1.12 kiyohara addr != gtpci_mem_bs_tag->pbs_base)
439 1.12 kiyohara return;
440 1.12 kiyohara #endif
441 1.12 kiyohara } else
442 1.12 kiyohara return;
443 1.1 garbled } else if (device_is_a(device_parent(dev), "pci")) {
444 1.1 garbled struct pci_attach_args *pa = aux;
445 1.1 garbled
446 1.7 mrg if (addr != pa->pa_device ||
447 1.7 mrg addr2 != pa->pa_function)
448 1.1 garbled return;
449 1.1 garbled } else if (device_is_a(device_parent(dev), "obio")) {
450 1.1 garbled struct confargs *ca = aux;
451 1.1 garbled
452 1.1 garbled if (addr != ca->ca_reg[0])
453 1.1 garbled return;
454 1.1 garbled } else if (device_is_a(device_parent(dev), "scsibus") ||
455 1.1 garbled device_is_a(device_parent(dev), "atapibus")) {
456 1.1 garbled struct scsipibus_attach_args *sa = aux;
457 1.1 garbled
458 1.1 garbled /* periph_target is target for scsi, drive # for atapi */
459 1.1 garbled if (addr != sa->sa_periph->periph_target)
460 1.1 garbled return;
461 1.7 mrg } else if (device_is_a(device_parent(device_parent(dev)), "pciide") ||
462 1.7 mrg device_is_a(device_parent(device_parent(dev)), "viaide") ||
463 1.7 mrg device_is_a(device_parent(device_parent(dev)), "slide")) {
464 1.1 garbled struct ata_device *adev = aux;
465 1.1 garbled
466 1.7 mrg if (addr != adev->adev_channel ||
467 1.7 mrg addr2 != adev->adev_drv_data->drive)
468 1.1 garbled return;
469 1.1 garbled } else if (device_is_a(device_parent(device_parent(dev)), "wdc")) {
470 1.1 garbled struct ata_device *adev = aux;
471 1.1 garbled
472 1.1 garbled if (addr != adev->adev_drv_data->drive)
473 1.1 garbled return;
474 1.1 garbled } else
475 1.1 garbled return;
476 1.1 garbled
477 1.1 garbled /* If we reach this point, then dev is a match for the current
478 1.1 garbled * path component.
479 1.1 garbled */
480 1.1 garbled
481 1.1 garbled if (p && *p) {
482 1.1 garbled parent = dev;
483 1.1 garbled cp = p;
484 1.1 garbled bp = strchr(bp, '/');
485 1.1 garbled if (bp)
486 1.1 garbled bp++;
487 1.1 garbled return;
488 1.1 garbled } else {
489 1.1 garbled booted_device = dev;
490 1.1 garbled booted_partition = 0; /* XXX -- should be extracted from bootpath */
491 1.1 garbled return;
492 1.1 garbled }
493 1.1 garbled }
494 1.1 garbled
495 1.1 garbled /*
496 1.1 garbled * Setup root device.
497 1.1 garbled * Configure swap area.
498 1.1 garbled */
499 1.1 garbled void
500 1.10 cegger cpu_rootconf(void)
501 1.1 garbled {
502 1.1 garbled printf("boot device: %s\n",
503 1.13 matt booted_device ? device_xname(booted_device) : "<unknown>");
504 1.1 garbled
505 1.17 mlelstv rootconf();
506 1.1 garbled }
507 1.1 garbled
508 1.1 garbled /*
509 1.1 garbled * Find OF-device corresponding to the PCI device.
510 1.1 garbled */
511 1.1 garbled int
512 1.1 garbled pcidev_to_ofdev(pci_chipset_tag_t pc, pcitag_t tag)
513 1.1 garbled {
514 1.1 garbled int bus, dev, func;
515 1.1 garbled u_int reg[5];
516 1.1 garbled int p, q;
517 1.1 garbled int l, b, d, f;
518 1.1 garbled
519 1.1 garbled pci_decompose_tag(pc, tag, &bus, &dev, &func);
520 1.1 garbled
521 1.1 garbled for (q = OF_peer(0); q; q = p) {
522 1.1 garbled l = OF_getprop(q, "assigned-addresses", reg, sizeof(reg));
523 1.1 garbled if (l > 4) {
524 1.1 garbled b = (reg[0] >> 16) & 0xff;
525 1.1 garbled d = (reg[0] >> 11) & 0x1f;
526 1.1 garbled f = (reg[0] >> 8) & 0x07;
527 1.1 garbled
528 1.1 garbled if (b == bus && d == dev && f == func)
529 1.1 garbled return q;
530 1.1 garbled }
531 1.1 garbled if ((p = OF_child(q)))
532 1.1 garbled continue;
533 1.1 garbled while (q) {
534 1.1 garbled if ((p = OF_peer(q)))
535 1.1 garbled break;
536 1.1 garbled q = OF_parent(q);
537 1.1 garbled }
538 1.1 garbled }
539 1.1 garbled return 0;
540 1.1 garbled }
541