pic_discovery.c revision 1.4 1 /* $NetBSD: pic_discovery.c,v 1.4 2011/06/18 06:41:43 matt Exp $ */
2
3 /*
4 * Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc.
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 for the NetBSD Project by
18 * Allegro Networks, Inc., and Wasabi Systems, Inc.
19 * 4. The name of Allegro Networks, Inc. may not be used to endorse
20 * or promote products derived from this software without specific prior
21 * written permission.
22 * 5. The name of Wasabi Systems, Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
24 * written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY ALLEGRO NETWORKS, INC. AND
27 * WASABI SYSTEMS, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
28 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 * IN NO EVENT SHALL EITHER ALLEGRO NETWORKS, INC. OR WASABI SYSTEMS, INC.
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: pic_discovery.c,v 1.4 2011/06/18 06:41:43 matt Exp $");
42
43 #include <sys/param.h>
44 #include <sys/bus.h>
45 #include <sys/malloc.h>
46 #include <sys/intr.h>
47
48 #include <powerpc/pic/picvar.h>
49
50 #include <dev/marvell/gtvar.h>
51 #include <dev/marvell/gtintrreg.h>
52 #include <dev/marvell/gtintrvar.h>
53
54
55 struct discovery_gpp_pic_ops;
56
57 struct discovery_pic_ops {
58 struct pic_ops pic;
59 union {
60 uint64_t mask64;
61 uint32_t mask32[2];
62 } _mask;
63 #define enable_mask _mask.mask64
64 #define enable_mask_high _mask.mask32[1]
65 #define enable_mask_low _mask.mask32[0]
66 };
67 struct discovery_gpp_pic_ops {
68 struct pic_ops pic;
69
70 int gpp_base;
71 };
72
73
74 static void discovery_enable_irq(struct pic_ops *, int, int);
75 static void discovery_disable_irq(struct pic_ops *, int);
76 static int discovery_get_irq(struct pic_ops *, int);
77 static void discovery_ack_irq(struct pic_ops *, int);
78
79 static void discovery_gpp_enable_irq(struct pic_ops *, int, int);
80 static void discovery_gpp_disable_irq(struct pic_ops *, int);
81 static int discovery_gpp_get_irq(struct pic_ops *, int);
82 static void discovery_gpp_ack_irq(struct pic_ops *, int);
83
84
85 struct pic_ops *
86 setup_discovery_pic()
87 {
88 struct discovery_pic_ops *discovery;
89 struct pic_ops *pic;
90
91 discovery =
92 malloc(sizeof(struct discovery_pic_ops), M_DEVBUF, M_NOWAIT);
93 KASSERT(discovery != NULL);
94
95 pic = &discovery->pic;
96 pic->pic_numintrs = 64;
97 pic->pic_cookie = (void *)NULL; /* set later */
98 pic->pic_enable_irq = discovery_enable_irq;
99 pic->pic_reenable_irq = discovery_enable_irq;
100 pic->pic_disable_irq = discovery_disable_irq;
101 pic->pic_get_irq = discovery_get_irq;
102 pic->pic_ack_irq = discovery_ack_irq;
103 pic->pic_establish_irq = dummy_pic_establish_intr;
104 pic->pic_finish_setup = NULL;
105 strcpy(pic->pic_name, "discovery");
106 pic_add(pic);
107
108 discovery->enable_mask = 0;
109
110 return pic;
111 }
112
113 static void
114 discovery_enable_irq(struct pic_ops *pic, int irq, int type)
115 {
116 struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
117
118 discovery->enable_mask |= (1 << irq);
119 discovery_enable_intr(pic->pic_cookie, irq);
120 }
121
122 static void
123 discovery_disable_irq(struct pic_ops *pic, int irq)
124 {
125 struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
126
127 discovery->enable_mask &= ~(1 << irq);
128 discovery_disable_intr(pic->pic_cookie, irq);
129 }
130
131 static int
132 discovery_get_irq(struct pic_ops *pic, int mode)
133 {
134 struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
135 uint32_t cause;
136 int irq, base, msk;
137
138 cause = discovery_mic_low(pic->pic_cookie) & discovery->enable_mask_low;
139 if (cause)
140 base = 0;
141 else {
142 cause = discovery_mic_high(pic->pic_cookie);
143 cause &= discovery->enable_mask_high;
144 if (!cause)
145 return 255;
146 base = 32;
147 }
148 for (irq = base, msk = 0x00000001; !(cause & msk); irq++, msk <<= 1);
149
150 return irq;
151 }
152
153 static void
154 discovery_ack_irq(struct pic_ops *pic, int irq)
155 {
156
157 /* nothing */
158 }
159
160
161 struct pic_ops *
162 setup_discovery_gpp_pic(void *discovery, int gpp_base)
163 {
164 struct discovery_gpp_pic_ops *discovery_gpp;
165 struct pic_ops *pic;
166
167 discovery_gpp =
168 malloc(sizeof(struct discovery_gpp_pic_ops), M_DEVBUF, M_NOWAIT);
169 KASSERT(discovery_gpp != NULL);
170
171 pic = &discovery_gpp->pic;
172 pic->pic_numintrs = 32;
173 pic->pic_cookie = discovery;
174 pic->pic_enable_irq = discovery_gpp_enable_irq;
175 pic->pic_reenable_irq = discovery_gpp_enable_irq;
176 pic->pic_disable_irq = discovery_gpp_disable_irq;
177 pic->pic_get_irq = discovery_gpp_get_irq;
178 pic->pic_ack_irq = discovery_gpp_ack_irq;
179 pic->pic_establish_irq = dummy_pic_establish_intr;
180 pic->pic_finish_setup = NULL;
181 strcpy(pic->pic_name, "discovery_gpp");
182 pic_add(pic);
183
184 discovery_gpp->gpp_base = gpp_base;
185
186 return pic;
187 }
188
189 static void
190 discovery_gpp_enable_irq(struct pic_ops *pic, int irq, int type)
191 {
192 struct discovery_gpp_pic_ops *discovery_gpp =
193 (struct discovery_gpp_pic_ops *)pic;
194 struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
195
196 discovery_gpp_enable_intr(discovery->pic.pic_cookie,
197 discovery_gpp->gpp_base + irq);
198 }
199
200 static void
201 discovery_gpp_disable_irq(struct pic_ops *pic, int irq)
202 {
203 struct discovery_gpp_pic_ops *discovery_gpp =
204 (struct discovery_gpp_pic_ops *)pic;
205 struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
206
207 discovery_gpp_disable_intr(discovery->pic.pic_cookie,
208 discovery_gpp->gpp_base + irq);
209 }
210
211 static int
212 discovery_gpp_get_irq(struct pic_ops *pic, int mode)
213 {
214 struct discovery_gpp_pic_ops *discovery_gpp =
215 (struct discovery_gpp_pic_ops *)pic;
216 struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
217 uint32_t cause, mask;
218 int irq, msk, base;
219
220 cause = discovery_gpp_cause(discovery->pic.pic_cookie);
221 mask = discovery_gpp_mask(discovery->pic.pic_cookie);
222
223 base = discovery_gpp->gpp_base;
224 cause &= (mask & (0xff << base));
225 if (!cause)
226 return 255;
227
228 for (irq = base, msk = (1 << base); !(cause & msk); irq++, msk <<= 1);
229
230 return irq;
231 }
232
233 static void
234 discovery_gpp_ack_irq(struct pic_ops *pic, int irq)
235 {
236 struct discovery_gpp_pic_ops *discovery_gpp =
237 (struct discovery_gpp_pic_ops *)pic;
238 struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
239
240 discovery_gpp_clear_cause(discovery->pic.pic_cookie,
241 discovery_gpp->gpp_base + irq);
242 }
243