xref: /netbsd-src/sys/arch/evbarm/cp3100/cp3100_pci.c (revision cce19cc266a52839894f2a8bc8e717697e71b9b6)
1 /*	$NetBSD: cp3100_pci.c,v 1.5 2018/11/16 15:06:23 jmcneill Exp $	*/
2 
3 /*
4  * Copyright 2006 Wasabi Systems, Inc.
5  * All rights reserved.
6  *
7  * Written by Steve C. Woodford for Wasabi Systems, Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed for the NetBSD Project by
20  *      Wasabi Systems, Inc.
21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22  *    or promote products derived from this software without specific prior
23  *    written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 /*
39  * CP3100 PCI interrupt support.
40  */
41 
42 #include <sys/cdefs.h>
43 __KERNEL_RCSID(0, "$NetBSD: cp3100_pci.c,v 1.5 2018/11/16 15:06:23 jmcneill Exp $");
44 
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/device.h>
48 
49 #include <machine/autoconf.h>
50 #include <sys/bus.h>
51 
52 #include <evbarm/iq80321/iq80321reg.h>
53 #include <evbarm/iq80321/iq80321var.h>
54 
55 #include <arm/xscale/i80321reg.h>
56 #include <arm/xscale/i80321var.h>
57 
58 #include <dev/pci/pcidevs.h>
59 #include <dev/pci/ppbreg.h>
60 
61 int	iq80321_pci_intr_map(const struct pci_attach_args *,
62 	    pci_intr_handle_t *);
63 const char *iq80321_pci_intr_string(void *, pci_intr_handle_t, char *, size_t);
64 const struct evcnt *iq80321_pci_intr_evcnt(void *, pci_intr_handle_t);
65 void	*iq80321_pci_intr_establish(void *, pci_intr_handle_t,
66 	    int, int (*func)(void *), void *, const char *);
67 void	iq80321_pci_intr_disestablish(void *, void *);
68 
69 void
iq80321_pci_init(pci_chipset_tag_t pc,void * cookie)70 iq80321_pci_init(pci_chipset_tag_t pc, void *cookie)
71 {
72 
73 	pc->pc_intr_v = cookie;		/* the i80321 softc */
74 	pc->pc_intr_map = iq80321_pci_intr_map;
75 	pc->pc_intr_string = iq80321_pci_intr_string;
76 	pc->pc_intr_evcnt = iq80321_pci_intr_evcnt;
77 	pc->pc_intr_establish = iq80321_pci_intr_establish;
78 	pc->pc_intr_disestablish = iq80321_pci_intr_disestablish;
79 }
80 
81 int
iq80321_pci_intr_map(const struct pci_attach_args * pa,pci_intr_handle_t * ihp)82 iq80321_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
83 {
84 	struct i80321_softc *sc = pa->pa_pc->pc_intr_v;
85 	int b, d, f;
86 	uint32_t busno;
87 
88 	busno = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, ATU_PCIXSR);
89 	busno = PCIXSR_BUSNO(busno);
90 	if (busno == 0xff)
91 		busno = 0;
92 
93 	pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, &b, &d, &f);
94 
95 	/* No mappings for devices not on our bus. */
96 	if (b != busno)
97 		goto no_mapping;
98 
99 	switch (d) {
100 	case 0:			/* i82546EB Dual GigE */
101 		/*
102 		 * This is a dual-function chip which uses INTA and INTB,
103 		 * connected to XINT0 and XINT1 respectively.
104 		 */
105 		if (f != 0 && f != 1)
106 			goto no_mapping;
107 		*ihp = ICU_INT_XINT(f);
108 		return (0);
109 
110 	case 1:			/* i31244 S-ATA Interface */
111 		*ihp = ICU_INT_XINT(2);
112 		return (0);
113 
114 	case 2:			/* Symbios Logic 53c1010 SCSI Controllers */
115 	case 3:
116 		/*
117 		 * Both controllers share a single pin
118 		 */
119 		*ihp = ICU_INT_XINT(3);
120 		return (0);
121 
122 	default:
123  no_mapping:
124 		printf("iq80321_pci_intr_map: no mapping for %d/%d/%d/%c\n",
125 		    pa->pa_bus, pa->pa_device, pa->pa_function,
126 		    '@' + pa->pa_intrpin);
127 		return (1);
128 	}
129 
130 	return (0);
131 }
132 
133 const char *
iq80321_pci_intr_string(void * v,pci_intr_handle_t ih,char * buf,size_t len)134 iq80321_pci_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
135 {
136 
137 	strlcpy(buf, i80321_irqnames[ih], len);
138 	return buf;
139 }
140 
141 const struct evcnt *
iq80321_pci_intr_evcnt(void * v,pci_intr_handle_t ih)142 iq80321_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
143 {
144 
145 	/* XXX For now. */
146 	return (NULL);
147 }
148 
149 void *
iq80321_pci_intr_establish(void * v,pci_intr_handle_t ih,int ipl,int (* func)(void *),void * arg,const char * xname)150 iq80321_pci_intr_establish(void *v, pci_intr_handle_t ih, int ipl,
151     int (*func)(void *), void *arg, const char *xname)
152 {
153 
154 	return (i80321_intr_establish(ih, ipl, func, arg));
155 }
156 
157 void
iq80321_pci_intr_disestablish(void * v,void * cookie)158 iq80321_pci_intr_disestablish(void *v, void *cookie)
159 {
160 
161 	i80321_intr_disestablish(cookie);
162 }
163