pci_machdep.c revision 1.36
11.36Sskrll/* $NetBSD: pci_machdep.c,v 1.36 2014/07/29 21:21:44 skrll 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.36Sskrll__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.36 2014/07/29 21:21:44 skrll 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.1Ssoren#include <sys/errno.h> 361.1Ssoren#include <sys/device.h> 371.17Stsutsui#include <sys/extent.h> 381.32Smatt#include <sys/intr.h> 391.32Smatt#include <sys/systm.h> 401.32Smatt#include <sys/time.h> 411.1Ssoren 421.1Ssoren#include <dev/pci/pcivar.h> 431.1Ssoren#include <dev/pci/pcireg.h> 441.1Ssoren#include <dev/pci/pcidevs.h> 451.17Stsutsui#include <dev/pci/pciconf.h> 461.23Stsutsui#include <dev/pci/pciide_apollo_reg.h> 471.1Ssoren 481.16Stsutsui#include <cobalt/dev/gtreg.h> 491.16Stsutsui 501.1Ssoren/* 511.1Ssoren * PCI doesn't have any special needs; just use 521.1Ssoren * the generic versions of these functions. 531.1Ssoren */ 541.36Sskrllstruct mips_bus_dma_tag pci_bus_dma_tag = { 551.36Sskrll ._dmamap_ops = _BUS_DMAMAP_OPS_INITIALIZER, 561.36Sskrll ._dmamem_ops = _BUS_DMAMEM_OPS_INITIALIZER, 571.36Sskrll ._dmatag_ops = _BUS_DMATAG_OPS_INITIALIZER, 581.1Ssoren}; 591.1Ssoren 601.1Ssorenvoid 611.33Schspci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba) 621.1Ssoren{ 631.1Ssoren /* XXX */ 641.1Ssoren 651.1Ssoren return; 661.1Ssoren} 671.1Ssoren 681.1Ssorenint 691.20Stsutsuipci_bus_maxdevs(pci_chipset_tag_t pc, int busno) 701.1Ssoren{ 711.20Stsutsui 721.6Ssoren return 32; 731.1Ssoren} 741.1Ssoren 751.1Ssorenpcitag_t 761.20Stsutsuipci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function) 771.1Ssoren{ 781.20Stsutsui 791.1Ssoren return (bus << 16) | (device << 11) | (function << 8); 801.1Ssoren} 811.1Ssoren 821.1Ssorenvoid 831.20Stsutsuipci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp) 841.1Ssoren{ 851.20Stsutsui 861.1Ssoren if (bp != NULL) 871.1Ssoren *bp = (tag >> 16) & 0xff; 881.1Ssoren if (dp != NULL) 891.1Ssoren *dp = (tag >> 11) & 0x1f; 901.1Ssoren if (fp != NULL) 911.1Ssoren *fp = (tag >> 8) & 0x07; 921.1Ssoren} 931.1Ssoren 941.1Ssorenpcireg_t 951.20Stsutsuipci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg) 961.1Ssoren{ 971.1Ssoren pcireg_t data; 981.6Ssoren int bus, dev, func; 991.14Stsutsui 1001.28Smatt KASSERT(pc != NULL); 1011.28Smatt 1021.6Ssoren pci_decompose_tag(pc, tag, &bus, &dev, &func); 1031.6Ssoren 1041.6Ssoren /* 1051.6Ssoren * 2700 hardware wedges on accesses to device 6. 1061.6Ssoren */ 1071.6Ssoren if (bus == 0 && dev == 6) 1081.6Ssoren return 0; 1091.6Ssoren /* 1101.6Ssoren * 2800 hardware wedges on accesses to device 31. 1111.6Ssoren */ 1121.6Ssoren if (bus == 0 && dev == 31) 1131.6Ssoren return 0; 1141.1Ssoren 1151.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 1161.21Stsutsui PCICFG_ENABLE | tag | reg); 1171.16Stsutsui data = bus_space_read_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA); 1181.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0); 1191.1Ssoren 1201.1Ssoren return data; 1211.1Ssoren} 1221.1Ssoren 1231.1Ssorenvoid 1241.20Stsutsuipci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data) 1251.1Ssoren{ 1261.1Ssoren 1271.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 1281.21Stsutsui PCICFG_ENABLE | tag | reg); 1291.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA, data); 1301.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0); 1311.1Ssoren} 1321.1Ssoren 1331.1Ssorenint 1341.29Sdyoungpci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp) 1351.1Ssoren{ 1361.10Ssommerfe pci_chipset_tag_t pc = pa->pa_pc; 1371.11Stsutsui pcitag_t intrtag = pa->pa_intrtag; 1381.10Ssommerfe int pin = pa->pa_intrpin; 1391.10Ssommerfe int line = pa->pa_intrline; 1401.5Ssoren int bus, dev, func; 1411.1Ssoren 1421.5Ssoren pci_decompose_tag(pc, intrtag, &bus, &dev, &func); 1431.5Ssoren 1441.5Ssoren /* 1451.26Stsutsui * The interrupt lines of the internal Tulips are connected 1461.5Ssoren * directly to the CPU. 1471.5Ssoren */ 1481.25Stsutsui if (cobalt_id == COBALT_ID_QUBE2700) { 1491.26Stsutsui if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) { 1501.26Stsutsui /* tulip is connected to CPU INT2 on Qube2700 */ 1511.26Stsutsui *ihp = NICU_INT + 2; 1521.26Stsutsui return 0; 1531.26Stsutsui } 1541.25Stsutsui } else { 1551.26Stsutsui if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) { 1561.26Stsutsui /* the primary tulip is connected to CPU INT1 */ 1571.26Stsutsui *ihp = NICU_INT + 1; 1581.26Stsutsui return 0; 1591.26Stsutsui } 1601.26Stsutsui if (bus == 0 && dev == 12 && pin == PCI_INTERRUPT_PIN_A) { 1611.26Stsutsui /* the secondary tulip is connected to CPU INT2 */ 1621.26Stsutsui *ihp = NICU_INT + 2; 1631.26Stsutsui return 0; 1641.26Stsutsui } 1651.25Stsutsui } 1661.1Ssoren 1671.26Stsutsui /* sanity check */ 1681.26Stsutsui if (line == 0 || line >= NICU_INT) 1691.26Stsutsui return -1; 1701.26Stsutsui 1711.26Stsutsui *ihp = line; 1721.1Ssoren return 0; 1731.1Ssoren} 1741.1Ssoren 1751.1Ssorenconst char * 1761.35Schristospci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf, size_t len) 1771.1Ssoren{ 1781.26Stsutsui if (ih >= NICU_INT) 1791.35Schristos snprintf(buf, len, "level %d", ih - NICU_INT); 1801.4Ssoren else 1811.35Schristos snprintf(buf, len, "irq %d", ih); 1821.1Ssoren 1831.35Schristos return buf; 1841.7Scgd} 1851.7Scgd 1861.7Scgdconst struct evcnt * 1871.20Stsutsuipci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih) 1881.7Scgd{ 1891.7Scgd 1901.7Scgd /* XXX for now, no evcnt parent reported */ 1911.7Scgd return NULL; 1921.1Ssoren} 1931.1Ssoren 1941.27Sadint 1951.27Sadpci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih, 1961.27Sad int attr, uint64_t data) 1971.27Sad{ 1981.27Sad 1991.27Sad switch (attr) { 2001.27Sad case PCI_INTR_MPSAFE: 2011.27Sad return 0; 2021.27Sad default: 2031.27Sad return ENODEV; 2041.27Sad } 2051.27Sad} 2061.27Sad 2071.1Ssorenvoid * 2081.20Stsutsuipci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level, 2091.20Stsutsui int (*func)(void *), void *arg) 2101.1Ssoren{ 2111.20Stsutsui 2121.26Stsutsui if (ih >= NICU_INT) 2131.26Stsutsui return cpu_intr_establish(ih - NICU_INT, level, func, arg); 2141.4Ssoren else 2151.4Ssoren return icu_intr_establish(ih, IST_LEVEL, level, func, arg); 2161.1Ssoren} 2171.1Ssoren 2181.1Ssorenvoid 2191.20Stsutsuipci_intr_disestablish(pci_chipset_tag_t pc, void *cookie) 2201.1Ssoren{ 2211.20Stsutsui 2221.12Saugustss /* Try both, only the valid one will disestablish. */ 2231.12Saugustss cpu_intr_disestablish(cookie); 2241.12Saugustss icu_intr_disestablish(cookie); 2251.1Ssoren} 2261.17Stsutsui 2271.17Stsutsuivoid 2281.17Stsutsuipci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz, 2291.17Stsutsui int *iline) 2301.17Stsutsui{ 2311.17Stsutsui 2321.26Stsutsui /* 2331.26Stsutsui * Use irq 9 on all devices on the Qube's PCI slot. 2341.26Stsutsui * XXX doesn't handle devices over PCI-PCI bridges 2351.26Stsutsui */ 2361.26Stsutsui if (bus == 0 && dev == 10 && pin != PCI_INTERRUPT_PIN_NONE) 2371.26Stsutsui *iline = 9; 2381.17Stsutsui} 2391.17Stsutsui 2401.17Stsutsuiint 2411.17Stsutsuipci_conf_hook(pci_chipset_tag_t pc, int bus, int dev, int func, pcireg_t id) 2421.17Stsutsui{ 2431.17Stsutsui 2441.22Stsutsui /* ignore bogus IDs */ 2451.22Stsutsui if (PCI_VENDOR(id) == 0) 2461.22Stsutsui return 0; 2471.22Stsutsui 2481.22Stsutsui /* 2700 hardware wedges on accesses to device 6. */ 2491.22Stsutsui if (bus == 0 && dev == 6) 2501.22Stsutsui return 0; 2511.22Stsutsui 2521.22Stsutsui /* 2800 hardware wedges on accesses to device 31. */ 2531.22Stsutsui if (bus == 0 && dev == 31) 2541.22Stsutsui return 0; 2551.22Stsutsui 2561.30Stsutsui /* Don't configure the bridge and PCI probe. */ 2571.24Sriz if (PCI_VENDOR(id) == PCI_VENDOR_MARVELL && 2581.24Sriz PCI_PRODUCT(id) == PCI_PRODUCT_MARVELL_GT64011) 2591.17Stsutsui return 0; 2601.17Stsutsui 2611.23Stsutsui /* Don't configure on-board VIA VT82C586 (pcib, uhci) */ 2621.23Stsutsui if (bus == 0 && dev == 9 && (func == 0 || func == 2)) 2631.17Stsutsui return 0; 2641.17Stsutsui 2651.23Stsutsui /* Enable viaide secondary port. Some firmware doesn't enable it. */ 2661.23Stsutsui if (bus == 0 && dev == 9 && func == 1) { 2671.23Stsutsui pcitag_t tag; 2681.23Stsutsui pcireg_t csr; 2691.23Stsutsui 2701.23Stsutsui#define APO_VIAIDECONF (APO_VIA_REGBASE + 0x00) 2711.23Stsutsui 2721.23Stsutsui tag = pci_make_tag(pc, bus, dev, func); 2731.23Stsutsui csr = pci_conf_read(pc, tag, APO_VIAIDECONF); 2741.23Stsutsui pci_conf_write(pc, tag, APO_VIAIDECONF, 2751.23Stsutsui csr | APO_IDECONF_EN(1)); 2761.23Stsutsui } 2771.19Sgdamore return PCI_CONF_DEFAULT & ~(PCI_COMMAND_SERR_ENABLE | 2781.19Sgdamore PCI_COMMAND_PARITY_ENABLE); 2791.17Stsutsui} 280