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