mvsoc_intr.c revision 1.5 1 /* $NetBSD: mvsoc_intr.c,v 1.5 2012/07/29 00:07:10 matt Exp $ */
2 /*
3 * Copyright (c) 2010 KIYOHARA Takashi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: mvsoc_intr.c,v 1.5 2012/07/29 00:07:10 matt Exp $");
30
31 #define _INTR_PRIVATE
32
33 #include <sys/param.h>
34 #include <sys/proc.h>
35
36 #include <machine/intr.h>
37
38 #include <arm/cpu.h>
39 #include <arm/pic/picvar.h>
40 #include <arm/marvell/mvsocreg.h>
41 #include <arm/marvell/mvsocvar.h>
42
43 int (*find_pending_irqs)(void);
44
45 static void mvsoc_bridge_pic_unblock_irqs(struct pic_softc *, size_t, uint32_t);
46 static void mvsoc_bridge_pic_block_irqs(struct pic_softc *, size_t, uint32_t);
47 static int mvsoc_bridge_pic_find_pending_irqs(struct pic_softc *);
48 static void mvsoc_bridge_pic_establish_irq(struct pic_softc *,
49 struct intrsource *);
50 static void mvsoc_bridge_pic_source_name(struct pic_softc *, int, char *,
51 size_t);
52
53 static const char * const sources[] = {
54 "CPUSelfInt", "CPUTimer0IntReq", "CPUTimer1IntReq", "CPUWDTimerIntReq",
55 "AccessErr", "Bit64Err",
56 };
57
58 static struct pic_ops mvsoc_bridge_picops = {
59 .pic_unblock_irqs = mvsoc_bridge_pic_unblock_irqs,
60 .pic_block_irqs = mvsoc_bridge_pic_block_irqs,
61 .pic_find_pending_irqs = mvsoc_bridge_pic_find_pending_irqs,
62 .pic_establish_irq = mvsoc_bridge_pic_establish_irq,
63 .pic_source_name = mvsoc_bridge_pic_source_name,
64 };
65
66 struct pic_softc mvsoc_bridge_pic = {
67 .pic_ops = &mvsoc_bridge_picops,
68 .pic_maxsources = MVSOC_MLMB_MLMBI_NIRQ,
69 .pic_name = "mvsoc_bridge",
70 };
71
72
73 void
74 mvsoc_irq_handler(void *frame)
75 {
76 struct cpu_info * const ci = curcpu();
77 const int oldipl = ci->ci_cpl;
78 const uint32_t oldipl_mask = __BIT(oldipl);
79 int ipl_mask = 0;
80
81 ci->ci_data.cpu_nintr++;
82
83 ipl_mask = find_pending_irqs();
84
85 /*
86 * Record the pending_ipls and deliver them if we can.
87 */
88 if ((ipl_mask & ~oldipl_mask) > oldipl_mask)
89 pic_do_pending_ints(I32_bit, oldipl, frame);
90 }
91
92 /*
93 * Mbus-L to Mbus bridge
94 */
95
96 void *
97 mvsoc_bridge_intr_establish(int ih, int ipl, int (*ih_func)(void *), void *arg)
98 {
99
100 return intr_establish(mvsoc_bridge_pic.pic_irqbase + ih, ipl,
101 IST_LEVEL_HIGH, ih_func, arg);
102 }
103
104 /* ARGSUSED */
105 static void
106 mvsoc_bridge_pic_unblock_irqs(struct pic_softc *pic, size_t irqbase,
107 uint32_t irq_mask)
108 {
109
110 write_mlmbreg(MVSOC_MLMB_MLMBICR,
111 read_mlmbreg(MVSOC_MLMB_MLMBICR) & ~irq_mask);
112 write_mlmbreg(MVSOC_MLMB_MLMBIMR,
113 read_mlmbreg(MVSOC_MLMB_MLMBIMR) | irq_mask);
114 }
115
116 /* ARGSUSED */
117 static void
118 mvsoc_bridge_pic_block_irqs(struct pic_softc *pic, size_t irqbase,
119 uint32_t irq_mask)
120 {
121
122 write_mlmbreg(MVSOC_MLMB_MLMBIMR,
123 read_mlmbreg(MVSOC_MLMB_MLMBIMR) & ~irq_mask);
124 }
125
126 static int
127 mvsoc_bridge_pic_find_pending_irqs(struct pic_softc *pic)
128 {
129 uint32_t pending;
130
131 pending =
132 read_mlmbreg(MVSOC_MLMB_MLMBICR) & read_mlmbreg(MVSOC_MLMB_MLMBIMR);
133
134 if (pending == 0)
135 return 0;
136
137 return pic_mark_pending_sources(pic, 0, pending);
138 }
139
140 /* ARGSUSED */
141 static void
142 mvsoc_bridge_pic_establish_irq(struct pic_softc *pic, struct intrsource *is)
143 {
144 /* Nothing */
145 }
146
147 static void
148 mvsoc_bridge_pic_source_name(struct pic_softc *pic, int irq, char *buf,
149 size_t len)
150 {
151
152 strlcpy(buf, sources[irq], len);
153 }
154