pci_machdep.c revision 1.6
11.6Ssoren/* $NetBSD: pci_machdep.c,v 1.6 2000/05/29 15:45:15 soren 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.1Ssoren 281.1Ssoren#include <sys/types.h> 291.1Ssoren#include <sys/param.h> 301.1Ssoren#include <sys/time.h> 311.1Ssoren#include <sys/systm.h> 321.1Ssoren#include <sys/errno.h> 331.1Ssoren#include <sys/device.h> 341.1Ssoren 351.1Ssoren#include <vm/vm.h> 361.1Ssoren#include <vm/vm_kern.h> 371.1Ssoren 381.1Ssoren#define _COBALT_BUS_DMA_PRIVATE 391.1Ssoren#include <machine/bus.h> 401.4Ssoren#include <machine/intr.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.1Ssoren 461.1Ssoren/* 471.1Ssoren * PCI doesn't have any special needs; just use 481.1Ssoren * the generic versions of these functions. 491.1Ssoren */ 501.1Ssorenstruct cobalt_bus_dma_tag pci_bus_dma_tag = { 511.1Ssoren _bus_dmamap_create, 521.1Ssoren _bus_dmamap_destroy, 531.1Ssoren _bus_dmamap_load, 541.1Ssoren _bus_dmamap_load_mbuf, 551.1Ssoren _bus_dmamap_load_uio, 561.1Ssoren _bus_dmamap_load_raw, 571.1Ssoren _bus_dmamap_unload, 581.1Ssoren _bus_dmamap_sync, 591.1Ssoren _bus_dmamem_alloc, 601.1Ssoren _bus_dmamem_free, 611.1Ssoren _bus_dmamem_map, 621.1Ssoren _bus_dmamem_unmap, 631.1Ssoren _bus_dmamem_mmap, 641.1Ssoren}; 651.1Ssoren 661.1Ssorenvoid 671.1Ssorenpci_attach_hook(parent, self, pba) 681.1Ssoren struct device *parent, *self; 691.1Ssoren struct pcibus_attach_args *pba; 701.1Ssoren{ 711.1Ssoren /* XXX */ 721.1Ssoren 731.1Ssoren return; 741.1Ssoren} 751.1Ssoren 761.1Ssorenint 771.1Ssorenpci_bus_maxdevs(pc, busno) 781.1Ssoren pci_chipset_tag_t pc; 791.1Ssoren int busno; 801.1Ssoren{ 811.6Ssoren return 32; 821.1Ssoren} 831.1Ssoren 841.1Ssorenpcitag_t 851.1Ssorenpci_make_tag(pc, bus, device, function) 861.1Ssoren pci_chipset_tag_t pc; 871.1Ssoren int bus, device, function; 881.1Ssoren{ 891.1Ssoren return (bus << 16) | (device << 11) | (function << 8); 901.1Ssoren} 911.1Ssoren 921.1Ssorenvoid 931.1Ssorenpci_decompose_tag(pc, tag, bp, dp, fp) 941.1Ssoren pci_chipset_tag_t pc; 951.1Ssoren pcitag_t tag; 961.1Ssoren int *bp, *dp, *fp; 971.1Ssoren{ 981.1Ssoren if (bp != NULL) 991.1Ssoren *bp = (tag >> 16) & 0xff; 1001.1Ssoren if (dp != NULL) 1011.1Ssoren *dp = (tag >> 11) & 0x1f; 1021.1Ssoren if (fp != NULL) 1031.1Ssoren *fp = (tag >> 8) & 0x07; 1041.1Ssoren} 1051.1Ssoren 1061.1Ssoren#define PCI_CFG_ADDR ((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x14000cf8)) 1071.1Ssoren#define PCI_CFG_DATA ((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x14000cfc)) 1081.1Ssoren 1091.1Ssorenpcireg_t 1101.1Ssorenpci_conf_read(pc, tag, reg) 1111.1Ssoren pci_chipset_tag_t pc; 1121.1Ssoren pcitag_t tag; 1131.1Ssoren int reg; 1141.1Ssoren{ 1151.1Ssoren pcireg_t data; 1161.6Ssoren int bus, dev, func; 1171.6Ssoren 1181.6Ssoren pci_decompose_tag(pc, tag, &bus, &dev, &func); 1191.6Ssoren 1201.6Ssoren /* 1211.6Ssoren * 2700 hardware wedges on accesses to device 6. 1221.6Ssoren */ 1231.6Ssoren if (bus == 0 && dev == 6) 1241.6Ssoren return 0; 1251.6Ssoren /* 1261.6Ssoren * 2800 hardware wedges on accesses to device 31. 1271.6Ssoren */ 1281.6Ssoren if (bus == 0 && dev == 31) 1291.6Ssoren return 0; 1301.1Ssoren 1311.1Ssoren *PCI_CFG_ADDR = 0x80000000 | tag | reg; 1321.1Ssoren data = *PCI_CFG_DATA; 1331.1Ssoren *PCI_CFG_ADDR = 0; 1341.1Ssoren 1351.1Ssoren return data; 1361.1Ssoren} 1371.1Ssoren 1381.1Ssorenvoid 1391.1Ssorenpci_conf_write(pc, tag, reg, data) 1401.1Ssoren pci_chipset_tag_t pc; 1411.1Ssoren pcitag_t tag; 1421.1Ssoren int reg; 1431.1Ssoren pcireg_t data; 1441.1Ssoren{ 1451.1Ssoren *PCI_CFG_ADDR = 0x80000000 | tag | reg; 1461.1Ssoren *PCI_CFG_DATA = data; 1471.1Ssoren *PCI_CFG_ADDR = 0; 1481.1Ssoren 1491.1Ssoren return; 1501.1Ssoren} 1511.1Ssoren 1521.1Ssorenint 1531.1Ssorenpci_intr_map(pc, intrtag, pin, line, ihp) 1541.1Ssoren pci_chipset_tag_t pc; 1551.1Ssoren pcitag_t intrtag; 1561.1Ssoren int pin, line; 1571.1Ssoren pci_intr_handle_t *ihp; 1581.1Ssoren{ 1591.5Ssoren int bus, dev, func; 1601.1Ssoren 1611.5Ssoren pci_decompose_tag(pc, intrtag, &bus, &dev, &func); 1621.5Ssoren 1631.5Ssoren /* 1641.5Ssoren * The interrupt lines of the two Tulips are connected 1651.5Ssoren * directly to the CPU. 1661.5Ssoren */ 1671.5Ssoren 1681.5Ssoren if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) 1691.5Ssoren *ihp = 16 + 1; 1701.5Ssoren else if (bus == 0 && dev == 12 && pin == PCI_INTERRUPT_PIN_A) 1711.5Ssoren *ihp = 16 + 2; 1721.5Ssoren else 1731.5Ssoren *ihp = line; 1741.1Ssoren 1751.1Ssoren return 0; 1761.1Ssoren} 1771.1Ssoren 1781.1Ssorenconst char * 1791.1Ssorenpci_intr_string(pc, ih) 1801.1Ssoren pci_chipset_tag_t pc; 1811.1Ssoren pci_intr_handle_t ih; 1821.1Ssoren{ 1831.4Ssoren static char irqstr[8]; 1841.4Ssoren 1851.5Ssoren if (ih >= 16) 1861.5Ssoren sprintf(irqstr, "level %d", ih - 16); 1871.4Ssoren else 1881.4Ssoren sprintf(irqstr, "irq %d", ih); 1891.1Ssoren 1901.1Ssoren return irqstr; 1911.1Ssoren} 1921.1Ssoren 1931.1Ssorenvoid * 1941.1Ssorenpci_intr_establish(pc, ih, level, func, arg) 1951.1Ssoren pci_chipset_tag_t pc; 1961.1Ssoren pci_intr_handle_t ih; 1971.1Ssoren int level, (*func)(void *); 1981.1Ssoren void *arg; 1991.1Ssoren{ 2001.5Ssoren if (ih >= 16) 2011.5Ssoren return cpu_intr_establish(ih - 16, level, func, arg); 2021.4Ssoren else 2031.4Ssoren return icu_intr_establish(ih, IST_LEVEL, level, func, arg); 2041.1Ssoren} 2051.1Ssoren 2061.1Ssorenvoid 2071.1Ssorenpci_intr_disestablish(pc, cookie) 2081.1Ssoren pci_chipset_tag_t pc; 2091.1Ssoren void *cookie; 2101.1Ssoren{ 2111.1Ssoren panic("pci_intr_disestablish: not implemented"); 2121.1Ssoren 2131.1Ssoren return; 2141.1Ssoren} 215