pic_discovery.c revision 1.3 1 1.3 kiyohara /* $NetBSD: pic_discovery.c,v 1.3 2010/04/28 13:51:55 kiyohara 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.3 kiyohara __KERNEL_RCSID(0, "$NetBSD: pic_discovery.c,v 1.3 2010/04/28 13:51:55 kiyohara 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.2 garbled
47 1.2 garbled #include <machine/intr.h>
48 1.3 kiyohara
49 1.2 garbled #include <powerpc/pic/picvar.h>
50 1.3 kiyohara
51 1.2 garbled #include <dev/marvell/gtvar.h>
52 1.2 garbled #include <dev/marvell/gtintrreg.h>
53 1.3 kiyohara #include <dev/marvell/gtintrvar.h>
54 1.2 garbled
55 1.2 garbled
56 1.3 kiyohara struct discovery_gpp_pic_ops;
57 1.2 garbled
58 1.2 garbled struct discovery_pic_ops {
59 1.3 kiyohara struct pic_ops pic;
60 1.3 kiyohara union {
61 1.3 kiyohara uint64_t mask64;
62 1.3 kiyohara uint32_t mask32[2];
63 1.3 kiyohara } _mask;
64 1.3 kiyohara #define enable_mask _mask.mask64
65 1.3 kiyohara #define enable_mask_high _mask.mask32[1]
66 1.3 kiyohara #define enable_mask_low _mask.mask32[0]
67 1.2 garbled };
68 1.3 kiyohara struct discovery_gpp_pic_ops {
69 1.3 kiyohara struct pic_ops pic;
70 1.2 garbled
71 1.3 kiyohara int gpp_base;
72 1.2 garbled };
73 1.2 garbled
74 1.2 garbled
75 1.3 kiyohara static void discovery_enable_irq(struct pic_ops *, int, int);
76 1.3 kiyohara static void discovery_disable_irq(struct pic_ops *, int);
77 1.3 kiyohara static int discovery_get_irq(struct pic_ops *, int);
78 1.3 kiyohara static void discovery_ack_irq(struct pic_ops *, int);
79 1.3 kiyohara
80 1.3 kiyohara static void discovery_gpp_enable_irq(struct pic_ops *, int, int);
81 1.3 kiyohara static void discovery_gpp_disable_irq(struct pic_ops *, int);
82 1.3 kiyohara static int discovery_gpp_get_irq(struct pic_ops *, int);
83 1.3 kiyohara static void discovery_gpp_ack_irq(struct pic_ops *, int);
84 1.3 kiyohara
85 1.3 kiyohara
86 1.3 kiyohara struct pic_ops *
87 1.3 kiyohara setup_discovery_pic()
88 1.3 kiyohara {
89 1.3 kiyohara struct discovery_pic_ops *discovery;
90 1.3 kiyohara struct pic_ops *pic;
91 1.3 kiyohara
92 1.3 kiyohara discovery =
93 1.3 kiyohara malloc(sizeof(struct discovery_pic_ops), M_DEVBUF, M_NOWAIT);
94 1.3 kiyohara KASSERT(discovery != NULL);
95 1.3 kiyohara
96 1.3 kiyohara pic = &discovery->pic;
97 1.3 kiyohara pic->pic_numintrs = 64;
98 1.3 kiyohara pic->pic_cookie = (void *)NULL; /* set later */
99 1.3 kiyohara pic->pic_enable_irq = discovery_enable_irq;
100 1.3 kiyohara pic->pic_reenable_irq = discovery_enable_irq;
101 1.3 kiyohara pic->pic_disable_irq = discovery_disable_irq;
102 1.3 kiyohara pic->pic_get_irq = discovery_get_irq;
103 1.3 kiyohara pic->pic_ack_irq = discovery_ack_irq;
104 1.3 kiyohara pic->pic_establish_irq = dummy_pic_establish_intr;
105 1.3 kiyohara pic->pic_finish_setup = NULL;
106 1.3 kiyohara strcpy(pic->pic_name, "discovery");
107 1.3 kiyohara pic_add(pic);
108 1.2 garbled
109 1.3 kiyohara discovery->enable_mask = 0;
110 1.2 garbled
111 1.3 kiyohara return pic;
112 1.2 garbled }
113 1.2 garbled
114 1.2 garbled static void
115 1.3 kiyohara discovery_enable_irq(struct pic_ops *pic, int irq, int type)
116 1.2 garbled {
117 1.3 kiyohara struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
118 1.2 garbled
119 1.3 kiyohara discovery->enable_mask |= (1 << irq);
120 1.3 kiyohara discovery_enable_intr(pic->pic_cookie, irq);
121 1.2 garbled }
122 1.2 garbled
123 1.2 garbled static void
124 1.3 kiyohara discovery_disable_irq(struct pic_ops *pic, int irq)
125 1.2 garbled {
126 1.3 kiyohara struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
127 1.2 garbled
128 1.3 kiyohara discovery->enable_mask &= ~(1 << irq);
129 1.3 kiyohara discovery_disable_intr(pic->pic_cookie, irq);
130 1.2 garbled }
131 1.2 garbled
132 1.3 kiyohara static int
133 1.3 kiyohara discovery_get_irq(struct pic_ops *pic, int mode)
134 1.2 garbled {
135 1.3 kiyohara struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
136 1.3 kiyohara uint32_t cause;
137 1.3 kiyohara int irq, base, msk;
138 1.3 kiyohara
139 1.3 kiyohara cause = discovery_mic_low(pic->pic_cookie) & discovery->enable_mask_low;
140 1.3 kiyohara if (cause)
141 1.3 kiyohara base = 0;
142 1.3 kiyohara else {
143 1.3 kiyohara cause = discovery_mic_high(pic->pic_cookie);
144 1.3 kiyohara cause &= discovery->enable_mask_high;
145 1.3 kiyohara if (!cause)
146 1.3 kiyohara return 255;
147 1.3 kiyohara base = 32;
148 1.3 kiyohara }
149 1.3 kiyohara for (irq = base, msk = 0x00000001; !(cause & msk); irq++, msk <<= 1);
150 1.2 garbled
151 1.3 kiyohara return irq;
152 1.2 garbled }
153 1.2 garbled
154 1.2 garbled static void
155 1.3 kiyohara discovery_ack_irq(struct pic_ops *pic, int irq)
156 1.2 garbled {
157 1.3 kiyohara
158 1.3 kiyohara /* nothing */
159 1.2 garbled }
160 1.2 garbled
161 1.3 kiyohara
162 1.3 kiyohara struct pic_ops *
163 1.3 kiyohara setup_discovery_gpp_pic(void *discovery, int gpp_base)
164 1.2 garbled {
165 1.3 kiyohara struct discovery_gpp_pic_ops *discovery_gpp;
166 1.3 kiyohara struct pic_ops *pic;
167 1.3 kiyohara
168 1.3 kiyohara discovery_gpp =
169 1.3 kiyohara malloc(sizeof(struct discovery_gpp_pic_ops), M_DEVBUF, M_NOWAIT);
170 1.3 kiyohara KASSERT(discovery_gpp != NULL);
171 1.2 garbled
172 1.3 kiyohara pic = &discovery_gpp->pic;
173 1.3 kiyohara pic->pic_numintrs = 32;
174 1.3 kiyohara pic->pic_cookie = discovery;
175 1.3 kiyohara pic->pic_enable_irq = discovery_gpp_enable_irq;
176 1.3 kiyohara pic->pic_reenable_irq = discovery_gpp_enable_irq;
177 1.3 kiyohara pic->pic_disable_irq = discovery_gpp_disable_irq;
178 1.3 kiyohara pic->pic_get_irq = discovery_gpp_get_irq;
179 1.3 kiyohara pic->pic_ack_irq = discovery_gpp_ack_irq;
180 1.3 kiyohara pic->pic_establish_irq = dummy_pic_establish_intr;
181 1.3 kiyohara pic->pic_finish_setup = NULL;
182 1.3 kiyohara strcpy(pic->pic_name, "discovery_gpp");
183 1.3 kiyohara pic_add(pic);
184 1.2 garbled
185 1.3 kiyohara discovery_gpp->gpp_base = gpp_base;
186 1.2 garbled
187 1.3 kiyohara return pic;
188 1.2 garbled }
189 1.2 garbled
190 1.2 garbled static void
191 1.3 kiyohara discovery_gpp_enable_irq(struct pic_ops *pic, int irq, int type)
192 1.2 garbled {
193 1.3 kiyohara struct discovery_gpp_pic_ops *discovery_gpp =
194 1.3 kiyohara (struct discovery_gpp_pic_ops *)pic;
195 1.3 kiyohara struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
196 1.2 garbled
197 1.3 kiyohara discovery_gpp_enable_intr(discovery->pic.pic_cookie,
198 1.3 kiyohara discovery_gpp->gpp_base + irq);
199 1.2 garbled }
200 1.2 garbled
201 1.2 garbled static void
202 1.3 kiyohara discovery_gpp_disable_irq(struct pic_ops *pic, int irq)
203 1.2 garbled {
204 1.3 kiyohara struct discovery_gpp_pic_ops *discovery_gpp =
205 1.3 kiyohara (struct discovery_gpp_pic_ops *)pic;
206 1.3 kiyohara struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
207 1.2 garbled
208 1.3 kiyohara discovery_gpp_disable_intr(discovery->pic.pic_cookie,
209 1.3 kiyohara discovery_gpp->gpp_base + irq);
210 1.2 garbled }
211 1.2 garbled
212 1.3 kiyohara static int
213 1.3 kiyohara discovery_gpp_get_irq(struct pic_ops *pic, int mode)
214 1.2 garbled {
215 1.3 kiyohara struct discovery_gpp_pic_ops *discovery_gpp =
216 1.3 kiyohara (struct discovery_gpp_pic_ops *)pic;
217 1.3 kiyohara struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
218 1.3 kiyohara uint32_t cause, mask;
219 1.3 kiyohara int irq, msk, base;
220 1.2 garbled
221 1.3 kiyohara cause = discovery_gpp_cause(discovery->pic.pic_cookie);
222 1.3 kiyohara mask = discovery_gpp_mask(discovery->pic.pic_cookie);
223 1.3 kiyohara
224 1.3 kiyohara base = discovery_gpp->gpp_base;
225 1.3 kiyohara cause &= (mask & (0xff << base));
226 1.3 kiyohara if (!cause)
227 1.3 kiyohara return 255;
228 1.2 garbled
229 1.3 kiyohara for (irq = base, msk = (1 << base); !(cause & msk); irq++, msk <<= 1);
230 1.2 garbled
231 1.3 kiyohara return irq;
232 1.2 garbled }
233 1.2 garbled
234 1.2 garbled static void
235 1.3 kiyohara discovery_gpp_ack_irq(struct pic_ops *pic, int irq)
236 1.2 garbled {
237 1.3 kiyohara struct discovery_gpp_pic_ops *discovery_gpp =
238 1.3 kiyohara (struct discovery_gpp_pic_ops *)pic;
239 1.3 kiyohara struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
240 1.2 garbled
241 1.3 kiyohara discovery_gpp_clear_cause(discovery->pic.pic_cookie,
242 1.3 kiyohara discovery_gpp->gpp_base + irq);
243 1.2 garbled }
244