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