mainbus.c revision 1.2
11.2Sthorpej/* $NetBSD: mainbus.c,v 1.2 2002/09/27 03:17:49 thorpej Exp $ */ 21.1Ssimonb 31.1Ssimonb/* 41.1Ssimonb * Copyright 2002 Wasabi Systems, Inc. 51.1Ssimonb * All rights reserved. 61.1Ssimonb * 71.1Ssimonb * Written by Simon Burge for Wasabi Systems, Inc. 81.1Ssimonb * 91.1Ssimonb * Redistribution and use in source and binary forms, with or without 101.1Ssimonb * modification, are permitted provided that the following conditions 111.1Ssimonb * are met: 121.1Ssimonb * 1. Redistributions of source code must retain the above copyright 131.1Ssimonb * notice, this list of conditions and the following disclaimer. 141.1Ssimonb * 2. Redistributions in binary form must reproduce the above copyright 151.1Ssimonb * notice, this list of conditions and the following disclaimer in the 161.1Ssimonb * documentation and/or other materials provided with the distribution. 171.1Ssimonb * 3. All advertising materials mentioning features or use of this software 181.1Ssimonb * must display the following acknowledgement: 191.1Ssimonb * This product includes software developed for the NetBSD Project by 201.1Ssimonb * Wasabi Systems, Inc. 211.1Ssimonb * 4. The name of Wasabi Systems, Inc. may not be used to endorse 221.1Ssimonb * or promote products derived from this software without specific prior 231.1Ssimonb * written permission. 241.1Ssimonb * 251.1Ssimonb * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 261.1Ssimonb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 271.1Ssimonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 281.1Ssimonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 291.1Ssimonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 301.1Ssimonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 311.1Ssimonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 321.1Ssimonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 331.1Ssimonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 341.1Ssimonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 351.1Ssimonb * POSSIBILITY OF SUCH DAMAGE. 361.1Ssimonb */ 371.1Ssimonb 381.1Ssimonb#include "opt_pci.h" 391.1Ssimonb 401.1Ssimonb#include <sys/param.h> 411.1Ssimonb#include <sys/systm.h> 421.1Ssimonb#include <sys/device.h> 431.1Ssimonb#if defined(PCI_NETBSD_CONFIGURE) 441.1Ssimonb#include <sys/extent.h> 451.1Ssimonb#include <sys/malloc.h> 461.1Ssimonb#endif 471.1Ssimonb 481.1Ssimonb#include <dev/pci/pcivar.h> 491.1Ssimonb#if defined(PCI_NETBSD_CONFIGURE) 501.1Ssimonb#include <dev/pci/pciconf.h> 511.1Ssimonb#endif 521.1Ssimonb 531.1Ssimonb#include <mips/cache.h> 541.1Ssimonb#include <mips/cpuregs.h> 551.1Ssimonb 561.1Ssimonb#include <evbmips/malta/autoconf.h> 571.1Ssimonb#include <evbmips/malta/maltareg.h> 581.1Ssimonb#include <evbmips/malta/maltavar.h> 591.1Ssimonb 601.1Ssimonb#if defined(PCI_NETBSD_ENABLE_IDE) 611.1Ssimonb#include <dev/pci/pciide_piix_reg.h> 621.1Ssimonb#endif /* PCI_NETBSD_ENABLE_IDE */ 631.1Ssimonb 641.1Ssimonb#include "locators.h" 651.1Ssimonb#include "pci.h" 661.1Ssimonb 671.1Ssimonbstatic int mainbus_match(struct device *, struct cfdata *, void *); 681.1Ssimonbstatic void mainbus_attach(struct device *, struct device *, void *); 691.1Ssimonbstatic int mainbus_submatch(struct device *, struct cfdata *, void *); 701.1Ssimonbstatic int mainbus_print(void *, const char *); 711.1Ssimonb 721.1Ssimonbstruct cfattach mainbus_ca = { 731.1Ssimonb sizeof(struct device), mainbus_match, mainbus_attach 741.1Ssimonb}; 751.1Ssimonb 761.1Ssimonb/* There can be only one. */ 771.1Ssimonbint mainbus_found; 781.1Ssimonb 791.1Ssimonbstruct mainbusdev { 801.1Ssimonb const char *md_name; 811.1Ssimonb bus_addr_t md_addr; 821.1Ssimonb int md_intr; 831.1Ssimonb}; 841.1Ssimonb 851.1Ssimonbstruct mainbusdev mainbusdevs[] = { 861.1Ssimonb { "cpu", -1, -1 }, 871.1Ssimonb { "gt", MALTA_CORECTRL_BASE, -1 }, 881.1Ssimonb { "com", MALTA_CBUSUART, MALTA_CBUSUART_INTR }, 891.1Ssimonb { "i2c", MALTA_I2C_BASE, -1 }, 901.1Ssimonb { "gpio", MALTA_GPIO_BASE, -1 }, 911.1Ssimonb { NULL, 0, 0 }, 921.1Ssimonb}; 931.1Ssimonb 941.1Ssimonbstatic int 951.1Ssimonbmainbus_match(parent, match, aux) 961.1Ssimonb struct device *parent; 971.1Ssimonb struct cfdata *match; 981.1Ssimonb void *aux; 991.1Ssimonb{ 1001.1Ssimonb 1011.1Ssimonb if (mainbus_found) 1021.1Ssimonb return (0); 1031.1Ssimonb 1041.1Ssimonb return (1); 1051.1Ssimonb} 1061.1Ssimonb 1071.1Ssimonbstatic void 1081.1Ssimonbmainbus_attach(parent, self, aux) 1091.1Ssimonb struct device *parent; 1101.1Ssimonb struct device *self; 1111.1Ssimonb void *aux; 1121.1Ssimonb{ 1131.1Ssimonb struct mainbus_attach_args ma; 1141.1Ssimonb struct mainbusdev *md; 1151.1Ssimonb#if defined(PCI_NETBSD_CONFIGURE) 1161.1Ssimonb struct extent *ioext, *memext; 1171.1Ssimonb#endif 1181.1Ssimonb#if defined(PCI_NETBSD_ENABLE_IDE) 1191.1Ssimonb struct malta_config *mcp = &malta_configuration; 1201.1Ssimonb pci_chipset_tag_t pc = &mcp->mc_pc; 1211.1Ssimonb pcitag_t idetag; 1221.1Ssimonb pcireg_t idetim; 1231.1Ssimonb#endif 1241.1Ssimonb 1251.1Ssimonb mainbus_found = 1; 1261.1Ssimonb printf("\n"); 1271.1Ssimonb 1281.1Ssimonb#if defined(PCI_NETBSD_CONFIGURE) 1291.1Ssimonb ioext = extent_create("pciio", 0x00001000, 0x0000efff, 1301.1Ssimonb M_DEVBUF, NULL, 0, EX_NOWAIT); 1311.1Ssimonb memext = extent_create("pcimem", MALTA_PCIMEM1_BASE, 1321.1Ssimonb MALTA_PCIMEM1_BASE + MALTA_PCIMEM1_SIZE, 1331.1Ssimonb M_DEVBUF, NULL, 0, EX_NOWAIT); 1341.1Ssimonb 1351.1Ssimonb pci_configure_bus(pc, ioext, memext, NULL, 0, mips_dcache_align); 1361.1Ssimonb extent_destroy(ioext); 1371.1Ssimonb extent_destroy(memext); 1381.1Ssimonb#endif /* PCI_NETBSD_CONFIGURE */ 1391.1Ssimonb 1401.1Ssimonb#if defined(PCI_NETBSD_ENABLE_IDE) 1411.1Ssimonb /* 1421.1Ssimonb * Perhaps PMON has not enabled the IDE controller. Easy to 1431.1Ssimonb * fix -- just set the ENABLE bits for each channel in the 1441.1Ssimonb * IDETIM register. Just clear all the bits for the channel 1451.1Ssimonb * except for the ENABLE bits -- the `pciide' driver will 1461.1Ssimonb * properly configure it later. 1471.1Ssimonb */ 1481.1Ssimonb idetim = 0; 1491.1Ssimonb if (PCI_NETBSD_ENABLE_IDE & 0x01) 1501.1Ssimonb idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 0); 1511.1Ssimonb if (PCI_NETBSD_ENABLE_IDE & 0x02) 1521.1Ssimonb idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 1); 1531.1Ssimonb 1541.1Ssimonb /* pciide0 is pci device 10, function 1 */ 1551.1Ssimonb idetag = pci_make_tag(pc, 0, 10, 1); 1561.1Ssimonb pci_conf_write(pc, idetag, PIIX_IDETIM, idetim); 1571.1Ssimonb#endif 1581.1Ssimonb for (md = mainbusdevs; md->md_name != NULL; md++) { 1591.1Ssimonb ma.ma_name = md->md_name; 1601.1Ssimonb ma.ma_addr = md->md_addr; 1611.1Ssimonb ma.ma_intr = md->md_intr; 1621.1Ssimonb (void) config_found_sm(self, &ma, mainbus_print, 1631.1Ssimonb mainbus_submatch); 1641.1Ssimonb } 1651.1Ssimonb} 1661.1Ssimonb 1671.1Ssimonbstatic int 1681.1Ssimonbmainbus_submatch(struct device *parent, struct cfdata *cf, void *aux) 1691.1Ssimonb{ 1701.1Ssimonb struct mainbus_attach_args *ma = aux; 1711.1Ssimonb 1721.1Ssimonb if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT && 1731.1Ssimonb cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr) 1741.1Ssimonb return (0); 1751.1Ssimonb 1761.2Sthorpej return (config_match(parent, cf, aux)); 1771.1Ssimonb} 1781.1Ssimonb 1791.1Ssimonbstatic int 1801.1Ssimonbmainbus_print(void *aux, const char *pnp) 1811.1Ssimonb{ 1821.1Ssimonb struct mainbus_attach_args *ma = aux; 1831.1Ssimonb 1841.1Ssimonb if (pnp != 0) 1851.1Ssimonb return QUIET; 1861.1Ssimonb 1871.1Ssimonb if (pnp) 1881.1Ssimonb printf("%s at %s", ma->ma_name, pnp); 1891.1Ssimonb if (ma->ma_addr != MAINBUSCF_ADDR_DEFAULT) 1901.1Ssimonb printf(" addr 0x%lx", ma->ma_addr); 1911.1Ssimonb 1921.1Ssimonb return (UNCONF); 1931.1Ssimonb} 194