Home | History | Annotate | Line # | Download | only in ixm1200
ixm1200_pci.c revision 1.12
      1 /*      $NetBSD: ixm1200_pci.c,v 1.12 2018/10/23 08:38:18 jmcneill Exp $ */
      2 #define PCI_DEBUG
      3 /*
      4  * Copyright (c) 2002, 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  *
     17  * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
     21  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  * SUCH DAMAGE.
     28  */
     29 
     30 #include <sys/cdefs.h>
     31 __KERNEL_RCSID(0, "$NetBSD: ixm1200_pci.c,v 1.12 2018/10/23 08:38:18 jmcneill Exp $");
     32 
     33 /*
     34  * IXM1200 PCI interrupt support.
     35  */
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/device.h>
     40 
     41 #include <machine/autoconf.h>
     42 #include <sys/bus.h>
     43 
     44 #include <evbarm/ixm1200/ixm1200reg.h>
     45 #include <evbarm/ixm1200/ixm1200var.h>
     46 
     47 #include <arm/ixp12x0/ixp12x0reg.h>
     48 #include <arm/ixp12x0/ixp12x0var.h>
     49 
     50 #include <arm/ixp12x0/ixp12x0_pcireg.h>
     51 
     52 #include <dev/pci/pcidevs.h>
     53 #include <dev/pci/ppbreg.h>
     54 
     55 int ixm1200_pci_intr_map(const struct pci_attach_args *, pci_intr_handle_t *);
     56 const char *ixm1200_pci_intr_string(void *, pci_intr_handle_t, char *, size_t);
     57 const struct evcnt *ixm1200_pci_intr_evcnt(void *, pci_intr_handle_t);
     58 void *ixm1200_pci_intr_establish(void *, pci_intr_handle_t, int,
     59 	int (*func)(void *), void *);
     60 void ixm1200_pci_intr_disestablish(void *, void *);
     61 
     62 void
     63 ixm1200_pci_init(pci_chipset_tag_t pc, void *cookie)
     64 {
     65 	pc->pc_intr_v = cookie;
     66 	pc->pc_intr_map = ixm1200_pci_intr_map;
     67 	pc->pc_intr_string = ixm1200_pci_intr_string;
     68 	pc->pc_intr_evcnt = ixm1200_pci_intr_evcnt;
     69 	pc->pc_intr_establish = ixm1200_pci_intr_establish;
     70 	pc->pc_intr_disestablish = ixm1200_pci_intr_disestablish;
     71 }
     72 
     73 int
     74 ixm1200_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
     75 {
     76 #ifdef PCI_DEBUG
     77 	void *v = pa->pa_pc;
     78 	int pin = pa->pa_intrpin;
     79 	int line = pa->pa_intrline;
     80 	int dev=pa->pa_device;
     81 	pcitag_t intrtag = pa->pa_intrtag;
     82 
     83 	printf("ixm1200_pci_intr_map: v=%p, tag=%08lx intrpin=%d line=%d dev=%d\n",
     84 		v, intrtag, pin, line, dev);
     85 #endif
     86 
     87 	/* ixp12x0 has only one interrupt line for PCI */
     88 	*ihp = IXPPCI_INTR_PIL;
     89 	return (0);
     90 }
     91 
     92 const char *
     93 ixm1200_pci_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
     94 {
     95 	snprintf(buf, len, "IXM1200 irq %" PRIu64, ih);
     96 	return buf;
     97 }
     98 
     99 const struct evcnt *
    100 ixm1200_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
    101 {
    102 	return (NULL);
    103 }
    104 
    105 void *
    106 ixm1200_pci_intr_establish(void *v, pci_intr_handle_t ih, int ipl, int (*func)(void *), void *arg)
    107 {
    108 #ifdef PCI_DEBUG
    109 	printf("ixm1200_pci_intr_establish(v=%p, irq=%d, ipl=%d, func=%p, arg=%p)\n",
    110 		v, (int) ih, ipl, func, arg);
    111 #endif
    112 
    113 	return (ixp12x0_intr_establish(ih, ipl, func, arg));
    114 }
    115 
    116 void
    117 ixm1200_pci_intr_disestablish(void *v, void *cookie)
    118 {
    119 #ifdef PCI_DEBUG
    120 	printf("ixm1200_pci_intr_disestablish(v=%p, cookie=%p)\n",
    121 		v, cookie);
    122 #endif
    123 
    124 	ixp12x0_intr_disestablish(cookie);
    125 }
    126