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