1 1.27 thorpej /* $NetBSD: ofw_autoconf.c,v 1.27 2025/09/21 13:51:50 thorpej 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.27 thorpej __KERNEL_RCSID(0, "$NetBSD: ofw_autoconf.c,v 1.27 2025/09/21 13:51:50 thorpej 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.25 macallan #include <dev/wscons/wsconsio.h> 65 1.25 macallan #include <dev/wscons/wsdisplayvar.h> 66 1.25 macallan #include <dev/rasops/rasops.h> 67 1.25 macallan #include <powerpc/oea/ofw_rasconsvar.h> 68 1.27 thorpej #include <powerpc/ofw_machdep.h> 69 1.25 macallan 70 1.12 kiyohara #include <machine/pci_machdep.h> 71 1.12 kiyohara 72 1.12 kiyohara #include <prop/proplib.h> 73 1.12 kiyohara 74 1.1 garbled extern char bootpath[256]; 75 1.1 garbled char cbootpath[256]; 76 1.21 macallan static int boot_node = 0; /* points at boot device if we netboot */ 77 1.1 garbled 78 1.1 garbled static void canonicalize_bootpath(void); 79 1.1 garbled 80 1.1 garbled /* 81 1.1 garbled * Determine device configuration for a machine. 82 1.1 garbled */ 83 1.1 garbled void 84 1.1 garbled cpu_configure(void) 85 1.1 garbled { 86 1.26 andvar #if NWSDISPLAY > 0 87 1.25 macallan rascons_add_rom_font(); 88 1.26 andvar #endif 89 1.1 garbled init_interrupt(); 90 1.1 garbled canonicalize_bootpath(); 91 1.1 garbled 92 1.1 garbled if (config_rootfound("mainbus", NULL) == NULL) 93 1.1 garbled panic("configure: mainbus not configured"); 94 1.1 garbled 95 1.1 garbled genppc_cpu_configure(); 96 1.1 garbled } 97 1.1 garbled 98 1.1 garbled static void 99 1.1 garbled canonicalize_bootpath(void) 100 1.1 garbled { 101 1.21 macallan int node, len; 102 1.1 garbled char *p, *lastp; 103 1.21 macallan char last[32], type[32]; 104 1.1 garbled 105 1.1 garbled /* 106 1.1 garbled * If the bootpath doesn't start with a / then it isn't 107 1.1 garbled * an OFW path and probably is an alias, so look up the alias 108 1.1 garbled * and regenerate the full bootpath so device_register will work. 109 1.1 garbled */ 110 1.1 garbled if (bootpath[0] != '/' && bootpath[0] != '\0') { 111 1.1 garbled int aliases = OF_finddevice("/aliases"); 112 1.1 garbled char tmpbuf[100]; 113 1.1 garbled char aliasbuf[256]; 114 1.1 garbled if (aliases != 0) { 115 1.1 garbled char *cp1, *cp2, *cp; 116 1.1 garbled char saved_ch = '\0'; 117 1.1 garbled cp1 = strchr(bootpath, ':'); 118 1.1 garbled cp2 = strchr(bootpath, ','); 119 1.1 garbled cp = cp1; 120 1.1 garbled if (cp1 == NULL || (cp2 != NULL && cp2 < cp1)) 121 1.1 garbled cp = cp2; 122 1.1 garbled tmpbuf[0] = '\0'; 123 1.1 garbled if (cp != NULL) { 124 1.1 garbled strcpy(tmpbuf, cp); 125 1.1 garbled saved_ch = *cp; 126 1.1 garbled *cp = '\0'; 127 1.1 garbled } 128 1.1 garbled len = OF_getprop(aliases, bootpath, aliasbuf, 129 1.1 garbled sizeof(aliasbuf)); 130 1.1 garbled if (len > 0) { 131 1.1 garbled if (aliasbuf[len-1] == '\0') 132 1.1 garbled len--; 133 1.1 garbled memcpy(bootpath, aliasbuf, len); 134 1.1 garbled strcpy(&bootpath[len], tmpbuf); 135 1.1 garbled } else { 136 1.1 garbled *cp = saved_ch; 137 1.1 garbled } 138 1.1 garbled } 139 1.1 garbled } 140 1.1 garbled 141 1.1 garbled /* 142 1.1 garbled * Strip kernel name. bootpath contains "OF-path"/"kernel". 143 1.1 garbled * 144 1.1 garbled * for example: 145 1.1 garbled * /bandit@F2000000/gc@10/53c94@10000/sd@0,0/netbsd (OF-1.x) 146 1.1 garbled * /pci/mac-io/ata-3@2000/disk@0:0/netbsd.new (OF-3.x) 147 1.1 garbled */ 148 1.1 garbled strcpy(cbootpath, bootpath); 149 1.24 joerg 150 1.24 joerg if ((node = OF_finddevice("/options")) == -1 || 151 1.24 joerg OF_getprop(node, "qemu_boot_hack", type, sizeof(type) - 1) == -1 || 152 1.24 joerg type[0] != 'y') { 153 1.24 joerg while ((node = OF_finddevice(cbootpath)) == -1) { 154 1.24 joerg if ((p = strrchr(cbootpath, '/')) == NULL) 155 1.24 joerg break; 156 1.24 joerg *p = '\0'; 157 1.24 joerg } 158 1.24 joerg } else { 159 1.24 joerg node = -1; 160 1.1 garbled } 161 1.1 garbled 162 1.7 mrg printf("bootpath: %s\n", bootpath); 163 1.1 garbled if (node == -1) { 164 1.1 garbled /* Cannot canonicalize... use bootpath anyway. */ 165 1.1 garbled strcpy(cbootpath, bootpath); 166 1.1 garbled 167 1.1 garbled return; 168 1.1 garbled } 169 1.1 garbled 170 1.21 macallan /* see if we netbooted */ 171 1.21 macallan len = OF_getprop(node, "device_type", type, sizeof(type) - 1); 172 1.21 macallan if (len > -1) { 173 1.21 macallan type[len] = 0; 174 1.21 macallan if (strcmp(type, "network") == 0) { 175 1.21 macallan boot_node = node; 176 1.21 macallan } 177 1.21 macallan } 178 1.21 macallan 179 1.1 garbled /* 180 1.1 garbled * cbootpath is a valid OF path. Use package-to-path to 181 1.1 garbled * canonicalize pathname. 182 1.1 garbled */ 183 1.1 garbled 184 1.1 garbled /* Back up the last component for later use. */ 185 1.1 garbled if ((p = strrchr(cbootpath, '/')) != NULL) 186 1.1 garbled strcpy(last, p + 1); 187 1.1 garbled else 188 1.1 garbled last[0] = '\0'; 189 1.1 garbled 190 1.1 garbled memset(cbootpath, 0, sizeof(cbootpath)); 191 1.1 garbled OF_package_to_path(node, cbootpath, sizeof(cbootpath) - 1); 192 1.1 garbled 193 1.1 garbled /* 194 1.1 garbled * OF_1.x (at least) always returns addr == 0 for 195 1.1 garbled * SCSI disks (i.e. "/bandit (at) .../.../sd@0,0"). 196 1.20 macallan * also check for .../disk@ which some Adaptec firmware uses 197 1.1 garbled */ 198 1.1 garbled lastp = strrchr(cbootpath, '/'); 199 1.1 garbled if (lastp != NULL) { 200 1.1 garbled lastp++; 201 1.20 macallan if ((strncmp(lastp, "sd@", 3) == 0 202 1.20 macallan && strncmp(last, "sd@", 3) == 0) || 203 1.20 macallan (strncmp(lastp, "disk@", 5) == 0 204 1.20 macallan && strncmp(last, "disk@", 5) == 0)) 205 1.1 garbled strcpy(lastp, last); 206 1.1 garbled } else { 207 1.1 garbled lastp = cbootpath; 208 1.1 garbled } 209 1.1 garbled 210 1.1 garbled /* 211 1.1 garbled * At this point, cbootpath contains like: 212 1.1 garbled * "/pci@80000000/mac-io@10/ata-3@20000/disk" 213 1.1 garbled * 214 1.1 garbled * The last component may have no address... so append it. 215 1.1 garbled */ 216 1.1 garbled if (strchr(lastp, '@') == NULL) { 217 1.1 garbled /* Append it. */ 218 1.1 garbled if ((p = strrchr(last, '@')) != NULL) 219 1.1 garbled strcat(cbootpath, p); 220 1.1 garbled } 221 1.1 garbled 222 1.1 garbled if ((p = strrchr(lastp, ':')) != NULL) { 223 1.1 garbled *p++ = '\0'; 224 1.1 garbled /* booted_partition = *p - '0'; XXX correct? */ 225 1.1 garbled } 226 1.1 garbled } 227 1.1 garbled 228 1.1 garbled /* 229 1.1 garbled * device_register is called from config_attach as each device is 230 1.1 garbled * attached. We use it to find the NetBSD device corresponding to the 231 1.1 garbled * known OF boot device. 232 1.1 garbled */ 233 1.1 garbled void 234 1.27 thorpej ofw_device_register(device_t dev, void *aux) 235 1.1 garbled { 236 1.13 matt static device_t parent; 237 1.1 garbled static char *bp = bootpath + 1, *cp = cbootpath; 238 1.7 mrg unsigned long addr, addr2; 239 1.1 garbled char *p; 240 1.12 kiyohara #if NGTPCI > 0 241 1.12 kiyohara struct powerpc_bus_space *gtpci_mem_bs_tag = NULL; 242 1.12 kiyohara #endif 243 1.1 garbled 244 1.1 garbled /* Skip over devices not represented in the OF tree. */ 245 1.1 garbled if (device_is_a(dev, "mainbus")) { 246 1.1 garbled parent = dev; 247 1.1 garbled return; 248 1.1 garbled } 249 1.16 macallan 250 1.22 macallan /* skip over CPUs */ 251 1.22 macallan if (device_is_a(dev, "cpu")) { 252 1.22 macallan return; 253 1.22 macallan } 254 1.22 macallan 255 1.16 macallan if (device_is_a(dev, "valkyriefb")) { 256 1.16 macallan struct confargs *ca = aux; 257 1.16 macallan prop_dictionary_t dict; 258 1.16 macallan 259 1.16 macallan dict = device_properties(dev); 260 1.16 macallan copy_disp_props(dev, ca->ca_node, dict); 261 1.16 macallan } 262 1.16 macallan 263 1.23 scole /* cannot read useful display properties for platinum */ 264 1.23 scole if (device_is_a(dev, "platinumfb")) { 265 1.23 scole return; 266 1.23 scole } 267 1.23 scole 268 1.12 kiyohara #if NGTPCI > 0 269 1.12 kiyohara if (device_is_a(dev, "gtpci")) { 270 1.12 kiyohara extern struct gtpci_prot gtpci0_prot, gtpci1_prot; 271 1.12 kiyohara extern struct powerpc_bus_space 272 1.12 kiyohara gtpci0_io_bs_tag, gtpci0_mem_bs_tag, 273 1.12 kiyohara gtpci1_io_bs_tag, gtpci1_mem_bs_tag; 274 1.12 kiyohara extern struct genppc_pci_chipset 275 1.12 kiyohara genppc_gtpci0_chipset, genppc_gtpci1_chipset; 276 1.12 kiyohara 277 1.12 kiyohara struct marvell_attach_args *mva = aux; 278 1.12 kiyohara struct gtpci_prot *gtpci_prot; 279 1.12 kiyohara struct powerpc_bus_space *gtpci_io_bs_tag; 280 1.12 kiyohara struct genppc_pci_chipset *genppc_gtpci_chipset; 281 1.12 kiyohara prop_dictionary_t dict = device_properties(dev); 282 1.12 kiyohara prop_data_t prot, io_bs_tag, mem_bs_tag, pc; 283 1.12 kiyohara int iostart, ioend; 284 1.12 kiyohara 285 1.12 kiyohara if (mva->mva_unit == 0) { 286 1.12 kiyohara gtpci_prot = >pci0_prot; 287 1.12 kiyohara gtpci_io_bs_tag = >pci0_io_bs_tag; 288 1.12 kiyohara gtpci_mem_bs_tag = >pci0_mem_bs_tag; 289 1.12 kiyohara genppc_gtpci_chipset = &genppc_gtpci0_chipset; 290 1.12 kiyohara iostart = 0; 291 1.12 kiyohara ioend = 0; 292 1.12 kiyohara } else { 293 1.12 kiyohara gtpci_prot = >pci1_prot; 294 1.12 kiyohara gtpci_io_bs_tag = >pci1_io_bs_tag; 295 1.12 kiyohara gtpci_mem_bs_tag = >pci1_mem_bs_tag; 296 1.12 kiyohara genppc_gtpci_chipset = &genppc_gtpci1_chipset; 297 1.12 kiyohara iostart = 0x1400; 298 1.12 kiyohara ioend = 0xffff; 299 1.12 kiyohara } 300 1.12 kiyohara 301 1.12 kiyohara prot = prop_data_create_data_nocopy( 302 1.12 kiyohara gtpci_prot, sizeof(struct gtpci_prot)); 303 1.12 kiyohara KASSERT(prot != NULL); 304 1.12 kiyohara prop_dictionary_set(dict, "prot", prot); 305 1.12 kiyohara prop_object_release(prot); 306 1.12 kiyohara 307 1.12 kiyohara io_bs_tag = prop_data_create_data_nocopy( 308 1.12 kiyohara gtpci_io_bs_tag, sizeof(struct powerpc_bus_space)); 309 1.12 kiyohara KASSERT(io_bs_tag != NULL); 310 1.12 kiyohara prop_dictionary_set(dict, "io-bus-tag", io_bs_tag); 311 1.12 kiyohara prop_object_release(io_bs_tag); 312 1.12 kiyohara mem_bs_tag = prop_data_create_data_nocopy( 313 1.12 kiyohara gtpci_mem_bs_tag, sizeof(struct powerpc_bus_space)); 314 1.12 kiyohara KASSERT(mem_bs_tag != NULL); 315 1.12 kiyohara prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag); 316 1.12 kiyohara prop_object_release(mem_bs_tag); 317 1.12 kiyohara 318 1.12 kiyohara genppc_gtpci_chipset->pc_conf_v = device_private(dev); 319 1.12 kiyohara pc = prop_data_create_data_nocopy(genppc_gtpci_chipset, 320 1.12 kiyohara sizeof(struct genppc_pci_chipset)); 321 1.12 kiyohara KASSERT(pc != NULL); 322 1.12 kiyohara prop_dictionary_set(dict, "pci-chipset", pc); 323 1.12 kiyohara prop_object_release(pc); 324 1.12 kiyohara 325 1.12 kiyohara prop_dictionary_set_uint64(dict, "iostart", iostart); 326 1.12 kiyohara prop_dictionary_set_uint64(dict, "ioend", ioend); 327 1.12 kiyohara prop_dictionary_set_uint64(dict, "memstart", 328 1.12 kiyohara gtpci_mem_bs_tag->pbs_base); 329 1.12 kiyohara prop_dictionary_set_uint64(dict, "memend", 330 1.12 kiyohara gtpci_mem_bs_tag->pbs_limit - 1); 331 1.12 kiyohara prop_dictionary_set_uint32(dict, "cache-line-size", 332 1.12 kiyohara CACHELINESIZE); 333 1.12 kiyohara } 334 1.12 kiyohara #endif 335 1.22 macallan if (device_is_a(dev, "atapibus") || 336 1.22 macallan #ifndef PMAC_G5 337 1.22 macallan device_is_a(dev, "pci") || 338 1.22 macallan #endif 339 1.1 garbled device_is_a(dev, "scsibus") || device_is_a(dev, "atabus")) 340 1.1 garbled return; 341 1.1 garbled 342 1.1 garbled if (device_is_a(device_parent(dev), "pci")) { 343 1.1 garbled struct pci_attach_args *pa = aux; 344 1.1 garbled prop_dictionary_t dict; 345 1.5 phx prop_bool_t b; 346 1.3 garbled int node; 347 1.3 garbled char name[32]; 348 1.1 garbled 349 1.1 garbled dict = device_properties(dev); 350 1.1 garbled node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag); 351 1.1 garbled 352 1.5 phx /* enable configuration of irq 14/15 for VIA native IDE */ 353 1.5 phx if (device_is_a(dev, "viaide") && 354 1.5 phx strncmp(model_name, "Pegasos", 7) == 0) { 355 1.5 phx b = prop_bool_create(true); 356 1.5 phx KASSERT(b != NULL); 357 1.5 phx (void)prop_dictionary_set(dict, 358 1.5 phx "use-compat-native-irq", b); 359 1.5 phx prop_object_release(b); 360 1.5 phx } 361 1.5 phx 362 1.4 macallan if (node != 0) { 363 1.6 aymeric int pci_class = 0; 364 1.6 aymeric 365 1.3 garbled prop_dictionary_set_uint32(dict, "device_node", node); 366 1.1 garbled 367 1.21 macallan if (node == boot_node) { 368 1.21 macallan /* we netbooted from whatever this is */ 369 1.21 macallan booted_device = dev; 370 1.21 macallan } 371 1.5 phx /* see if this is going to be console */ 372 1.3 garbled memset(name, 0, sizeof(name)); 373 1.3 garbled OF_getprop(node, "device_type", name, sizeof(name)); 374 1.6 aymeric 375 1.6 aymeric OF_getprop(node, "class-code", &pci_class, 376 1.6 aymeric sizeof pci_class); 377 1.6 aymeric pci_class = (pci_class >> 16) & 0xff; 378 1.6 aymeric 379 1.6 aymeric if (strcmp(name, "display") == 0 || 380 1.8 macallan strcmp(name, "ATY,DDParent") == 0 || 381 1.8 macallan pci_class == PCI_CLASS_DISPLAY) { 382 1.3 garbled /* setup display properties for fb driver */ 383 1.3 garbled prop_dictionary_set_bool(dict, "is_console", 0); 384 1.3 garbled copy_disp_props(dev, node, dict); 385 1.1 garbled } 386 1.11 macallan if (pci_class == PCI_CLASS_NETWORK) { 387 1.11 macallan of_to_dataprop(dict, node, "local-mac-address", 388 1.11 macallan "mac-address"); 389 1.11 macallan of_to_dataprop(dict, node, "shared-pins", 390 1.11 macallan "shared-pins"); 391 1.11 macallan } 392 1.1 garbled } 393 1.18 macallan #ifdef macppc 394 1.18 macallan /* 395 1.18 macallan * XXX 396 1.18 macallan * some macppc boxes have onboard devices where parts or all of 397 1.18 macallan * the PCI_INTERRUPT register are hardwired to 0 398 1.18 macallan */ 399 1.18 macallan if (pa->pa_intrpin == 0) 400 1.18 macallan pa->pa_intrpin = 1; 401 1.18 macallan #endif 402 1.3 garbled } 403 1.1 garbled 404 1.3 garbled if (booted_device) 405 1.3 garbled return; 406 1.1 garbled 407 1.7 mrg /* 408 1.7 mrg * Skip over devices that are really just layers of NetBSD 409 1.7 mrg * autoconf(9) we should just skip as they do not have any 410 1.7 mrg * OFW devices. 411 1.22 macallan * XXX except on G5, where we have /ht/pci* instead of /pci* 412 1.7 mrg */ 413 1.1 garbled if (device_is_a(device_parent(dev), "atapibus") || 414 1.1 garbled device_is_a(device_parent(dev), "atabus") || 415 1.22 macallan #ifndef PMAC_G5 416 1.1 garbled device_is_a(device_parent(dev), "pci") || 417 1.22 macallan #endif 418 1.1 garbled device_is_a(device_parent(dev), "scsibus")) { 419 1.22 macallan if (device_parent(device_parent(dev)) != parent) { 420 1.1 garbled return; 421 1.22 macallan } 422 1.1 garbled } else { 423 1.1 garbled if (device_parent(dev) != parent) 424 1.1 garbled return; 425 1.1 garbled } 426 1.1 garbled 427 1.7 mrg /* 428 1.7 mrg * Get the address part of the current path component. The 429 1.1 garbled * last component of the canonical bootpath may have no 430 1.1 garbled * address (eg, "disk"), in which case we need to get the 431 1.1 garbled * address from the original bootpath instead. 432 1.1 garbled */ 433 1.1 garbled p = strchr(cp, '@'); 434 1.1 garbled if (!p) { 435 1.1 garbled if (bp) 436 1.1 garbled p = strchr(bp, '@'); 437 1.1 garbled if (!p) 438 1.1 garbled addr = 0; 439 1.7 mrg else 440 1.7 mrg addr = strtoul(p + 1, &p, 16); 441 1.1 garbled } else 442 1.1 garbled addr = strtoul(p + 1, &p, 16); 443 1.1 garbled 444 1.7 mrg /* if the current path has more address, grab that too */ 445 1.7 mrg if (p && *p == ',') 446 1.7 mrg addr2 = strtoul(p + 1, &p, 16); 447 1.7 mrg else 448 1.7 mrg addr2 = 0; 449 1.7 mrg 450 1.1 garbled if (device_is_a(device_parent(dev), "mainbus")) { 451 1.1 garbled struct confargs *ca = aux; 452 1.1 garbled if (strcmp(ca->ca_name, "ofw") == 0) /* XXX */ 453 1.1 garbled return; 454 1.12 kiyohara if (strcmp(ca->ca_name, "gt") == 0) 455 1.12 kiyohara parent = dev; 456 1.1 garbled if (addr != ca->ca_reg[0]) 457 1.1 garbled return; 458 1.22 macallan if (addr2 != 0 && addr2 != ca->ca_reg[1]) 459 1.22 macallan return; 460 1.12 kiyohara } else if (device_is_a(device_parent(dev), "gt")) { 461 1.12 kiyohara /* 462 1.12 kiyohara * Special handle for MV64361 on PegasosII(ofppc). 463 1.12 kiyohara */ 464 1.12 kiyohara if (device_is_a(dev, "mvgbec")) { 465 1.12 kiyohara /* 466 1.12 kiyohara * Fix cp to /port@N from /ethernet/portN. (N is 0...2) 467 1.12 kiyohara */ 468 1.12 kiyohara static char fix_cp[8] = "/port@N"; 469 1.12 kiyohara 470 1.12 kiyohara if (strlen(cp) != 15 || 471 1.12 kiyohara strncmp(cp, "/ethernet/port", 14) != 0) 472 1.12 kiyohara return; 473 1.12 kiyohara fix_cp[7] = *(cp + 15); 474 1.12 kiyohara p = fix_cp; 475 1.12 kiyohara #if NGTPCI > 0 476 1.12 kiyohara } else if (device_is_a(dev, "gtpci")) { 477 1.12 kiyohara if (gtpci_mem_bs_tag != NULL && 478 1.12 kiyohara addr != gtpci_mem_bs_tag->pbs_base) 479 1.12 kiyohara return; 480 1.12 kiyohara #endif 481 1.12 kiyohara } else 482 1.12 kiyohara return; 483 1.1 garbled } else if (device_is_a(device_parent(dev), "pci")) { 484 1.1 garbled struct pci_attach_args *pa = aux; 485 1.1 garbled 486 1.7 mrg if (addr != pa->pa_device || 487 1.7 mrg addr2 != pa->pa_function) 488 1.1 garbled return; 489 1.1 garbled } else if (device_is_a(device_parent(dev), "obio")) { 490 1.1 garbled struct confargs *ca = aux; 491 1.1 garbled 492 1.1 garbled if (addr != ca->ca_reg[0]) 493 1.1 garbled return; 494 1.1 garbled } else if (device_is_a(device_parent(dev), "scsibus") || 495 1.1 garbled device_is_a(device_parent(dev), "atapibus")) { 496 1.1 garbled struct scsipibus_attach_args *sa = aux; 497 1.1 garbled 498 1.1 garbled /* periph_target is target for scsi, drive # for atapi */ 499 1.1 garbled if (addr != sa->sa_periph->periph_target) 500 1.1 garbled return; 501 1.7 mrg } else if (device_is_a(device_parent(device_parent(dev)), "pciide") || 502 1.7 mrg device_is_a(device_parent(device_parent(dev)), "viaide") || 503 1.7 mrg device_is_a(device_parent(device_parent(dev)), "slide")) { 504 1.1 garbled struct ata_device *adev = aux; 505 1.1 garbled 506 1.7 mrg if (addr != adev->adev_channel || 507 1.7 mrg addr2 != adev->adev_drv_data->drive) 508 1.1 garbled return; 509 1.1 garbled } else if (device_is_a(device_parent(device_parent(dev)), "wdc")) { 510 1.1 garbled struct ata_device *adev = aux; 511 1.1 garbled 512 1.1 garbled if (addr != adev->adev_drv_data->drive) 513 1.1 garbled return; 514 1.22 macallan } else if (device_is_a(dev, "pci")) { 515 1.22 macallan if (addr != device_unit(dev)) 516 1.22 macallan return; 517 1.22 macallan } else if (device_is_a(device_parent(dev), "atabus")) { 518 1.22 macallan /* 519 1.22 macallan * XXX 520 1.22 macallan * on svwsata this is the channel number and we ignore the 521 1.22 macallan * drive number which is always 0 anyway 522 1.22 macallan * needs to be revisited for other (S)ATA cards 523 1.22 macallan */ 524 1.22 macallan struct ata_device *adev = aux; 525 1.22 macallan if (addr != adev->adev_channel) 526 1.22 macallan return; 527 1.22 macallan /* we have our match, cut off the rest */ 528 1.22 macallan if (p) *p = 0; 529 1.1 garbled } else 530 1.1 garbled return; 531 1.1 garbled 532 1.1 garbled /* If we reach this point, then dev is a match for the current 533 1.1 garbled * path component. 534 1.1 garbled */ 535 1.1 garbled if (p && *p) { 536 1.1 garbled parent = dev; 537 1.1 garbled cp = p; 538 1.1 garbled bp = strchr(bp, '/'); 539 1.1 garbled if (bp) 540 1.1 garbled bp++; 541 1.1 garbled return; 542 1.1 garbled } else { 543 1.1 garbled booted_device = dev; 544 1.1 garbled booted_partition = 0; /* XXX -- should be extracted from bootpath */ 545 1.1 garbled return; 546 1.1 garbled } 547 1.1 garbled } 548 1.1 garbled 549 1.1 garbled /* 550 1.1 garbled * Setup root device. 551 1.1 garbled * Configure swap area. 552 1.1 garbled */ 553 1.1 garbled void 554 1.10 cegger cpu_rootconf(void) 555 1.1 garbled { 556 1.1 garbled printf("boot device: %s\n", 557 1.13 matt booted_device ? device_xname(booted_device) : "<unknown>"); 558 1.1 garbled 559 1.17 mlelstv rootconf(); 560 1.1 garbled } 561 1.1 garbled 562 1.1 garbled /* 563 1.1 garbled * Find OF-device corresponding to the PCI device. 564 1.1 garbled */ 565 1.1 garbled int 566 1.1 garbled pcidev_to_ofdev(pci_chipset_tag_t pc, pcitag_t tag) 567 1.1 garbled { 568 1.1 garbled int bus, dev, func; 569 1.1 garbled u_int reg[5]; 570 1.1 garbled int p, q; 571 1.1 garbled int l, b, d, f; 572 1.1 garbled 573 1.1 garbled pci_decompose_tag(pc, tag, &bus, &dev, &func); 574 1.1 garbled 575 1.1 garbled for (q = OF_peer(0); q; q = p) { 576 1.1 garbled l = OF_getprop(q, "assigned-addresses", reg, sizeof(reg)); 577 1.1 garbled if (l > 4) { 578 1.1 garbled b = (reg[0] >> 16) & 0xff; 579 1.1 garbled d = (reg[0] >> 11) & 0x1f; 580 1.1 garbled f = (reg[0] >> 8) & 0x07; 581 1.1 garbled 582 1.1 garbled if (b == bus && d == dev && f == func) 583 1.1 garbled return q; 584 1.1 garbled } 585 1.1 garbled if ((p = OF_child(q))) 586 1.1 garbled continue; 587 1.1 garbled while (q) { 588 1.1 garbled if ((p = OF_peer(q))) 589 1.1 garbled break; 590 1.1 garbled q = OF_parent(q); 591 1.1 garbled } 592 1.1 garbled } 593 1.1 garbled return 0; 594 1.1 garbled } 595