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