rmixl_mainbus.c revision 1.5
11.5Sthorpej/* $NetBSD: rmixl_mainbus.c,v 1.5 2021/04/24 23:36:43 thorpej Exp $ */ 21.2Smatt 31.2Smatt/* 41.2Smatt * Copyright (c) 1994,1995 Mark Brinicombe. 51.2Smatt * Copyright (c) 1994 Brini. 61.2Smatt * All rights reserved. 71.2Smatt * 81.2Smatt * Redistribution and use in source and binary forms, with or without 91.2Smatt * modification, are permitted provided that the following conditions 101.2Smatt * are met: 111.2Smatt * 1. Redistributions of source code must retain the above copyright 121.2Smatt * notice, this list of conditions and the following disclaimer. 131.2Smatt * 2. Redistributions in binary form must reproduce the above copyright 141.2Smatt * notice, this list of conditions and the following disclaimer in the 151.2Smatt * documentation and/or other materials provided with the distribution. 161.2Smatt * 3. All advertising materials mentioning features or use of this software 171.2Smatt * must display the following acknowledgement: 181.2Smatt * This product includes software developed by Brini. 191.2Smatt * 4. The name of the company nor the name of the author may be used to 201.2Smatt * endorse or promote products derived from this software without specific 211.2Smatt * prior written permission. 221.2Smatt * 231.2Smatt * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED 241.2Smatt * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 251.2Smatt * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 261.2Smatt * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 271.2Smatt * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 281.2Smatt * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 291.2Smatt * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301.2Smatt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311.2Smatt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321.2Smatt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331.2Smatt * SUCH DAMAGE. 341.2Smatt * 351.2Smatt * RiscBSD kernel project 361.2Smatt * 371.2Smatt * mainbus.c 381.2Smatt * 391.2Smatt * mainbus configuration 401.2Smatt * 411.2Smatt * Created : 15/12/94 421.2Smatt */ 431.2Smatt 441.2Smatt#include <sys/cdefs.h> 451.5Sthorpej__KERNEL_RCSID(0, "$NetBSD: rmixl_mainbus.c,v 1.5 2021/04/24 23:36:43 thorpej Exp $"); 461.2Smatt 471.2Smatt#include <sys/param.h> 481.2Smatt#include <sys/systm.h> 491.2Smatt#include <sys/kernel.h> 501.2Smatt#include <sys/conf.h> 511.2Smatt#include <sys/malloc.h> 521.2Smatt#include <sys/device.h> 531.2Smatt 541.3Smatt#include <evbmips/rmixl/autoconf.h> 551.4Sdyoung#include <sys/bus.h> 561.2Smatt#include "locators.h" 571.2Smatt 581.2Smattstatic int mainbusmatch(device_t, cfdata_t, void *); 591.2Smattstatic void mainbusattach(device_t, device_t, void *); 601.3Smattstatic int mainbus_node_alloc(struct mainbus_softc *, int); 611.3Smattstatic int mainbus_search(device_t, cfdata_t, const int *, void *); 621.3Smattstatic int mainbus_print(void *, const char *); 631.2Smatt 641.3SmattCFATTACH_DECL_NEW(mainbus, sizeof(struct mainbus_softc), 651.3Smatt mainbusmatch, mainbusattach, NULL, NULL); 661.2Smatt 671.2Smattstatic int mainbus_found; 681.2Smatt 691.2Smattstatic int 701.2Smattmainbusmatch(device_t parent, cfdata_t cf, void *aux) 711.2Smatt{ 721.2Smatt if (mainbus_found) 731.2Smatt return 0; 741.2Smatt return 1; 751.2Smatt} 761.2Smatt 771.3Smattstatic void 781.3Smattmainbusattach(device_t parent, device_t self, void *aux) 791.3Smatt{ 801.3Smatt struct mainbus_softc *sc = device_private(self); 811.3Smatt 821.3Smatt aprint_naive("\n"); 831.3Smatt aprint_normal("\n"); 841.3Smatt 851.3Smatt sc->sc_dev = self; 861.3Smatt sc->sc_node_next = 0; 871.3Smatt sc->sc_node_mask = 0; 881.3Smatt 891.3Smatt mainbus_found = 1; 901.3Smatt 911.3Smatt /* 921.3Smatt * attach mainbus devices 931.3Smatt */ 941.5Sthorpej config_search(self, NULL, 951.5Sthorpej CFARG_SEARCH, mainbus_search, 961.5Sthorpej CFARG_EOL); 971.3Smatt} 981.3Smatt 991.3Smattstatic int 1001.3Smattmainbus_print(void *aux, const char *pnp) 1011.3Smatt{ 1021.3Smatt struct mainbus_attach_args *ma = aux; 1031.3Smatt 1041.3Smatt if (pnp != NULL) 1051.3Smatt aprint_normal("%s:", pnp); 1061.3Smatt aprint_normal(" node %d", ma->ma_node); 1071.3Smatt 1081.3Smatt return (UNCONF); 1091.3Smatt} 1101.3Smatt 1111.2Smattstatic int 1121.3Smattmainbus_node_alloc(struct mainbus_softc *sc, int node) 1131.2Smatt{ 1141.3Smatt uint64_t bit; 1151.3Smatt 1161.3Smatt if (node == MAINBUSCF_NODE_DEFAULT) { 1171.3Smatt for (node=sc->sc_node_next; node < 64; node++) { 1181.3Smatt bit = 1 << node; 1191.3Smatt if ((sc->sc_node_mask & bit) == 0) { 1201.3Smatt sc->sc_node_mask |= bit; 1211.3Smatt sc->sc_node_next = node + 1; 1221.3Smatt return node; 1231.3Smatt } 1241.3Smatt } 1251.3Smatt panic("%s: node mask underflow", __func__); 1261.3Smatt } else { 1271.3Smatt if (node >= 64) 1281.3Smatt panic("%s: node >= 64", __func__); 1291.3Smatt if (node < 0) 1301.3Smatt panic("%s: bad node %d", __func__, node); 1311.3Smatt bit = 1 << node; 1321.3Smatt if ((sc->sc_node_mask & bit) == 0) { 1331.3Smatt sc->sc_node_mask |= bit; 1341.3Smatt sc->sc_node_next = node + 1; 1351.3Smatt return node; 1361.3Smatt } else { 1371.3Smatt panic("%s: node %d already used\n", 1381.3Smatt __func__, node); 1391.3Smatt } 1401.3Smatt } 1411.2Smatt 1421.3Smatt /*NOTREACHED*/ 1431.3Smatt return -1; /* as if */ 1441.2Smatt} 1451.2Smatt 1461.3Smattstatic int 1471.3Smattmainbus_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux) 1481.2Smatt{ 1491.3Smatt struct mainbus_softc *sc = device_private(parent); 1501.3Smatt struct mainbus_attach_args ma; 1511.3Smatt 1521.3Smatt ma.ma_node = mainbus_node_alloc(sc, cf->cf_loc[MAINBUSCF_NODE]); 1531.3Smatt 1541.5Sthorpej if (config_probe(parent, cf, &ma)) 1551.5Sthorpej config_attach(parent, cf, &ma, mainbus_print, CFARG_EOL); 1561.2Smatt 1571.3Smatt return 0; 1581.2Smatt} 1591.3Smatt 160