1 /* $NetBSD: ixdp425_pci.c,v 1.1 2003/05/24 01:59:32 ichiro Exp $ */ 2 /* 3 * Copyright (c) 2003 4 * Ichiro FUKUHARA <ichiro@ichiro.org>. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Ichiro FUKUHARA. 18 * 4. The name of the company nor the name of the author may be used to 19 * endorse or promote products derived from this software without specific 20 * prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR 26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 #include <sys/cdefs.h> 36 __KERNEL_RCSID(0, "$NetBSD: ixdp425_pci.c,v 1.1 2003/05/24 01:59:32 ichiro Exp $"); 37 38 /* 39 * IXDP425 PCI interrupt support. 40 */ 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/device.h> 45 46 #include <machine/autoconf.h> 47 #include <machine/bus.h> 48 49 #include <evbarm/ixdp425/ixdp425reg.h> 50 #include <evbarm/ixdp425/ixdp425var.h> 51 52 #include <arm/xscale/ixp425reg.h> 53 #include <arm/xscale/ixp425var.h> 54 55 #include <dev/pci/pcidevs.h> 56 #include <dev/pci/ppbreg.h> 57 58 int ixdp425_pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); 59 const char *ixdp425_pci_intr_string(void *, pci_intr_handle_t); 60 const struct evcnt *ixdp425_pci_intr_evcnt(void *, pci_intr_handle_t); 61 void *ixdp425_pci_intr_establish(void *, pci_intr_handle_t, int, 62 int (*func)(void *), void *); 63 void ixdp425_pci_intr_disestablish(void *, void *); 64 65 void 66 ixdp425_pci_init(pci_chipset_tag_t pc, void *cookie) 67 { 68 pc->pc_intr_v = cookie; 69 pc->pc_intr_map = ixdp425_pci_intr_map; 70 pc->pc_intr_string = ixdp425_pci_intr_string; 71 pc->pc_intr_evcnt = ixdp425_pci_intr_evcnt; 72 pc->pc_intr_establish = ixdp425_pci_intr_establish; 73 pc->pc_intr_disestablish = ixdp425_pci_intr_disestablish; 74 } 75 76 int 77 ixdp425_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp) 78 { 79 int pin = pa->pa_intrpin; 80 81 #ifdef PCI_DEBUG 82 void *v = pa->pa_pc; 83 int line = pa->pa_intrline; 84 int dev=pa->pa_device; 85 pcitag_t intrtag = pa->pa_intrtag; 86 87 printf("ixdp425_pci_intr_map: v=%p, tag=%08lx intrpin=%d line=%d dev=%d\n", 88 v, intrtag, pin, line, dev); 89 #endif 90 91 switch (pin) { 92 case 1: 93 *ihp = PCI_INT_A; 94 return (0); 95 case 2: 96 *ihp = PCI_INT_B; 97 return (0); 98 case 3: 99 *ihp = PCI_INT_C; 100 return (0); 101 case 4: 102 *ihp = PCI_INT_D; 103 return (0); 104 default: 105 #ifdef PCI_DEBUG 106 printf("ixdp425_pci_intr_map: no mapping for %d/%d/%d\n", 107 pa->pa_bus, pa->pa_device, pa->pa_function); 108 #endif 109 return (1); 110 } 111 112 return (0); 113 } 114 115 const char * 116 ixdp425_pci_intr_string(void *v, pci_intr_handle_t ih) 117 { 118 static char irqstr[IRQNAMESIZE]; 119 120 sprintf(irqstr, "ixp425 irq %ld", ih); 121 return (irqstr); 122 } 123 124 const struct evcnt * 125 ixdp425_pci_intr_evcnt(void *v, pci_intr_handle_t ih) 126 { 127 return (NULL); 128 } 129 130 void * 131 ixdp425_pci_intr_establish(void *v, pci_intr_handle_t ih, int ipl, 132 int (*func)(void *), void *arg) 133 { 134 #ifdef PCI_DEBUG 135 printf("ixdp425_pci_intr_establish(v=%p, irq=%d, ipl=%d, func=%p, arg=%p)\n", 136 v, (int) ih, ipl, func, arg); 137 #endif 138 139 return (ixp425_intr_establish(ih, ipl, func, arg)); 140 } 141 142 void 143 ixdp425_pci_intr_disestablish(void *v, void *cookie) 144 { 145 #ifdef PCI_DEBUG 146 printf("ixdp425_pci_intr_disestablish(v=%p, cookie=%p)\n", 147 v, cookie); 148 #endif 149 150 ixp425_intr_disestablish(cookie); 151 } 152