11.10Sthorpej/* $NetBSD: mainbus.c,v 1.10 2023/12/20 14:12:25 thorpej Exp $ */ 21.1Smatt 31.1Smatt/* 41.1Smatt * Copyright 2002 Wasabi Systems, Inc. 51.1Smatt * All rights reserved. 61.1Smatt * 71.1Smatt * Written by Simon Burge for Wasabi Systems, Inc. 81.1Smatt * 91.1Smatt * Redistribution and use in source and binary forms, with or without 101.1Smatt * modification, are permitted provided that the following conditions 111.1Smatt * are met: 121.1Smatt * 1. Redistributions of source code must retain the above copyright 131.1Smatt * notice, this list of conditions and the following disclaimer. 141.1Smatt * 2. Redistributions in binary form must reproduce the above copyright 151.1Smatt * notice, this list of conditions and the following disclaimer in the 161.1Smatt * documentation and/or other materials provided with the distribution. 171.1Smatt * 3. All advertising materials mentioning features or use of this software 181.1Smatt * must display the following acknowledgement: 191.1Smatt * This product includes software developed for the NetBSD Project by 201.1Smatt * Wasabi Systems, Inc. 211.1Smatt * 4. The name of Wasabi Systems, Inc. may not be used to endorse 221.1Smatt * or promote products derived from this software without specific prior 231.1Smatt * written permission. 241.1Smatt * 251.1Smatt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 261.1Smatt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 271.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 281.1Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 291.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 301.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 311.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 321.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 331.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 341.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 351.1Smatt * POSSIBILITY OF SUCH DAMAGE. 361.1Smatt */ 371.1Smatt 381.1Smatt#include <sys/cdefs.h> 391.10Sthorpej__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.10 2023/12/20 14:12:25 thorpej Exp $"); 401.1Smatt 411.1Smatt#include "opt_pci.h" 421.1Smatt 431.1Smatt#include <sys/param.h> 441.1Smatt#include <sys/systm.h> 451.1Smatt#include <sys/device.h> 461.1Smatt 471.1Smatt#include <dev/pci/pcivar.h> 481.1Smatt#if defined(PCI_NETBSD_CONFIGURE) 491.1Smatt#include <dev/pci/pciconf.h> 501.1Smatt#endif 511.1Smatt 521.1Smatt#include <mips/cache.h> 531.1Smatt#include <mips/cpuregs.h> 541.1Smatt 551.1Smatt#include <mips/bonito/bonitoreg.h> 561.1Smatt#include <evbmips/gdium/gdiumvar.h> 571.1Smatt 581.1Smatt#include "locators.h" 591.1Smatt#include "pci.h" 601.1Smatt 611.1Smattstatic int mainbus_match(device_t, cfdata_t, void *); 621.1Smattstatic void mainbus_attach(device_t, device_t, void *); 631.1Smattstatic int mainbus_print(void *, const char *); 641.1Smatt 651.1SmattCFATTACH_DECL_NEW(mainbus, 0, 661.1Smatt mainbus_match, mainbus_attach, NULL, NULL); 671.1Smatt 681.1Smatt/* There can be only one. */ 691.2Smattstatic bool mainbus_found; 701.1Smatt 711.1Smattconst char * const mainbusdevs[] = { 721.1Smatt "cpu", 731.1Smatt "bonito", 741.1Smatt#if 0 751.1Smatt "i2c", 761.1Smatt "gpio", 771.1Smatt#endif 781.1Smatt}; 791.1Smatt 801.7Sthorpej#define PCI_IO_START 0x00001000 811.7Sthorpej#define PCI_IO_END 0x00003fff 821.7Sthorpej#define PCI_IO_SIZE ((PCI_IO_END - PCI_IO_START) + 1) 831.7Sthorpej 841.7Sthorpej#define PCI_MEM_START 0 851.7Sthorpej#define PCI_MEM_SIZE BONITO_PCILO_SIZE 861.7Sthorpej 871.1Smattstatic int 881.1Smattmainbus_match(device_t parent, cfdata_t match, void *aux) 891.1Smatt{ 901.1Smatt if (mainbus_found) 911.1Smatt return (0); 921.1Smatt 931.1Smatt return (1); 941.1Smatt} 951.1Smatt 961.1Smattstatic void 971.1Smattmainbus_attach(device_t parent, device_t self, void *aux) 981.1Smatt{ 991.1Smatt size_t i; 1001.1Smatt 1011.2Smatt mainbus_found = true; 1021.1Smatt aprint_normal("\n"); 1031.1Smatt 1041.1Smatt#if defined(PCI_NETBSD_CONFIGURE) 1051.5Sskrll struct mips_cache_info * const mci = &mips_cache_info; 1061.1Smatt 1071.7Sthorpej struct pciconf_resources *pcires = pciconf_resource_init(); 1081.7Sthorpej pciconf_resource_add(pcires, PCICONF_RESOURCE_IO, 1091.7Sthorpej PCI_IO_START, PCI_IO_SIZE); 1101.7Sthorpej pciconf_resource_add(pcires, PCICONF_RESOURCE_MEM, 1111.7Sthorpej PCI_MEM_START, PCI_MEM_SIZE); 1121.7Sthorpej pci_configure_bus(&gdium_configuration.gc_pc, pcires, 1131.7Sthorpej 0, mci->mci_dcache_align); 1141.7Sthorpej pciconf_resource_fini(pcires); 1151.1Smatt#endif /* PCI_NETBSD_CONFIGURE */ 1161.1Smatt 1171.1Smatt for (i = 0; i < __arraycount(mainbusdevs); i++) { 1181.1Smatt struct mainbus_attach_args maa; 1191.1Smatt maa.maa_name = mainbusdevs[i]; 1201.9Sthorpej (void) config_found(self, &maa, mainbus_print, CFARGS_NONE); 1211.1Smatt } 1221.1Smatt} 1231.1Smatt 1241.1Smattstatic int 1251.1Smattmainbus_print(void *aux, const char *pnp) 1261.1Smatt{ 1271.1Smatt struct mainbus_attach_args *maa = aux; 1281.1Smatt 1291.1Smatt if (pnp) 1301.1Smatt aprint_normal("%s at %s", maa->maa_name, pnp); 1311.1Smatt 1321.1Smatt return UNCONF; 1331.1Smatt} 134