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