pci_machdep.c revision 1.32
11.32Smatt/* $NetBSD: pci_machdep.c,v 1.32 2011/07/09 16:09:02 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.32Smatt__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.32 2011/07/09 16:09:02 matt Exp $"); 301.32Smatt 311.32Smatt#define _COBALT_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.1Ssorenstruct cobalt_bus_dma_tag pci_bus_dma_tag = { 551.14Stsutsui _bus_dmamap_create, 561.1Ssoren _bus_dmamap_destroy, 571.1Ssoren _bus_dmamap_load, 581.1Ssoren _bus_dmamap_load_mbuf, 591.1Ssoren _bus_dmamap_load_uio, 601.1Ssoren _bus_dmamap_load_raw, 611.1Ssoren _bus_dmamap_unload, 621.1Ssoren _bus_dmamap_sync, 631.1Ssoren _bus_dmamem_alloc, 641.1Ssoren _bus_dmamem_free, 651.1Ssoren _bus_dmamem_map, 661.1Ssoren _bus_dmamem_unmap, 671.1Ssoren _bus_dmamem_mmap, 681.1Ssoren}; 691.1Ssoren 701.1Ssorenvoid 711.20Stsutsuipci_attach_hook(struct device *parent, struct device *self, 721.20Stsutsui struct pcibus_attach_args *pba) 731.1Ssoren{ 741.1Ssoren /* XXX */ 751.1Ssoren 761.1Ssoren return; 771.1Ssoren} 781.1Ssoren 791.1Ssorenint 801.20Stsutsuipci_bus_maxdevs(pci_chipset_tag_t pc, int busno) 811.1Ssoren{ 821.20Stsutsui 831.6Ssoren return 32; 841.1Ssoren} 851.1Ssoren 861.1Ssorenpcitag_t 871.20Stsutsuipci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function) 881.1Ssoren{ 891.20Stsutsui 901.1Ssoren return (bus << 16) | (device << 11) | (function << 8); 911.1Ssoren} 921.1Ssoren 931.1Ssorenvoid 941.20Stsutsuipci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp) 951.1Ssoren{ 961.20Stsutsui 971.1Ssoren if (bp != NULL) 981.1Ssoren *bp = (tag >> 16) & 0xff; 991.1Ssoren if (dp != NULL) 1001.1Ssoren *dp = (tag >> 11) & 0x1f; 1011.1Ssoren if (fp != NULL) 1021.1Ssoren *fp = (tag >> 8) & 0x07; 1031.1Ssoren} 1041.1Ssoren 1051.1Ssorenpcireg_t 1061.20Stsutsuipci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg) 1071.1Ssoren{ 1081.1Ssoren pcireg_t data; 1091.6Ssoren int bus, dev, func; 1101.14Stsutsui 1111.28Smatt KASSERT(pc != NULL); 1121.28Smatt 1131.6Ssoren pci_decompose_tag(pc, tag, &bus, &dev, &func); 1141.6Ssoren 1151.6Ssoren /* 1161.6Ssoren * 2700 hardware wedges on accesses to device 6. 1171.6Ssoren */ 1181.6Ssoren if (bus == 0 && dev == 6) 1191.6Ssoren return 0; 1201.6Ssoren /* 1211.6Ssoren * 2800 hardware wedges on accesses to device 31. 1221.6Ssoren */ 1231.6Ssoren if (bus == 0 && dev == 31) 1241.6Ssoren return 0; 1251.1Ssoren 1261.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 1271.21Stsutsui PCICFG_ENABLE | tag | reg); 1281.16Stsutsui data = bus_space_read_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA); 1291.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0); 1301.1Ssoren 1311.1Ssoren return data; 1321.1Ssoren} 1331.1Ssoren 1341.1Ssorenvoid 1351.20Stsutsuipci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data) 1361.1Ssoren{ 1371.1Ssoren 1381.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 1391.21Stsutsui PCICFG_ENABLE | tag | reg); 1401.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA, data); 1411.16Stsutsui bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0); 1421.1Ssoren} 1431.1Ssoren 1441.1Ssorenint 1451.29Sdyoungpci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp) 1461.1Ssoren{ 1471.10Ssommerfe pci_chipset_tag_t pc = pa->pa_pc; 1481.11Stsutsui pcitag_t intrtag = pa->pa_intrtag; 1491.10Ssommerfe int pin = pa->pa_intrpin; 1501.10Ssommerfe int line = pa->pa_intrline; 1511.5Ssoren int bus, dev, func; 1521.1Ssoren 1531.5Ssoren pci_decompose_tag(pc, intrtag, &bus, &dev, &func); 1541.5Ssoren 1551.5Ssoren /* 1561.26Stsutsui * The interrupt lines of the internal Tulips are connected 1571.5Ssoren * directly to the CPU. 1581.5Ssoren */ 1591.25Stsutsui if (cobalt_id == COBALT_ID_QUBE2700) { 1601.26Stsutsui if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) { 1611.26Stsutsui /* tulip is connected to CPU INT2 on Qube2700 */ 1621.26Stsutsui *ihp = NICU_INT + 2; 1631.26Stsutsui return 0; 1641.26Stsutsui } 1651.25Stsutsui } else { 1661.26Stsutsui if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) { 1671.26Stsutsui /* the primary tulip is connected to CPU INT1 */ 1681.26Stsutsui *ihp = NICU_INT + 1; 1691.26Stsutsui return 0; 1701.26Stsutsui } 1711.26Stsutsui if (bus == 0 && dev == 12 && pin == PCI_INTERRUPT_PIN_A) { 1721.26Stsutsui /* the secondary tulip is connected to CPU INT2 */ 1731.26Stsutsui *ihp = NICU_INT + 2; 1741.26Stsutsui return 0; 1751.26Stsutsui } 1761.25Stsutsui } 1771.1Ssoren 1781.26Stsutsui /* sanity check */ 1791.26Stsutsui if (line == 0 || line >= NICU_INT) 1801.26Stsutsui return -1; 1811.26Stsutsui 1821.26Stsutsui *ihp = line; 1831.1Ssoren return 0; 1841.1Ssoren} 1851.1Ssoren 1861.1Ssorenconst char * 1871.20Stsutsuipci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih) 1881.1Ssoren{ 1891.4Ssoren static char irqstr[8]; 1901.4Ssoren 1911.26Stsutsui if (ih >= NICU_INT) 1921.26Stsutsui sprintf(irqstr, "level %d", ih - NICU_INT); 1931.4Ssoren else 1941.4Ssoren sprintf(irqstr, "irq %d", ih); 1951.1Ssoren 1961.1Ssoren return irqstr; 1971.7Scgd} 1981.7Scgd 1991.7Scgdconst struct evcnt * 2001.20Stsutsuipci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih) 2011.7Scgd{ 2021.7Scgd 2031.7Scgd /* XXX for now, no evcnt parent reported */ 2041.7Scgd return NULL; 2051.1Ssoren} 2061.1Ssoren 2071.27Sadint 2081.27Sadpci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih, 2091.27Sad int attr, uint64_t data) 2101.27Sad{ 2111.27Sad 2121.27Sad switch (attr) { 2131.27Sad case PCI_INTR_MPSAFE: 2141.27Sad return 0; 2151.27Sad default: 2161.27Sad return ENODEV; 2171.27Sad } 2181.27Sad} 2191.27Sad 2201.1Ssorenvoid * 2211.20Stsutsuipci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level, 2221.20Stsutsui int (*func)(void *), void *arg) 2231.1Ssoren{ 2241.20Stsutsui 2251.26Stsutsui if (ih >= NICU_INT) 2261.26Stsutsui return cpu_intr_establish(ih - NICU_INT, level, func, arg); 2271.4Ssoren else 2281.4Ssoren return icu_intr_establish(ih, IST_LEVEL, level, func, arg); 2291.1Ssoren} 2301.1Ssoren 2311.1Ssorenvoid 2321.20Stsutsuipci_intr_disestablish(pci_chipset_tag_t pc, void *cookie) 2331.1Ssoren{ 2341.20Stsutsui 2351.12Saugustss /* Try both, only the valid one will disestablish. */ 2361.12Saugustss cpu_intr_disestablish(cookie); 2371.12Saugustss icu_intr_disestablish(cookie); 2381.1Ssoren} 2391.17Stsutsui 2401.17Stsutsuivoid 2411.17Stsutsuipci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz, 2421.17Stsutsui int *iline) 2431.17Stsutsui{ 2441.17Stsutsui 2451.26Stsutsui /* 2461.26Stsutsui * Use irq 9 on all devices on the Qube's PCI slot. 2471.26Stsutsui * XXX doesn't handle devices over PCI-PCI bridges 2481.26Stsutsui */ 2491.26Stsutsui if (bus == 0 && dev == 10 && pin != PCI_INTERRUPT_PIN_NONE) 2501.26Stsutsui *iline = 9; 2511.17Stsutsui} 2521.17Stsutsui 2531.17Stsutsuiint 2541.17Stsutsuipci_conf_hook(pci_chipset_tag_t pc, int bus, int dev, int func, pcireg_t id) 2551.17Stsutsui{ 2561.17Stsutsui 2571.22Stsutsui /* ignore bogus IDs */ 2581.22Stsutsui if (PCI_VENDOR(id) == 0) 2591.22Stsutsui return 0; 2601.22Stsutsui 2611.22Stsutsui /* 2700 hardware wedges on accesses to device 6. */ 2621.22Stsutsui if (bus == 0 && dev == 6) 2631.22Stsutsui return 0; 2641.22Stsutsui 2651.22Stsutsui /* 2800 hardware wedges on accesses to device 31. */ 2661.22Stsutsui if (bus == 0 && dev == 31) 2671.22Stsutsui return 0; 2681.22Stsutsui 2691.30Stsutsui /* Don't configure the bridge and PCI probe. */ 2701.24Sriz if (PCI_VENDOR(id) == PCI_VENDOR_MARVELL && 2711.24Sriz PCI_PRODUCT(id) == PCI_PRODUCT_MARVELL_GT64011) 2721.17Stsutsui return 0; 2731.17Stsutsui 2741.23Stsutsui /* Don't configure on-board VIA VT82C586 (pcib, uhci) */ 2751.23Stsutsui if (bus == 0 && dev == 9 && (func == 0 || func == 2)) 2761.17Stsutsui return 0; 2771.17Stsutsui 2781.23Stsutsui /* Enable viaide secondary port. Some firmware doesn't enable it. */ 2791.23Stsutsui if (bus == 0 && dev == 9 && func == 1) { 2801.23Stsutsui pcitag_t tag; 2811.23Stsutsui pcireg_t csr; 2821.23Stsutsui 2831.23Stsutsui#define APO_VIAIDECONF (APO_VIA_REGBASE + 0x00) 2841.23Stsutsui 2851.23Stsutsui tag = pci_make_tag(pc, bus, dev, func); 2861.23Stsutsui csr = pci_conf_read(pc, tag, APO_VIAIDECONF); 2871.23Stsutsui pci_conf_write(pc, tag, APO_VIAIDECONF, 2881.23Stsutsui csr | APO_IDECONF_EN(1)); 2891.23Stsutsui } 2901.19Sgdamore return PCI_CONF_DEFAULT & ~(PCI_COMMAND_SERR_ENABLE | 2911.19Sgdamore PCI_COMMAND_PARITY_ENABLE); 2921.17Stsutsui} 293