pci_machdep.c revision 1.37
11.37Smatt/* $NetBSD: pci_machdep.c,v 1.37 2015/06/09 22:47:59 matt Exp $ */ 21.1Ssoren 31.1Ssoren/* 41.1Ssoren * Copyright (c) 2000 Soren S. Jorvang. All rights reserved. 51.1Ssoren * 61.1Ssoren * Redistribution and use in source and binary forms, with or without 71.1Ssoren * modification, are permitted provided that the following conditions 81.1Ssoren * are met: 91.1Ssoren * 1. Redistributions of source code must retain the above copyright 101.1Ssoren * notice, this list of conditions, and the following disclaimer. 111.1Ssoren * 2. Redistributions in binary form must reproduce the above copyright 121.1Ssoren * notice, this list of conditions and the following disclaimer in the 131.1Ssoren * documentation and/or other materials provided with the distribution. 141.1Ssoren * 151.1Ssoren * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 161.1Ssoren * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 171.1Ssoren * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 181.1Ssoren * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 191.1Ssoren * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 201.1Ssoren * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 211.1Ssoren * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 221.1Ssoren * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 231.1Ssoren * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 241.1Ssoren * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 251.1Ssoren * SUCH DAMAGE. 261.1Ssoren */ 271.13Slukem 281.13Slukem#include <sys/cdefs.h> 291.37Smatt__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.37 2015/06/09 22:47:59 matt Exp $"); 301.32Smatt 311.36Sskrll#define _MIPS_BUS_DMA_PRIVATE 321.1Ssoren 331.1Ssoren#include <sys/param.h> 341.32Smatt#include <sys/bus.h> 351.37Smatt#include <sys/cpu.h> 361.37Smatt#include <sys/device.h> 371.1Ssoren#include <sys/errno.h> 381.17Stsutsui#include <sys/extent.h> 391.32Smatt#include <sys/intr.h> 401.32Smatt#include <sys/systm.h> 411.32Smatt#include <sys/time.h> 421.1Ssoren 431.1Ssoren#include <dev/pci/pcivar.h> 441.1Ssoren#include <dev/pci/pcireg.h> 451.1Ssoren#include <dev/pci/pcidevs.h> 461.17Stsutsui#include <dev/pci/pciconf.h> 471.23Stsutsui#include <dev/pci/pciide_apollo_reg.h> 481.1Ssoren 491.16Stsutsui#include <cobalt/dev/gtreg.h> 501.16Stsutsui 511.1Ssoren/* 521.1Ssoren * PCI doesn't have any special needs; just use 531.1Ssoren * the generic versions of these functions. 541.1Ssoren */ 551.36Sskrllstruct mips_bus_dma_tag pci_bus_dma_tag = { 561.36Sskrll ._dmamap_ops = _BUS_DMAMAP_OPS_INITIALIZER, 571.36Sskrll ._dmamem_ops = _BUS_DMAMEM_OPS_INITIALIZER, 581.36Sskrll ._dmatag_ops = _BUS_DMATAG_OPS_INITIALIZER, 591.1Ssoren}; 601.1Ssoren 611.1Ssorenvoid 621.33Schspci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba) 631.1Ssoren{ 641.1Ssoren /* XXX */ 651.1Ssoren 661.1Ssoren return; 671.1Ssoren} 681.1Ssoren 691.1Ssorenint 701.20Stsutsuipci_bus_maxdevs(pci_chipset_tag_t pc, int busno) 711.1Ssoren{ 721.20Stsutsui 731.6Ssoren return 32; 741.1Ssoren} 751.1Ssoren 761.1Ssorenpcitag_t 771.20Stsutsuipci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function) 781.1Ssoren{ 791.20Stsutsui 801.1Ssoren return (bus << 16) | (device << 11) | (function << 8); 811.1Ssoren} 821.1Ssoren 831.1Ssorenvoid 841.20Stsutsuipci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp) 851.1Ssoren{ 861.20Stsutsui 871.1Ssoren if (bp != NULL) 881.1Ssoren *bp = (tag >> 16) & 0xff; 891.1Ssoren if (dp != NULL) 901.1Ssoren *dp = (tag >> 11) & 0x1f; 911.1Ssoren if (fp != NULL) 921.1Ssoren *fp = (tag >> 8) & 0x07; 931.1Ssoren} 941.1Ssoren 951.1Ssorenpcireg_t 961.20Stsutsuipci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg) 971.1Ssoren{ 981.1Ssoren pcireg_t data; 991.6Ssoren int bus, dev, func; 1001.14Stsutsui 1011.28Smatt KASSERT(pc != NULL); 1021.28Smatt 1031.6Ssoren pci_decompose_tag(pc, tag, &bus, &dev, &func); 1041.6Ssoren 1051.6Ssoren /* 1061.6Ssoren * 2700 hardware wedges on accesses to device 6. 1071.6Ssoren */ 1081.6Ssoren if (bus == 0 && dev == 6) 1091.6Ssoren return 0; 1101.6Ssoren /* 1111.6Ssoren * 2800 hardware wedges on accesses to device 31. 1121.6Ssoren */ 1131.6Ssoren if (bus == 0 && dev == 31) 1141.6Ssoren return 0; 1151.1Ssoren 1161.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 1171.21Stsutsui PCICFG_ENABLE | tag | reg); 1181.16Stsutsui data = bus_space_read_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA); 1191.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0); 1201.1Ssoren 1211.1Ssoren return data; 1221.1Ssoren} 1231.1Ssoren 1241.1Ssorenvoid 1251.20Stsutsuipci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data) 1261.1Ssoren{ 1271.1Ssoren 1281.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 1291.21Stsutsui PCICFG_ENABLE | tag | reg); 1301.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA, data); 1311.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0); 1321.1Ssoren} 1331.1Ssoren 1341.1Ssorenint 1351.29Sdyoungpci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp) 1361.1Ssoren{ 1371.10Ssommerfe pci_chipset_tag_t pc = pa->pa_pc; 1381.11Stsutsui pcitag_t intrtag = pa->pa_intrtag; 1391.10Ssommerfe int pin = pa->pa_intrpin; 1401.10Ssommerfe int line = pa->pa_intrline; 1411.5Ssoren int bus, dev, func; 1421.1Ssoren 1431.5Ssoren pci_decompose_tag(pc, intrtag, &bus, &dev, &func); 1441.5Ssoren 1451.5Ssoren /* 1461.26Stsutsui * The interrupt lines of the internal Tulips are connected 1471.5Ssoren * directly to the CPU. 1481.5Ssoren */ 1491.25Stsutsui if (cobalt_id == COBALT_ID_QUBE2700) { 1501.26Stsutsui if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) { 1511.26Stsutsui /* tulip is connected to CPU INT2 on Qube2700 */ 1521.26Stsutsui *ihp = NICU_INT + 2; 1531.26Stsutsui return 0; 1541.26Stsutsui } 1551.25Stsutsui } else { 1561.26Stsutsui if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) { 1571.26Stsutsui /* the primary tulip is connected to CPU INT1 */ 1581.26Stsutsui *ihp = NICU_INT + 1; 1591.26Stsutsui return 0; 1601.26Stsutsui } 1611.26Stsutsui if (bus == 0 && dev == 12 && pin == PCI_INTERRUPT_PIN_A) { 1621.26Stsutsui /* the secondary tulip is connected to CPU INT2 */ 1631.26Stsutsui *ihp = NICU_INT + 2; 1641.26Stsutsui return 0; 1651.26Stsutsui } 1661.25Stsutsui } 1671.1Ssoren 1681.26Stsutsui /* sanity check */ 1691.26Stsutsui if (line == 0 || line >= NICU_INT) 1701.26Stsutsui return -1; 1711.26Stsutsui 1721.26Stsutsui *ihp = line; 1731.1Ssoren return 0; 1741.1Ssoren} 1751.1Ssoren 1761.1Ssorenconst char * 1771.35Schristospci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf, size_t len) 1781.1Ssoren{ 1791.26Stsutsui if (ih >= NICU_INT) 1801.35Schristos snprintf(buf, len, "level %d", ih - NICU_INT); 1811.4Ssoren else 1821.35Schristos snprintf(buf, len, "irq %d", ih); 1831.1Ssoren 1841.35Schristos return buf; 1851.7Scgd} 1861.7Scgd 1871.7Scgdconst struct evcnt * 1881.20Stsutsuipci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih) 1891.7Scgd{ 1901.7Scgd 1911.7Scgd /* XXX for now, no evcnt parent reported */ 1921.7Scgd return NULL; 1931.1Ssoren} 1941.1Ssoren 1951.27Sadint 1961.27Sadpci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih, 1971.27Sad int attr, uint64_t data) 1981.27Sad{ 1991.27Sad 2001.27Sad switch (attr) { 2011.27Sad case PCI_INTR_MPSAFE: 2021.27Sad return 0; 2031.27Sad default: 2041.27Sad return ENODEV; 2051.27Sad } 2061.27Sad} 2071.27Sad 2081.1Ssorenvoid * 2091.20Stsutsuipci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level, 2101.20Stsutsui int (*func)(void *), void *arg) 2111.1Ssoren{ 2121.20Stsutsui 2131.26Stsutsui if (ih >= NICU_INT) 2141.26Stsutsui return cpu_intr_establish(ih - NICU_INT, level, func, arg); 2151.4Ssoren else 2161.4Ssoren return icu_intr_establish(ih, IST_LEVEL, level, func, arg); 2171.1Ssoren} 2181.1Ssoren 2191.1Ssorenvoid 2201.20Stsutsuipci_intr_disestablish(pci_chipset_tag_t pc, void *cookie) 2211.1Ssoren{ 2221.20Stsutsui 2231.12Saugustss /* Try both, only the valid one will disestablish. */ 2241.12Saugustss cpu_intr_disestablish(cookie); 2251.12Saugustss icu_intr_disestablish(cookie); 2261.1Ssoren} 2271.17Stsutsui 2281.17Stsutsuivoid 2291.17Stsutsuipci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz, 2301.17Stsutsui int *iline) 2311.17Stsutsui{ 2321.17Stsutsui 2331.26Stsutsui /* 2341.26Stsutsui * Use irq 9 on all devices on the Qube's PCI slot. 2351.26Stsutsui * XXX doesn't handle devices over PCI-PCI bridges 2361.26Stsutsui */ 2371.26Stsutsui if (bus == 0 && dev == 10 && pin != PCI_INTERRUPT_PIN_NONE) 2381.26Stsutsui *iline = 9; 2391.17Stsutsui} 2401.17Stsutsui 2411.17Stsutsuiint 2421.17Stsutsuipci_conf_hook(pci_chipset_tag_t pc, int bus, int dev, int func, pcireg_t id) 2431.17Stsutsui{ 2441.17Stsutsui 2451.22Stsutsui /* ignore bogus IDs */ 2461.22Stsutsui if (PCI_VENDOR(id) == 0) 2471.22Stsutsui return 0; 2481.22Stsutsui 2491.22Stsutsui /* 2700 hardware wedges on accesses to device 6. */ 2501.22Stsutsui if (bus == 0 && dev == 6) 2511.22Stsutsui return 0; 2521.22Stsutsui 2531.22Stsutsui /* 2800 hardware wedges on accesses to device 31. */ 2541.22Stsutsui if (bus == 0 && dev == 31) 2551.22Stsutsui return 0; 2561.22Stsutsui 2571.30Stsutsui /* Don't configure the bridge and PCI probe. */ 2581.24Sriz if (PCI_VENDOR(id) == PCI_VENDOR_MARVELL && 2591.24Sriz PCI_PRODUCT(id) == PCI_PRODUCT_MARVELL_GT64011) 2601.17Stsutsui return 0; 2611.17Stsutsui 2621.23Stsutsui /* Don't configure on-board VIA VT82C586 (pcib, uhci) */ 2631.23Stsutsui if (bus == 0 && dev == 9 && (func == 0 || func == 2)) 2641.17Stsutsui return 0; 2651.17Stsutsui 2661.23Stsutsui /* Enable viaide secondary port. Some firmware doesn't enable it. */ 2671.23Stsutsui if (bus == 0 && dev == 9 && func == 1) { 2681.23Stsutsui pcitag_t tag; 2691.23Stsutsui pcireg_t csr; 2701.23Stsutsui 2711.23Stsutsui#define APO_VIAIDECONF (APO_VIA_REGBASE + 0x00) 2721.23Stsutsui 2731.23Stsutsui tag = pci_make_tag(pc, bus, dev, func); 2741.23Stsutsui csr = pci_conf_read(pc, tag, APO_VIAIDECONF); 2751.23Stsutsui pci_conf_write(pc, tag, APO_VIAIDECONF, 2761.23Stsutsui csr | APO_IDECONF_EN(1)); 2771.23Stsutsui } 2781.19Sgdamore return PCI_CONF_DEFAULT & ~(PCI_COMMAND_SERR_ENABLE | 2791.19Sgdamore PCI_COMMAND_PARITY_ENABLE); 2801.17Stsutsui} 281