pcib.c revision 1.13
1/* $NetBSD: pcib.c,v 1.13 2006/04/21 15:46:07 tsutsui 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.13 2006/04/21 15:46:07 tsutsui 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#define PCIB_BASE 0x10000000 /* XXX */ 49 50static int pcib_match(struct device *, struct cfdata *, void *); 51static void pcib_attach(struct device *, struct device *, void *); 52static int icu_intr(void *); 53 54CFATTACH_DECL(pcib, sizeof(struct device), 55 pcib_match, pcib_attach, NULL, NULL); 56 57static struct cobalt_intrhand icu[IO_ICUSIZE]; 58 59static int 60pcib_match(struct device *parent, struct cfdata *match, 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(struct device *parent, struct device *self, void *aux) 73{ 74 struct pci_attach_args *pa = aux; 75 char devinfo[256]; 76 77 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo)); 78 printf("\n%s: %s, rev %d\n", self->dv_xname, devinfo, 79 PCI_REVISION(pa->pa_class)); 80 81 /* 82 * Initialize ICU. Since we block all these interrupts with 83 * splbio(), we can just enable all of them all the time here. 84 */ 85 *(volatile uint8_t *)MIPS_PHYS_TO_KSEG1(PCIB_BASE + IO_ICU1) = 0x10; 86 *(volatile uint8_t *)MIPS_PHYS_TO_KSEG1(PCIB_BASE + IO_ICU1 + 1) = 0xff; 87 *(volatile uint8_t *)MIPS_PHYS_TO_KSEG1(PCIB_BASE + IO_ICU2) = 0x10; 88 *(volatile uint8_t *)MIPS_PHYS_TO_KSEG1(PCIB_BASE + IO_ICU2 + 1) = 0xff; 89 wbflush(); 90 91 cpu_intr_establish(4, IPL_NONE, icu_intr, NULL); 92} 93 94void * 95icu_intr_establish(int irq, int type, int level, int (*func)(void *), 96 void *arg) 97{ 98 int i; 99 100 for (i = 0; i < IO_ICUSIZE; i++) { 101 if (icu[i].ih_func == NULL) { 102 icu[i].cookie_type = COBALT_COOKIE_TYPE_ICU; 103 icu[i].ih_func = func; 104 icu[i].ih_arg = arg; 105 return &icu[i]; 106 } 107 } 108 109 panic("too many IRQs"); 110} 111 112void 113icu_intr_disestablish(void *cookie) 114{ 115 struct cobalt_intrhand *ih = cookie; 116 117 if (ih->cookie_type == COBALT_COOKIE_TYPE_ICU) { 118 ih->ih_func = NULL; 119 ih->ih_arg = NULL; 120 } 121} 122 123int 124icu_intr(void *arg) 125{ 126 int i; 127 128 for (i = 0; i < IO_ICUSIZE; i++) { 129 if (icu[i].ih_func == NULL) 130 return 0; 131 132 (*icu[i].ih_func)(icu[i].ih_arg); 133 } 134 135 return 0; 136} 137