pcib.c revision 1.2
11.2Ssoren/* $NetBSD: pcib.c,v 1.2 2000/03/31 14:51:55 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/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.1Ssoren 391.1Ssoren#include <dev/pci/pcivar.h> 401.1Ssoren#include <dev/pci/pcireg.h> 411.2Ssoren#include <dev/pci/pcidevs.h> 421.1Ssoren 431.2Ssoren#include <dev/isa/isareg.h> 441.1Ssoren 451.1Ssorenstatic int pcib_match(struct device *, struct cfdata *, void *); 461.1Ssorenstatic void pcib_attach(struct device *, struct device *, void *); 471.2Ssorenstatic int icu_intr(void *); 481.1Ssoren 491.1Ssorenstruct cfattach pcib_ca = { 501.1Ssoren sizeof(struct device), pcib_match, pcib_attach 511.1Ssoren}; 521.1Ssoren 531.2Ssorenstatic struct { 541.2Ssoren int (*func)(void *); 551.2Ssoren void *arg; 561.2Ssoren} icu[IO_ICUSIZE]; 571.2Ssoren 581.1Ssorenstatic int 591.1Ssorenpcib_match(parent, match, aux) 601.1Ssoren struct device *parent; 611.1Ssoren struct cfdata *match; 621.1Ssoren void *aux; 631.1Ssoren{ 641.1Ssoren struct pci_attach_args *pa = aux; 651.1Ssoren 661.1Ssoren if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH) && 671.1Ssoren (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT82C586_ISA)) 681.1Ssoren return 1; 691.1Ssoren 701.1Ssoren return 0; 711.1Ssoren} 721.1Ssoren 731.1Ssorenstatic void 741.1Ssorenpcib_attach(parent, self, aux) 751.1Ssoren struct device *parent; 761.1Ssoren struct device *self; 771.1Ssoren void *aux; 781.1Ssoren{ 791.1Ssoren struct pci_attach_args *pa = aux; 801.1Ssoren char devinfo[256]; 811.1Ssoren 821.1Ssoren pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo); 831.1Ssoren printf("\n%s: %s, rev %d\n", self->dv_xname, devinfo, 841.1Ssoren PCI_REVISION(pa->pa_class)); 851.2Ssoren 861.2Ssoren /* 871.2Ssoren * Initialize ICU. Since we block all these interrupts with 881.2Ssoren * splbio(), we can just enable all of them all the time here. 891.2Ssoren */ 901.2Ssoren *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1) = 0x10; 911.2Ssoren *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1+1) = 0xff; 921.2Ssoren *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2) = 0x10; 931.2Ssoren *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2+1) = 0xff; 941.2Ssoren wbflush(); 951.2Ssoren 961.2Ssoren cpu_intr_establish(4, IPL_NONE, icu_intr, NULL); 971.2Ssoren} 981.2Ssoren 991.2Ssorenvoid * 1001.2Ssorenicu_intr_establish(irq, type, level, func, arg) 1011.2Ssoren int irq; 1021.2Ssoren int type; 1031.2Ssoren int level; 1041.2Ssoren int (*func)(void *); 1051.2Ssoren void *arg; 1061.2Ssoren{ 1071.2Ssoren int i; 1081.2Ssoren 1091.2Ssoren for (i = 0; i <= IO_ICUSIZE; i++) { 1101.2Ssoren if (i == IO_ICUSIZE) 1111.2Ssoren panic("too many IRQs"); 1121.2Ssoren 1131.2Ssoren if (icu[i].func != NULL) 1141.2Ssoren continue; 1151.2Ssoren 1161.2Ssoren icu[i].func = func; 1171.2Ssoren icu[i].arg = arg; 1181.2Ssoren break; 1191.2Ssoren } 1201.2Ssoren 1211.2Ssoren return (void *)-1; 1221.2Ssoren} 1231.2Ssoren 1241.2Ssorenint 1251.2Ssorenicu_intr(arg) 1261.2Ssoren void *arg; 1271.2Ssoren{ 1281.2Ssoren int i; 1291.2Ssoren 1301.2Ssoren for (i = 0; i < IO_ICUSIZE; i++) { 1311.2Ssoren if (icu[i].func == NULL) 1321.2Ssoren return 0; 1331.2Ssoren 1341.2Ssoren (*icu[i].func)(icu[i].arg); 1351.2Ssoren } 1361.2Ssoren 1371.2Ssoren return 0; 1381.1Ssoren} 139