1 /* $NetBSD: autoconf.c,v 1.4 2026/06/22 12:34:19 rkujawa Exp $ */ 2 3 /* 4 * Copyright (c) 2012, 2014, 2024, 2026 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Radoslaw Kujawa. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 /* 32 * Copyright 2004 Shigeyuki Fukushima. 33 * All rights reserved. 34 * 35 * Written by Shigeyuki Fukushima for The NetBSD Project. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above 43 * copyright notice, this list of conditions and the following 44 * disclaimer in the documentation and/or other materials provided 45 * with the distribution. 46 * 3. The name of the author may not be used to endorse or promote 47 * products derived from this software without specific prior 48 * written permission. 49 * 50 * THIS SOFTWARE IS PROVIDED THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 51 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 52 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 53 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE 54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 55 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 56 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 57 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 58 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 60 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 61 * DAMAGE. 62 */ 63 64 /* 65 * Autoconfiguration for the ACube Sam460ex (AMCC 460EX). 66 * Modeled on evbppc/obs405/obs600_autoconf.c. 67 */ 68 69 #include <sys/cdefs.h> 70 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.4 2026/06/22 12:34:19 rkujawa Exp $"); 71 72 #include <sys/param.h> 73 #include <sys/device.h> 74 #include <sys/disklabel.h> 75 #include <sys/intr.h> 76 #include <sys/systm.h> 77 78 #include <machine/sam460ex.h> 79 80 #include <powerpc/ibm4xx/amcc460ex.h> 81 #include <powerpc/ibm4xx/cpu.h> 82 #include <powerpc/ibm4xx/dcr4xx.h> 83 #include <powerpc/ibm4xx/pci_machdep.h> 84 85 #include <dev/pci/pcivar.h> 86 #include <dev/pci/pcireg.h> 87 #include <dev/pci/pcidevs.h> 88 89 /* 90 * PCIe INTx routing 91 */ 92 int 93 pciex_inta_irq(int port) 94 { 95 96 return 0x60 + port * 0x6; 97 } 98 99 /* Set once console=pci has made a PCI display the console (see below). */ 100 static bool sam460ex_pci_console_found; 101 102 /* 103 * Determine device configuration for a machine. 104 */ 105 void 106 cpu_configure(void) 107 { 108 109 /* UIC */ 110 mtdcr(DCR_UIC1_BASE + DCR_UIC_PR, 111 mfdcr(DCR_UIC1_BASE + DCR_UIC_PR) & ~0x80000000); 112 mtdcr(DCR_UIC1_BASE + DCR_UIC_TR, 113 mfdcr(DCR_UIC1_BASE + DCR_UIC_TR) & ~0x80000000); 114 mtdcr(DCR_UIC1_BASE + DCR_UIC_SR, 0x80000000); 115 mtdcr(DCR_UIC3_BASE + DCR_UIC_PR, 116 mfdcr(DCR_UIC3_BASE + DCR_UIC_PR) & ~0x000ff000); 117 mtdcr(DCR_UIC3_BASE + DCR_UIC_TR, 118 mfdcr(DCR_UIC3_BASE + DCR_UIC_TR) & ~0x000ff000); 119 mtdcr(DCR_UIC3_BASE + DCR_UIC_SR, 0x000ff000); 120 121 /* 122 * Initialize intr and add the cascaded UICs. 123 * UIC0 = 0, UIC1 = +32, UIC2 = +64, UIC3 = +96. 124 */ 125 intr_init(); 126 pic_add(&pic_uic1); 127 pic_add(&pic_uic2); 128 pic_add(&pic_uic3); 129 130 if (config_rootfound("plb", NULL) == NULL) 131 panic("configure: mainbus not configured"); 132 133 if (sam460ex_console == SAM460EX_CONS_PCI && !sam460ex_pci_console_found) 134 printf("sam460ex: console=pci: no suitable PCI display found, " 135 "using serial\n"); 136 137 pic_finish_setup(); 138 139 genppc_cpu_configure(); 140 } 141 142 void 143 device_register(device_t dev, void *aux) 144 { 145 146 ibm4xx_device_register(dev, aux, sam460ex_com_freq()); 147 148 /* console=sm502: the on-board SM502 voyagerfb becomes the console */ 149 if (sam460ex_console == SAM460EX_CONS_SM502 && 150 device_is_a(dev, "voyagerfb")) 151 prop_dictionary_set_bool(device_properties(dev), 152 "is_console", true); 153 154 /* 155 * console=pci: when first non-SM502 PCI display device attaches, make 156 * a console 157 */ 158 if (sam460ex_console == SAM460EX_CONS_PCI && !sam460ex_pci_console_found && 159 device_parent(dev) != NULL && device_is_a(device_parent(dev), "pci")) { 160 struct pci_attach_args *pa = aux; 161 const int *bdf = sam460ex_console_pci_bdf; 162 163 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY && 164 !(PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SILMOTION && 165 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SILMOTION_SM502) && 166 (bdf[0] == -1 || bdf[0] == pa->pa_bus) && 167 (bdf[1] == -1 || bdf[1] == pa->pa_device) && 168 (bdf[2] == -1 || bdf[2] == pa->pa_function)) { 169 aprint_normal("sam460ex: console=pci: selected PCI display " 170 "at %d:%d:%d (vendor 0x%04x product 0x%04x)\n", 171 pa->pa_bus, pa->pa_device, pa->pa_function, 172 PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id)); 173 prop_dictionary_set_bool(device_properties(dev), 174 "is_console", true); 175 sam460ex_pci_console_found = true; 176 } 177 } 178 179 /* 180 * Match a "root=" from the bootargs. 181 */ 182 if (bootspec != NULL) { 183 size_t len = strlen(bootspec); 184 int part = 0; 185 186 if (len > 1 && bootspec[len - 1] >= 'a' && 187 bootspec[len - 1] < 'a' + MAXPARTITIONS && 188 bootspec[len - 2] >= '0' && bootspec[len - 2] <= '9') { 189 part = bootspec[len - 1] - 'a'; 190 len--; 191 } 192 if (strncmp(device_xname(dev), bootspec, len) == 0 && 193 device_xname(dev)[len] == '\0') { 194 booted_device = dev; 195 booted_partition = part; 196 } 197 } 198 } 199 200