1 /* $NetBSD: autoconf.c,v 1.19 2025/10/03 14:05:12 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1990 The Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * William Jolitz. 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 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)autoconf.c 7.1 (Berkeley) 5/9/91 35 */ 36 37 /* 38 * Setup the system to run on the current machine. 39 * 40 * Configure() is called at boot time and initializes the vba 41 * device tables and the memory controller monitoring. Available 42 * devices are determined (from possibilities mentioned in ioconf.c), 43 * and the drivers are initialized. 44 */ 45 46 #include <sys/cdefs.h> 47 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.19 2025/10/03 14:05:12 thorpej Exp $"); 48 49 #include <sys/param.h> 50 #include <sys/conf.h> 51 #include <sys/device_if.h> 52 #include <sys/reboot.h> 53 #include <sys/systm.h> 54 55 #include <net/if.h> 56 #include <net/if_ether.h> 57 58 #include <dev/pci/pcivar.h> 59 60 #include <machine/pci_machdep.h> 61 62 #include <dev/marvell/gtpcivar.h> 63 #include <dev/marvell/gtreg.h> 64 #include <dev/marvell/marvellvar.h> 65 66 67 static void findroot(void); 68 69 70 /* 71 * Determine i/o configuration for a machine. 72 */ 73 void 74 cpu_configure(void) 75 { 76 77 if (config_rootfound("mainbus", NULL) == NULL) 78 panic("configure: mainbus not configured"); 79 80 spl0(); 81 } 82 83 void 84 cpu_rootconf(void) 85 { 86 findroot(); 87 88 printf("boot device: %s\n", 89 booted_device ? device_xname(booted_device) : "<unknown>"); 90 91 rootconf(); 92 } 93 94 dev_t bootdev = 0; 95 96 /* 97 * Attempt to find the device from which we were booted. 98 * If we can do so, and not instructed not to do so, 99 * change rootdev to correspond to the load device. 100 */ 101 static void 102 findroot(void) 103 { 104 device_t dv; 105 const char *name; 106 107 #if 0 108 printf("howto %x bootdev %x ", boothowto, bootdev); 109 #endif 110 111 if ((bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC) 112 return; 113 114 115 name = devsw_blk2name(B_TYPE(bootdev)); 116 if (name == NULL) 117 return; 118 119 if ((dv = device_find_by_driver_unit(name, B_UNIT(bootdev))) != NULL) { 120 booted_device = dv; 121 booted_partition = B_PARTITION(bootdev); 122 } 123 } 124 125 void 126 device_register(device_t dev, void *aux) 127 { 128 prop_dictionary_t dict = device_properties(dev); 129 130 if (device_is_a(dev, "gfe") && 131 device_is_a(device_parent(dev), "gt") ) { 132 struct marvell_attach_args *mva = aux; 133 char enaddr[ETHER_ADDR_LEN] = 134 { 0x02, 0x00, 0x04, 0x00, 0x00, 0x04 }; 135 136 switch (mva->mva_offset) { 137 case ETH0_BASE: enaddr[5] |= 0; break; 138 case ETH1_BASE: enaddr[5] |= 1; break; 139 case ETH2_BASE: enaddr[5] |= 2; break; 140 default: 141 aprint_error("WARNING: unknown mac-no. for %s\n", 142 device_xname(dev)); 143 } 144 if (! device_setprop_data(dev, "mac-address", enaddr, 145 ETHER_ADDR_LEN)) { 146 aprint_error( 147 "WARNING: unable to set mac-address property for %s\n", 148 device_xname(dev)); 149 } 150 } 151 if (device_is_a(dev, "gtpci")) { 152 extern struct gtpci_prot gtpci_prot; 153 extern struct powerpc_bus_space 154 ev64260_pci0_io_bs_tag, ev64260_pci0_mem_bs_tag, 155 ev64260_pci1_io_bs_tag, ev64260_pci1_mem_bs_tag; 156 extern struct genppc_pci_chipset 157 genppc_gtpci0_chipset, genppc_gtpci1_chipset; 158 159 struct marvell_attach_args *mva = aux; 160 struct powerpc_bus_space *pci_io_bs_tag, *pci_mem_bs_tag; 161 struct genppc_pci_chipset *genppc_gtpci_chipset; 162 prop_data_t prot, io_bs_tag, mem_bs_tag, pc; 163 164 if (mva->mva_unit == 0) { 165 pci_io_bs_tag = &ev64260_pci0_io_bs_tag; 166 pci_mem_bs_tag = &ev64260_pci0_mem_bs_tag; 167 genppc_gtpci_chipset = &genppc_gtpci0_chipset; 168 } else { 169 pci_io_bs_tag = &ev64260_pci1_io_bs_tag; 170 pci_mem_bs_tag = &ev64260_pci1_mem_bs_tag; 171 genppc_gtpci_chipset = &genppc_gtpci1_chipset; 172 } 173 174 prot = prop_data_create_data_nocopy( 175 >pci_prot, sizeof(struct gtpci_prot)); 176 KASSERT(prot != NULL); 177 prop_dictionary_set(dict, "prot", prot); 178 prop_object_release(prot); 179 io_bs_tag = prop_data_create_data_nocopy( 180 pci_io_bs_tag, sizeof(struct powerpc_bus_space)); 181 KASSERT(io_bs_tag != NULL); 182 prop_dictionary_set(dict, "io-bus-tag", io_bs_tag); 183 prop_object_release(io_bs_tag); 184 mem_bs_tag = prop_data_create_data_nocopy( 185 pci_mem_bs_tag, sizeof(struct powerpc_bus_space)); 186 KASSERT(mem_bs_tag != NULL); 187 prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag); 188 prop_object_release(mem_bs_tag); 189 190 genppc_gtpci_chipset->pc_conf_v = device_private(dev); 191 pc = prop_data_create_data_nocopy(genppc_gtpci_chipset, 192 sizeof(struct genppc_pci_chipset)); 193 KASSERT(pc != NULL); 194 prop_dictionary_set(dict, "pci-chipset", pc); 195 prop_object_release(pc); 196 197 prop_dictionary_set_uint64(dict, "iostart", 0x00000600); 198 prop_dictionary_set_uint64(dict, "ioend", 0x0000ffff); 199 prop_dictionary_set_uint64(dict, "memstart", 200 pci_mem_bs_tag->pbs_base); 201 prop_dictionary_set_uint64(dict, "memend", 202 pci_mem_bs_tag->pbs_limit - 1); 203 prop_dictionary_set_uint32(dict, "cache-line-size", 32); 204 } 205 if (device_is_a(dev, "obio") && 206 device_is_a(device_parent(dev), "gt") ) { 207 extern struct powerpc_bus_space *ev64260_obio_bs_tags[5]; 208 struct marvell_attach_args *mva = aux; 209 struct powerpc_bus_space *bst = 210 ev64260_obio_bs_tags[mva->mva_unit]; 211 prop_data_t bstd; 212 213 bstd = 214 prop_data_create_data_nocopy(bst, sizeof(bus_space_tag_t)); 215 KASSERT(bstd != NULL); 216 if (prop_dictionary_set(dict, "bus-tag", bstd) == false) 217 aprint_error( 218 "WARNING: unable to set bus-tag property for %s\n", 219 device_xname(dev)); 220 prop_object_release(bstd); 221 } 222 } 223