pci_machdep.c revision 1.13
1/* $NetBSD: pci_machdep.c,v 1.13 2003/07/15 01:29:23 lukem Exp $ */ 2 3/* 4 * Copyright (c) 2000 Soren S. Jorvang. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions, and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> 29__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.13 2003/07/15 01:29:23 lukem Exp $"); 30 31#include <sys/types.h> 32#include <sys/param.h> 33#include <sys/time.h> 34#include <sys/systm.h> 35#include <sys/errno.h> 36#include <sys/device.h> 37 38#define _COBALT_BUS_DMA_PRIVATE 39#include <machine/bus.h> 40#include <machine/intr.h> 41#include <machine/intr_machdep.h> 42 43#include <dev/pci/pcivar.h> 44#include <dev/pci/pcireg.h> 45#include <dev/pci/pcidevs.h> 46 47/* 48 * PCI doesn't have any special needs; just use 49 * the generic versions of these functions. 50 */ 51struct cobalt_bus_dma_tag pci_bus_dma_tag = { 52 _bus_dmamap_create, 53 _bus_dmamap_destroy, 54 _bus_dmamap_load, 55 _bus_dmamap_load_mbuf, 56 _bus_dmamap_load_uio, 57 _bus_dmamap_load_raw, 58 _bus_dmamap_unload, 59 _bus_dmamap_sync, 60 _bus_dmamem_alloc, 61 _bus_dmamem_free, 62 _bus_dmamem_map, 63 _bus_dmamem_unmap, 64 _bus_dmamem_mmap, 65}; 66 67void 68pci_attach_hook(parent, self, pba) 69 struct device *parent, *self; 70 struct pcibus_attach_args *pba; 71{ 72 /* XXX */ 73 74 return; 75} 76 77int 78pci_bus_maxdevs(pc, busno) 79 pci_chipset_tag_t pc; 80 int busno; 81{ 82 return 32; 83} 84 85pcitag_t 86pci_make_tag(pc, bus, device, function) 87 pci_chipset_tag_t pc; 88 int bus, device, function; 89{ 90 return (bus << 16) | (device << 11) | (function << 8); 91} 92 93void 94pci_decompose_tag(pc, tag, bp, dp, fp) 95 pci_chipset_tag_t pc; 96 pcitag_t tag; 97 int *bp, *dp, *fp; 98{ 99 if (bp != NULL) 100 *bp = (tag >> 16) & 0xff; 101 if (dp != NULL) 102 *dp = (tag >> 11) & 0x1f; 103 if (fp != NULL) 104 *fp = (tag >> 8) & 0x07; 105} 106 107#define PCI_CFG_ADDR ((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x14000cf8)) 108#define PCI_CFG_DATA ((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x14000cfc)) 109 110pcireg_t 111pci_conf_read(pc, tag, reg) 112 pci_chipset_tag_t pc; 113 pcitag_t tag; 114 int reg; 115{ 116 pcireg_t data; 117 int bus, dev, func; 118 119 pci_decompose_tag(pc, tag, &bus, &dev, &func); 120 121 /* 122 * 2700 hardware wedges on accesses to device 6. 123 */ 124 if (bus == 0 && dev == 6) 125 return 0; 126 /* 127 * 2800 hardware wedges on accesses to device 31. 128 */ 129 if (bus == 0 && dev == 31) 130 return 0; 131 132 *PCI_CFG_ADDR = 0x80000000 | tag | reg; 133 data = *PCI_CFG_DATA; 134 *PCI_CFG_ADDR = 0; 135 136 return data; 137} 138 139void 140pci_conf_write(pc, tag, reg, data) 141 pci_chipset_tag_t pc; 142 pcitag_t tag; 143 int reg; 144 pcireg_t data; 145{ 146 *PCI_CFG_ADDR = 0x80000000 | tag | reg; 147 *PCI_CFG_DATA = data; 148 *PCI_CFG_ADDR = 0; 149 150 return; 151} 152 153int 154pci_intr_map(pa, ihp) 155 struct pci_attach_args *pa; 156 pci_intr_handle_t *ihp; 157{ 158 pci_chipset_tag_t pc = pa->pa_pc; 159 pcitag_t intrtag = pa->pa_intrtag; 160 int pin = pa->pa_intrpin; 161 int line = pa->pa_intrline; 162 int bus, dev, func; 163 164 pci_decompose_tag(pc, intrtag, &bus, &dev, &func); 165 166 /* 167 * The interrupt lines of the two Tulips are connected 168 * directly to the CPU. 169 */ 170 171 if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) 172 *ihp = 16 + 1; 173 else if (bus == 0 && dev == 12 && pin == PCI_INTERRUPT_PIN_A) 174 *ihp = 16 + 2; 175 else 176 *ihp = line; 177 178 return 0; 179} 180 181const char * 182pci_intr_string(pc, ih) 183 pci_chipset_tag_t pc; 184 pci_intr_handle_t ih; 185{ 186 static char irqstr[8]; 187 188 if (ih >= 16) 189 sprintf(irqstr, "level %d", ih - 16); 190 else 191 sprintf(irqstr, "irq %d", ih); 192 193 return irqstr; 194} 195 196const struct evcnt * 197pci_intr_evcnt(pc, ih) 198 pci_chipset_tag_t pc; 199 pci_intr_handle_t ih; 200{ 201 202 /* XXX for now, no evcnt parent reported */ 203 return NULL; 204} 205 206void * 207pci_intr_establish(pc, ih, level, func, arg) 208 pci_chipset_tag_t pc; 209 pci_intr_handle_t ih; 210 int level, (*func)(void *); 211 void *arg; 212{ 213 if (ih >= 16) 214 return cpu_intr_establish(ih - 16, level, func, arg); 215 else 216 return icu_intr_establish(ih, IST_LEVEL, level, func, arg); 217} 218 219void 220pci_intr_disestablish(pc, cookie) 221 pci_chipset_tag_t pc; 222 void *cookie; 223{ 224 /* Try both, only the valid one will disestablish. */ 225 cpu_intr_disestablish(cookie); 226 icu_intr_disestablish(cookie); 227} 228