pcib.c revision 1.12
11.12Stsutsui/* $NetBSD: pcib.c,v 1.12 2006/04/05 15:50:48 tsutsui 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.7Slukem 281.7Slukem#include <sys/cdefs.h> 291.12Stsutsui__KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.12 2006/04/05 15:50:48 tsutsui Exp $"); 301.1Ssoren 311.1Ssoren#include <sys/types.h> 321.1Ssoren#include <sys/param.h> 331.1Ssoren#include <sys/systm.h> 341.1Ssoren#include <sys/device.h> 351.2Ssoren#include <sys/malloc.h> 361.1Ssoren 371.2Ssoren#include <machine/cpu.h> 381.1Ssoren#include <machine/bus.h> 391.8Stsutsui#include <machine/autoconf.h> 401.2Ssoren#include <machine/intr.h> 411.1Ssoren 421.1Ssoren#include <dev/pci/pcivar.h> 431.1Ssoren#include <dev/pci/pcireg.h> 441.2Ssoren#include <dev/pci/pcidevs.h> 451.1Ssoren 461.2Ssoren#include <dev/isa/isareg.h> 471.1Ssoren 481.1Ssorenstatic int pcib_match(struct device *, struct cfdata *, void *); 491.1Ssorenstatic void pcib_attach(struct device *, struct device *, void *); 501.2Ssorenstatic int icu_intr(void *); 511.1Ssoren 521.6SthorpejCFATTACH_DECL(pcib, sizeof(struct device), 531.6Sthorpej pcib_match, pcib_attach, NULL, NULL); 541.1Ssoren 551.9Stsutsuistatic struct cobalt_intrhand icu[IO_ICUSIZE]; 561.2Ssoren 571.1Ssorenstatic int 581.12Stsutsuipcib_match(struct device *parent, struct cfdata *match, void *aux) 591.1Ssoren{ 601.1Ssoren struct pci_attach_args *pa = aux; 611.1Ssoren 621.1Ssoren if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH) && 631.1Ssoren (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT82C586_ISA)) 641.1Ssoren return 1; 651.1Ssoren 661.1Ssoren return 0; 671.1Ssoren} 681.1Ssoren 691.1Ssorenstatic void 701.12Stsutsuipcib_attach(struct device *parent, struct device *self, void *aux) 711.1Ssoren{ 721.1Ssoren struct pci_attach_args *pa = aux; 731.1Ssoren char devinfo[256]; 741.1Ssoren 751.10Sitojun pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo)); 761.1Ssoren printf("\n%s: %s, rev %d\n", self->dv_xname, devinfo, 771.12Stsutsui PCI_REVISION(pa->pa_class)); 781.2Ssoren 791.2Ssoren /* 801.2Ssoren * Initialize ICU. Since we block all these interrupts with 811.2Ssoren * splbio(), we can just enable all of them all the time here. 821.2Ssoren */ 831.12Stsutsui *(volatile uint8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1) = 0x10; 841.12Stsutsui *(volatile uint8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1 +1 ) = 851.12Stsutsui 0xff; 861.12Stsutsui *(volatile uint8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2) = 0x10; 871.12Stsutsui *(volatile uint8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2 + 1) = 881.12Stsutsui 0xff; 891.2Ssoren wbflush(); 901.2Ssoren 911.2Ssoren cpu_intr_establish(4, IPL_NONE, icu_intr, NULL); 921.2Ssoren} 931.2Ssoren 941.8Stsutsuivoid * 951.12Stsutsuiicu_intr_establish(int irq, int type, int level, int (*func)(void *), 961.12Stsutsui void *arg) 971.2Ssoren{ 981.2Ssoren int i; 991.2Ssoren 1001.4Saugustss for (i = 0; i < IO_ICUSIZE; i++) { 1011.9Stsutsui if (icu[i].ih_func == NULL) { 1021.4Saugustss icu[i].cookie_type = COBALT_COOKIE_TYPE_ICU; 1031.9Stsutsui icu[i].ih_func = func; 1041.9Stsutsui icu[i].ih_arg = arg; 1051.4Saugustss return &icu[i]; 1061.4Saugustss } 1071.2Ssoren } 1081.2Ssoren 1091.4Saugustss panic("too many IRQs"); 1101.3Saugustss} 1111.3Saugustss 1121.3Saugustssvoid 1131.12Stsutsuiicu_intr_disestablish(void *cookie) 1141.3Saugustss{ 1151.9Stsutsui struct cobalt_intrhand *ih = cookie; 1161.3Saugustss 1171.9Stsutsui if (ih->cookie_type == COBALT_COOKIE_TYPE_ICU) { 1181.9Stsutsui ih->ih_func = NULL; 1191.9Stsutsui ih->ih_arg = NULL; 1201.3Saugustss } 1211.2Ssoren} 1221.2Ssoren 1231.2Ssorenint 1241.12Stsutsuiicu_intr(void *arg) 1251.2Ssoren{ 1261.2Ssoren int i; 1271.2Ssoren 1281.2Ssoren for (i = 0; i < IO_ICUSIZE; i++) { 1291.9Stsutsui if (icu[i].ih_func == NULL) 1301.2Ssoren return 0; 1311.2Ssoren 1321.9Stsutsui (*icu[i].ih_func)(icu[i].ih_arg); 1331.2Ssoren } 1341.2Ssoren 1351.2Ssoren return 0; 1361.1Ssoren} 137