mainbus.c revision 1.2
11.2Sskrll/* $NetBSD: mainbus.c,v 1.2 2016/08/26 13:58:27 skrll Exp $ */ 21.1Sbouyer 31.1Sbouyer/* 41.1Sbouyer * Copyright 2002 Wasabi Systems, Inc. 51.1Sbouyer * All rights reserved. 61.1Sbouyer * 71.1Sbouyer * Written by Simon Burge for Wasabi Systems, Inc. 81.1Sbouyer * 91.1Sbouyer * Redistribution and use in source and binary forms, with or without 101.1Sbouyer * modification, are permitted provided that the following conditions 111.1Sbouyer * are met: 121.1Sbouyer * 1. Redistributions of source code must retain the above copyright 131.1Sbouyer * notice, this list of conditions and the following disclaimer. 141.1Sbouyer * 2. Redistributions in binary form must reproduce the above copyright 151.1Sbouyer * notice, this list of conditions and the following disclaimer in the 161.1Sbouyer * documentation and/or other materials provided with the distribution. 171.1Sbouyer * 3. All advertising materials mentioning features or use of this software 181.1Sbouyer * must display the following acknowledgement: 191.1Sbouyer * This product includes software developed for the NetBSD Project by 201.1Sbouyer * Wasabi Systems, Inc. 211.1Sbouyer * 4. The name of Wasabi Systems, Inc. may not be used to endorse 221.1Sbouyer * or promote products derived from this software without specific prior 231.1Sbouyer * written permission. 241.1Sbouyer * 251.1Sbouyer * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 261.1Sbouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 271.1Sbouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 281.1Sbouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 291.1Sbouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 301.1Sbouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 311.1Sbouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 321.1Sbouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 331.1Sbouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 341.1Sbouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 351.1Sbouyer * POSSIBILITY OF SUCH DAMAGE. 361.1Sbouyer */ 371.1Sbouyer 381.1Sbouyer#include <sys/cdefs.h> 391.2Sskrll__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.2 2016/08/26 13:58:27 skrll Exp $"); 401.1Sbouyer 411.1Sbouyer#include "opt_pci.h" 421.1Sbouyer 431.1Sbouyer#include <sys/param.h> 441.1Sbouyer#include <sys/systm.h> 451.1Sbouyer#include <sys/device.h> 461.1Sbouyer#if defined(PCI_NETBSD_CONFIGURE) 471.1Sbouyer#include <sys/extent.h> 481.1Sbouyer#include <sys/malloc.h> 491.1Sbouyer#endif 501.1Sbouyer 511.1Sbouyer#include <dev/pci/pcivar.h> 521.1Sbouyer#if defined(PCI_NETBSD_CONFIGURE) 531.1Sbouyer#include <dev/pci/pciconf.h> 541.1Sbouyer#endif 551.1Sbouyer 561.1Sbouyer#include <mips/cache.h> 571.1Sbouyer#include <mips/cpuregs.h> 581.1Sbouyer 591.1Sbouyer#include <mips/bonito/bonitoreg.h> 601.1Sbouyer 611.1Sbouyer#include <evbmips/loongson/autoconf.h> 621.2Sskrll#if defined(PCI_NETBSD_CONFIGURE) 631.2Sskrll#include <evbmips/loongson/loongson_bus_defs.h> 641.2Sskrll#endif 651.1Sbouyer 661.1Sbouyer#include "locators.h" 671.1Sbouyer#include "pci.h" 681.1Sbouyer 691.1Sbouyerstatic int mainbus_match(device_t, cfdata_t, void *); 701.1Sbouyerstatic void mainbus_attach(device_t, device_t, void *); 711.1Sbouyerstatic int mainbus_print(void *, const char *); 721.1Sbouyer 731.1SbouyerCFATTACH_DECL_NEW(mainbus, 0, 741.1Sbouyer mainbus_match, mainbus_attach, NULL, NULL); 751.1Sbouyer 761.1Sbouyer/* There can be only one. */ 771.1Sbouyerstatic bool mainbus_found; 781.1Sbouyer 791.1Sbouyerconst char * const mainbusdevs[] = { 801.1Sbouyer "cpu", 811.1Sbouyer "bonito", 821.1Sbouyer#if 0 831.1Sbouyer "i2c", 841.1Sbouyer "gpio", 851.1Sbouyer#endif 861.1Sbouyer}; 871.1Sbouyer 881.1Sbouyerstatic int 891.1Sbouyermainbus_match(device_t parent, cfdata_t match, void *aux) 901.1Sbouyer{ 911.1Sbouyer if (mainbus_found) 921.1Sbouyer return (0); 931.1Sbouyer 941.1Sbouyer return (1); 951.1Sbouyer} 961.1Sbouyer 971.1Sbouyerstatic void 981.1Sbouyermainbus_attach(device_t parent, device_t self, void *aux) 991.1Sbouyer{ 1001.1Sbouyer size_t i; 1011.1Sbouyer 1021.1Sbouyer mainbus_found = true; 1031.1Sbouyer aprint_normal("\n"); 1041.1Sbouyer 1051.1Sbouyer#if defined(PCI_NETBSD_CONFIGURE) 1061.2Sskrll struct extent *ioext = extent_create("pciio", 0x00001000, 0x00003fff, 1071.2Sskrll NULL, 0, EX_NOWAIT); 1081.2Sskrll struct extent *memext = extent_create("pcimem", 0, BONITO_PCILO_SIZE, 1091.2Sskrll NULL, 0, EX_NOWAIT); 1101.2Sskrll struct mips_cache_info * const mci = &mips_cache_info; 1111.2Sskrll 1121.2Sskrll pci_configure_bus(&bonito_pc, ioext, memext, 1131.2Sskrll NULL, 0, mci->mci_dcache_align); 1141.2Sskrll extent_destroy(ioext); 1151.2Sskrll extent_destroy(memext); 1161.1Sbouyer#endif /* PCI_NETBSD_CONFIGURE */ 1171.1Sbouyer 1181.1Sbouyer for (i = 0; i < __arraycount(mainbusdevs); i++) { 1191.1Sbouyer struct mainbus_attach_args maa; 1201.1Sbouyer maa.maa_name = mainbusdevs[i]; 1211.1Sbouyer (void) config_found(self, &maa, mainbus_print); 1221.1Sbouyer } 1231.1Sbouyer} 1241.1Sbouyer 1251.1Sbouyerstatic int 1261.1Sbouyermainbus_print(void *aux, const char *pnp) 1271.1Sbouyer{ 1281.1Sbouyer struct mainbus_attach_args *maa = aux; 1291.1Sbouyer 1301.1Sbouyer if (pnp) 1311.1Sbouyer aprint_normal("%s at %s", maa->maa_name, pnp); 1321.1Sbouyer 1331.1Sbouyer return UNCONF; 1341.1Sbouyer} 135