xref: /netbsd-src/sys/arch/arm/marvell/mvsoc_intr.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*	$NetBSD: mvsoc_intr.c,v 1.8 2013/11/20 12:16:47 kiyohara 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.8 2013/11/20 12:16:47 kiyohara Exp $");
30 
31 #include "opt_mvsoc.h"
32 
33 #define _INTR_PRIVATE
34 
35 #include <sys/param.h>
36 #include <sys/proc.h>
37 
38 #include <machine/intr.h>
39 
40 #include <arm/cpu.h>
41 #include <arm/pic/picvar.h>
42 #include <arm/marvell/mvsocreg.h>
43 #include <arm/marvell/mvsocvar.h>
44 
45 
46 int (*find_pending_irqs)(void);
47 
48 static void mvsoc_bridge_pic_unblock_irqs(struct pic_softc *, size_t, uint32_t);
49 static void mvsoc_bridge_pic_block_irqs(struct pic_softc *, size_t, uint32_t);
50 static int mvsoc_bridge_pic_find_pending_irqs(struct pic_softc *);
51 static void mvsoc_bridge_pic_establish_irq(struct pic_softc *,
52 					   struct intrsource *);
53 static void mvsoc_bridge_pic_source_name(struct pic_softc *, int, char *,
54 					 size_t);
55 
56 static const char * const sources[] = {
57     "CPUSelfInt",      "CPUTimer0IntReq", "CPUTimer1IntReq", "CPUWDTimerIntReq",
58     "AccessErr",       "Bit64Err",
59 };
60 
61 static struct pic_ops mvsoc_bridge_picops = {
62 	.pic_unblock_irqs = mvsoc_bridge_pic_unblock_irqs,
63 	.pic_block_irqs = mvsoc_bridge_pic_block_irqs,
64 	.pic_find_pending_irqs = mvsoc_bridge_pic_find_pending_irqs,
65 	.pic_establish_irq = mvsoc_bridge_pic_establish_irq,
66 	.pic_source_name = mvsoc_bridge_pic_source_name,
67 };
68 
69 struct pic_softc mvsoc_bridge_pic = {
70 	.pic_ops = &mvsoc_bridge_picops,
71 	.pic_maxsources = MVSOC_MLMB_MLMBI_NIRQ,
72 	.pic_name = "mvsoc_bridge",
73 };
74 
75 
76 void
77 mvsoc_irq_handler(void *frame)
78 {
79 	struct cpu_info * const ci = curcpu();
80 	const int oldipl = ci->ci_cpl;
81 	const uint32_t oldipl_mask = __BIT(oldipl);
82 	int ipl_mask = 0;
83 
84 	ci->ci_data.cpu_nintr++;
85 
86 	ipl_mask = find_pending_irqs();
87 
88 	/*
89 	 * Record the pending_ipls and deliver them if we can.
90 	 */
91 	if ((ipl_mask & ~oldipl_mask) > oldipl_mask)
92 		pic_do_pending_ints(I32_bit, oldipl, frame);
93 }
94 
95 /*
96  * Mbus-L to Mbus bridge
97  */
98 
99 void *
100 mvsoc_bridge_intr_establish(int ih, int ipl, int (*ih_func)(void *), void *arg)
101 {
102 
103 	return intr_establish(mvsoc_bridge_pic.pic_irqbase + ih, ipl,
104 	    IST_LEVEL_HIGH, ih_func, arg);
105 }
106 
107 /* ARGSUSED */
108 static void
109 mvsoc_bridge_pic_unblock_irqs(struct pic_softc *pic, size_t irqbase,
110 			      uint32_t irq_mask)
111 {
112 
113 	write_mlmbreg(MVSOC_MLMB_MLMBICR,
114 	    read_mlmbreg(MVSOC_MLMB_MLMBICR) & ~irq_mask);
115 	write_mlmbreg(MVSOC_MLMB_MLMBIMR,
116 	    read_mlmbreg(MVSOC_MLMB_MLMBIMR) | irq_mask);
117 }
118 
119 /* ARGSUSED */
120 static void
121 mvsoc_bridge_pic_block_irqs(struct pic_softc *pic, size_t irqbase,
122 			    uint32_t irq_mask)
123 {
124 
125 	write_mlmbreg(MVSOC_MLMB_MLMBIMR,
126 	    read_mlmbreg(MVSOC_MLMB_MLMBIMR) & ~irq_mask);
127 }
128 
129 static int
130 mvsoc_bridge_pic_find_pending_irqs(struct pic_softc *pic)
131 {
132 	uint32_t pending;
133 
134 	pending =
135 	    read_mlmbreg(MVSOC_MLMB_MLMBICR) & read_mlmbreg(MVSOC_MLMB_MLMBIMR);
136 
137 	if (pending == 0)
138 		return 0;
139 
140 	return pic_mark_pending_sources(pic, 0, pending);
141 }
142 
143 /* ARGSUSED */
144 static void
145 mvsoc_bridge_pic_establish_irq(struct pic_softc *pic, struct intrsource *is)
146 {
147 	/* Nothing */
148 }
149 
150 static void
151 mvsoc_bridge_pic_source_name(struct pic_softc *pic, int irq, char *buf,
152 			     size_t len)
153 {
154 
155 	strlcpy(buf, sources[irq], len);
156 }
157