pcib.c revision 1.5
1/* $NetBSD: pcib.c,v 1.5 2002/09/27 20:31:19 thorpej 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/types.h> 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/device.h> 32#include <sys/malloc.h> 33 34#include <machine/cpu.h> 35#include <machine/bus.h> 36#include <machine/autoconf.h> 37#include <machine/intr.h> 38#include <machine/intr_machdep.h> 39 40#include <dev/pci/pcivar.h> 41#include <dev/pci/pcireg.h> 42#include <dev/pci/pcidevs.h> 43 44#include <dev/isa/isareg.h> 45 46static int pcib_match(struct device *, struct cfdata *, void *); 47static void pcib_attach(struct device *, struct device *, void *); 48static int icu_intr(void *); 49 50const struct cfattach pcib_ca = { 51 sizeof(struct device), pcib_match, pcib_attach 52}; 53 54static struct cobalt_intr icu[IO_ICUSIZE]; 55 56static int 57pcib_match(parent, match, aux) 58 struct device *parent; 59 struct cfdata *match; 60 void *aux; 61{ 62 struct pci_attach_args *pa = aux; 63 64 if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH) && 65 (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT82C586_ISA)) 66 return 1; 67 68 return 0; 69} 70 71static void 72pcib_attach(parent, self, aux) 73 struct device *parent; 74 struct device *self; 75 void *aux; 76{ 77 struct pci_attach_args *pa = aux; 78 char devinfo[256]; 79 80 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo); 81 printf("\n%s: %s, rev %d\n", self->dv_xname, devinfo, 82 PCI_REVISION(pa->pa_class)); 83 84 /* 85 * Initialize ICU. Since we block all these interrupts with 86 * splbio(), we can just enable all of them all the time here. 87 */ 88 *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1) = 0x10; 89 *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1+1) = 0xff; 90 *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2) = 0x10; 91 *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2+1) = 0xff; 92 wbflush(); 93 94 cpu_intr_establish(4, IPL_NONE, icu_intr, NULL); 95} 96 97void * 98icu_intr_establish(irq, type, level, func, arg) 99 int irq; 100 int type; 101 int level; 102 int (*func)(void *); 103 void *arg; 104{ 105 int i; 106 107 for (i = 0; i < IO_ICUSIZE; i++) { 108 if (icu[i].func == NULL) { 109 icu[i].cookie_type = COBALT_COOKIE_TYPE_ICU; 110 icu[i].func = func; 111 icu[i].arg = arg; 112 return &icu[i]; 113 } 114 } 115 116 panic("too many IRQs"); 117} 118 119void 120icu_intr_disestablish(cookie) 121 void *cookie; 122{ 123 struct cobalt_intr *p = cookie; 124 125 if (p->cookie_type == COBALT_COOKIE_TYPE_ICU) { 126 p->func = NULL; 127 p->arg = NULL; 128 } 129} 130 131int 132icu_intr(arg) 133 void *arg; 134{ 135 int i; 136 137 for (i = 0; i < IO_ICUSIZE; i++) { 138 if (icu[i].func == NULL) 139 return 0; 140 141 (*icu[i].func)(icu[i].arg); 142 } 143 144 return 0; 145} 146