pcib.c revision 1.3
11.3Saugustss/* $NetBSD: pcib.c,v 1.3 2002/01/13 23:02:35 augustss 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/systm.h> 311.1Ssoren#include <sys/device.h> 321.2Ssoren#include <sys/malloc.h> 331.1Ssoren 341.2Ssoren#include <machine/cpu.h> 351.1Ssoren#include <machine/bus.h> 361.2Ssoren#include <machine/autoconf.h> 371.2Ssoren#include <machine/intr.h> 381.3Saugustss#include <machine/intr_machdep.h> 391.1Ssoren 401.1Ssoren#include <dev/pci/pcivar.h> 411.1Ssoren#include <dev/pci/pcireg.h> 421.2Ssoren#include <dev/pci/pcidevs.h> 431.1Ssoren 441.2Ssoren#include <dev/isa/isareg.h> 451.1Ssoren 461.1Ssorenstatic int pcib_match(struct device *, struct cfdata *, void *); 471.1Ssorenstatic void pcib_attach(struct device *, struct device *, void *); 481.2Ssorenstatic int icu_intr(void *); 491.1Ssoren 501.1Ssorenstruct cfattach pcib_ca = { 511.1Ssoren sizeof(struct device), pcib_match, pcib_attach 521.1Ssoren}; 531.1Ssoren 541.3Saugustssstatic struct cobalt_intr icu[IO_ICUSIZE]; 551.2Ssoren 561.1Ssorenstatic int 571.1Ssorenpcib_match(parent, match, aux) 581.1Ssoren struct device *parent; 591.1Ssoren struct cfdata *match; 601.1Ssoren void *aux; 611.1Ssoren{ 621.1Ssoren struct pci_attach_args *pa = aux; 631.1Ssoren 641.1Ssoren if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH) && 651.1Ssoren (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT82C586_ISA)) 661.1Ssoren return 1; 671.1Ssoren 681.1Ssoren return 0; 691.1Ssoren} 701.1Ssoren 711.1Ssorenstatic void 721.1Ssorenpcib_attach(parent, self, aux) 731.1Ssoren struct device *parent; 741.1Ssoren struct device *self; 751.1Ssoren void *aux; 761.1Ssoren{ 771.1Ssoren struct pci_attach_args *pa = aux; 781.1Ssoren char devinfo[256]; 791.1Ssoren 801.1Ssoren pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo); 811.1Ssoren printf("\n%s: %s, rev %d\n", self->dv_xname, devinfo, 821.1Ssoren PCI_REVISION(pa->pa_class)); 831.2Ssoren 841.2Ssoren /* 851.2Ssoren * Initialize ICU. Since we block all these interrupts with 861.2Ssoren * splbio(), we can just enable all of them all the time here. 871.2Ssoren */ 881.2Ssoren *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1) = 0x10; 891.2Ssoren *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1+1) = 0xff; 901.2Ssoren *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2) = 0x10; 911.2Ssoren *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2+1) = 0xff; 921.2Ssoren wbflush(); 931.2Ssoren 941.2Ssoren cpu_intr_establish(4, IPL_NONE, icu_intr, NULL); 951.2Ssoren} 961.2Ssoren 971.2Ssorenvoid * 981.2Ssorenicu_intr_establish(irq, type, level, func, arg) 991.2Ssoren int irq; 1001.2Ssoren int type; 1011.2Ssoren int level; 1021.2Ssoren int (*func)(void *); 1031.2Ssoren void *arg; 1041.2Ssoren{ 1051.2Ssoren int i; 1061.2Ssoren 1071.2Ssoren for (i = 0; i <= IO_ICUSIZE; i++) { 1081.2Ssoren if (i == IO_ICUSIZE) 1091.2Ssoren panic("too many IRQs"); 1101.2Ssoren 1111.2Ssoren if (icu[i].func != NULL) 1121.2Ssoren continue; 1131.2Ssoren 1141.3Saugustss icu[i].cookie_type = COBALT_COOKIE_TYPE_ICU; 1151.2Ssoren icu[i].func = func; 1161.2Ssoren icu[i].arg = arg; 1171.2Ssoren break; 1181.2Ssoren } 1191.2Ssoren 1201.2Ssoren return (void *)-1; 1211.3Saugustss} 1221.3Saugustss 1231.3Saugustssvoid 1241.3Saugustssicu_intr_disestablish(cookie) 1251.3Saugustss void *cookie; 1261.3Saugustss{ 1271.3Saugustss struct cobalt_intr *p = cookie; 1281.3Saugustss 1291.3Saugustss if (p->cookie_type == COBALT_COOKIE_TYPE_ICU) { 1301.3Saugustss p->func = NULL; 1311.3Saugustss p->arg = NULL; 1321.3Saugustss } 1331.2Ssoren} 1341.2Ssoren 1351.2Ssorenint 1361.2Ssorenicu_intr(arg) 1371.2Ssoren void *arg; 1381.2Ssoren{ 1391.2Ssoren int i; 1401.2Ssoren 1411.2Ssoren for (i = 0; i < IO_ICUSIZE; i++) { 1421.2Ssoren if (icu[i].func == NULL) 1431.2Ssoren return 0; 1441.2Ssoren 1451.2Ssoren (*icu[i].func)(icu[i].arg); 1461.2Ssoren } 1471.2Ssoren 1481.2Ssoren return 0; 1491.1Ssoren} 150