xref: /netbsd-src/sys/arch/evbarm/ixm1200/ixm1200_pci.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*      $NetBSD: ixm1200_pci.c,v 1.9 2011/07/01 20:42:37 dyoung Exp $ */
2 #define PCI_DEBUG
3 /*
4  * Copyright (c) 2002, 2003
5  *      Ichiro FUKUHARA <ichiro@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.9 2011/07/01 20:42:37 dyoung 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);
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)
94 {
95 	static char irqstr[IRQNAMESIZE];
96 
97 	sprintf(irqstr, "IXM1200 irq %ld", ih);
98 	return (irqstr);
99 }
100 
101 const struct evcnt *
102 ixm1200_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
103 {
104 	return (NULL);
105 }
106 
107 void *
108 ixm1200_pci_intr_establish(void *v, pci_intr_handle_t ih, int ipl, int (*func)(void *), void *arg)
109 {
110 #ifdef PCI_DEBUG
111 	printf("ixm1200_pci_intr_establish(v=%p, irq=%d, ipl=%d, func=%p, arg=%p)\n",
112 		v, (int) ih, ipl, func, arg);
113 #endif
114 
115 	return (ixp12x0_intr_establish(ih, ipl, func, arg));
116 }
117 
118 void
119 ixm1200_pci_intr_disestablish(void *v, void *cookie)
120 {
121 #ifdef PCI_DEBUG
122 	printf("ixm1200_pci_intr_disestablish(v=%p, cookie=%p)\n",
123 		v, cookie);
124 #endif
125 
126 	ixp12x0_intr_disestablish(cookie);
127 }
128