pci_machdep.c revision 1.1
11.1Ssoren/* $NetBSD: pci_machdep.c,v 1.1 2000/03/19 23:07:48 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.1Ssoren 411.1Ssoren#include <dev/pci/pcivar.h> 421.1Ssoren#include <dev/pci/pcireg.h> 431.1Ssoren#include <dev/pci/pcidevs.h> 441.1Ssoren 451.1Ssoren/* 461.1Ssoren * PCI doesn't have any special needs; just use 471.1Ssoren * the generic versions of these functions. 481.1Ssoren */ 491.1Ssorenstruct cobalt_bus_dma_tag pci_bus_dma_tag = { 501.1Ssoren _bus_dmamap_create, 511.1Ssoren _bus_dmamap_destroy, 521.1Ssoren _bus_dmamap_load, 531.1Ssoren _bus_dmamap_load_mbuf, 541.1Ssoren _bus_dmamap_load_uio, 551.1Ssoren _bus_dmamap_load_raw, 561.1Ssoren _bus_dmamap_unload, 571.1Ssoren _bus_dmamap_sync, 581.1Ssoren _bus_dmamem_alloc, 591.1Ssoren _bus_dmamem_free, 601.1Ssoren _bus_dmamem_map, 611.1Ssoren _bus_dmamem_unmap, 621.1Ssoren _bus_dmamem_mmap, 631.1Ssoren}; 641.1Ssoren 651.1Ssorenvoid 661.1Ssorenpci_attach_hook(parent, self, pba) 671.1Ssoren struct device *parent, *self; 681.1Ssoren struct pcibus_attach_args *pba; 691.1Ssoren{ 701.1Ssoren /* XXX */ 711.1Ssoren 721.1Ssoren return; 731.1Ssoren} 741.1Ssoren 751.1Ssorenint 761.1Ssorenpci_bus_maxdevs(pc, busno) 771.1Ssoren pci_chipset_tag_t pc; 781.1Ssoren int busno; 791.1Ssoren{ 801.1Ssoren return 31; /* Probing device 31 hangs the system. */ 811.1Ssoren} 821.1Ssoren 831.1Ssorenpcitag_t 841.1Ssorenpci_make_tag(pc, bus, device, function) 851.1Ssoren pci_chipset_tag_t pc; 861.1Ssoren int bus, device, function; 871.1Ssoren{ 881.1Ssoren return (bus << 16) | (device << 11) | (function << 8); 891.1Ssoren} 901.1Ssoren 911.1Ssorenvoid 921.1Ssorenpci_decompose_tag(pc, tag, bp, dp, fp) 931.1Ssoren pci_chipset_tag_t pc; 941.1Ssoren pcitag_t tag; 951.1Ssoren int *bp, *dp, *fp; 961.1Ssoren{ 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.1Ssoren#define PCI_CFG_ADDR ((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x14000cf8)) 1061.1Ssoren#define PCI_CFG_DATA ((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x14000cfc)) 1071.1Ssoren 1081.1Ssorenpcireg_t 1091.1Ssorenpci_conf_read(pc, tag, reg) 1101.1Ssoren pci_chipset_tag_t pc; 1111.1Ssoren pcitag_t tag; 1121.1Ssoren int reg; 1131.1Ssoren{ 1141.1Ssoren pcireg_t data; 1151.1Ssoren 1161.1Ssoren *PCI_CFG_ADDR = 0x80000000 | tag | reg; 1171.1Ssoren data = *PCI_CFG_DATA; 1181.1Ssoren *PCI_CFG_ADDR = 0; 1191.1Ssoren 1201.1Ssoren return data; 1211.1Ssoren} 1221.1Ssoren 1231.1Ssorenvoid 1241.1Ssorenpci_conf_write(pc, tag, reg, data) 1251.1Ssoren pci_chipset_tag_t pc; 1261.1Ssoren pcitag_t tag; 1271.1Ssoren int reg; 1281.1Ssoren pcireg_t data; 1291.1Ssoren{ 1301.1Ssoren *PCI_CFG_ADDR = 0x80000000 | tag | reg; 1311.1Ssoren *PCI_CFG_DATA = data; 1321.1Ssoren *PCI_CFG_ADDR = 0; 1331.1Ssoren 1341.1Ssoren return; 1351.1Ssoren} 1361.1Ssoren 1371.1Ssorenint 1381.1Ssorenpci_intr_map(pc, intrtag, pin, line, ihp) 1391.1Ssoren pci_chipset_tag_t pc; 1401.1Ssoren pcitag_t intrtag; 1411.1Ssoren int pin, line; 1421.1Ssoren pci_intr_handle_t *ihp; 1431.1Ssoren{ 1441.1Ssoren /* XXX checks XXX */ 1451.1Ssoren 1461.1Ssoren *ihp = line; 1471.1Ssoren 1481.1Ssoren return 0; 1491.1Ssoren} 1501.1Ssoren 1511.1Ssorenconst char * 1521.1Ssorenpci_intr_string(pc, ih) 1531.1Ssoren pci_chipset_tag_t pc; 1541.1Ssoren pci_intr_handle_t ih; 1551.1Ssoren{ 1561.1Ssoren static char irqstr[8]; /* 4 + 2 + NULL + sanity */ 1571.1Ssoren 1581.1Ssoren sprintf(irqstr, "irq %d", ih); 1591.1Ssoren return irqstr; 1601.1Ssoren} 1611.1Ssoren 1621.1Ssoren/* XXX */ 1631.1Ssorenextern void * intr_establish(int, int, int, int, int (*)(void *), void *); 1641.1Ssorenextern void *tlp0; 1651.1Ssoren 1661.1Ssorenvoid * 1671.1Ssorenpci_intr_establish(pc, ih, level, func, arg) 1681.1Ssoren pci_chipset_tag_t pc; 1691.1Ssoren pci_intr_handle_t ih; 1701.1Ssoren int level, (*func)(void *); 1711.1Ssoren void *arg; 1721.1Ssoren{ 1731.1Ssoren /* 1741.1Ssoren * XXX XXX XXX 1751.1Ssoren */ 1761.1Ssoren 1771.1Ssoren if (ih == 4) 1781.1Ssoren tlp0 = arg; 1791.1Ssoren 1801.1Ssoren return intr_establish(NULL, ih, IST_LEVEL, level, func, arg); 1811.1Ssoren} 1821.1Ssoren 1831.1Ssorenvoid 1841.1Ssorenpci_intr_disestablish(pc, cookie) 1851.1Ssoren pci_chipset_tag_t pc; 1861.1Ssoren void *cookie; 1871.1Ssoren{ 1881.1Ssoren panic("pci_intr_disestablish: not implemented"); 1891.1Ssoren 1901.1Ssoren return; 1911.1Ssoren} 192