1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
/*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
* Code to handle x86 style IRQs plus some generic interrupt stuff.
*
* Copyright (C) 1992 Linus Torvalds
* Copyright (C) 1994 - 2000 Ralf Baechle
*/
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel_stat.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/random.h>
#include <linux/sched.h>
#include <linux/seq_file.h>
#include <linux/kallsyms.h>
#include <linux/kgdb.h>
#include <asm/atomic.h>
#include <asm/system.h>
#include <asm/uaccess.h>
#ifdef CONFIG_KGDB
int kgdb_early_setup;
#endif
static unsigned long irq_map[NR_IRQS / BITS_PER_LONG];
int allocate_irqno(void)
{
int irq;
again:
irq = find_first_zero_bit(irq_map, NR_IRQS);
if (irq >= NR_IRQS)
return -ENOSPC;
if (test_and_set_bit(irq, irq_map))
goto again;
return irq;
}
/*
* Allocate the 16 legacy interrupts for i8259 devices. This happens early
* in the kernel initialization so treating allocation failure as BUG() is
* ok.
*/
void __init alloc_legacy_irqno(void)
{
int i;
for (i = 0; i <= 16; i++)
BUG_ON(test_and_set_bit(i, irq_map));
}
void free_irqno(unsigned int irq)
{
smp_mb__before_clear_bit();
clear_bit(irq, irq_map);
smp_mb__after_clear_bit();
}
/*
* 'what should we do if we get a hw irq event on an illegal vector'.
* each architecture has to answer this themselves.
*/
void ack_bad_irq(unsigned int irq)
{
printk("unexpected IRQ # %d\n", irq);
}
//by rock 2010-04-06
#if defined(CONFIG_RTK_VOIP) || defined(CONFIG_RTL_819X)
static atomic_t irq_err_count[SPURIOS_INT_MAX];
#else
static atomic_t irq_err_count;
#endif
#ifdef CONFIG_CPU_RLX5281
static void get_int_counts(u32 *hw_int, u32 *vec_int)
{
// enable hardware, vercor interrupts
u32 mode = (0x2e << 0) | (0x2f << 8);
u64 cnt[4];
__asm__ __volatile__ (
// enable cp3
"mfc0 $8, $12 \n\t"
"nop \n\t"
"nop \n\t"
"or $8, 0x80000000 \n\t"
"mtc0 $8, $12 \n\t"
"nop \n\t"
"nop \n\t"
// stop counter
"ctc3 $0,$0 \n\t"
"nop \n\t"
"nop \n\t"
// save counter
"mfc3 %L[cnt0],$8 \n\t"
"mfc3 %M[cnt0],$9 \n\t"
"mfc3 %L[cnt1],$10 \n\t"
"mfc3 %M[cnt1],$11 \n\t"
"mfc3 %L[cnt2],$12 \n\t"
"mfc3 %M[cnt2],$13 \n\t"
"mfc3 %L[cnt3],$14 \n\t"
"mfc3 %M[cnt3],$15 \n\t"
"nop \n\t"
"nop \n\t"
// start counter
"ctc3 %[mode],$0 \n\t"
"nop \n\t"
"nop \n\t"
:[cnt0] "=&r" (cnt[0]), [cnt1] "=&r" (cnt[1]), [cnt2] "=&r" (cnt[2]), [cnt3] "=&r" (cnt[3])
:[mode] "r" (mode)
);
*hw_int = (u32) cnt[0];
*vec_int = (u32) cnt[1];
}
#endif
/*
* Generic, controller-independent functions:
*/
int show_interrupts(struct seq_file *p, void *v)
{
int i = *(loff_t *) v, j;
struct irqaction * action;
unsigned long flags;
struct irq_desc *rtl_irq_desc;
if (i == 0) {
seq_printf(p, " ");
for_each_online_cpu(j)
seq_printf(p, "CPU%d ", j);
seq_putc(p, '\n');
}
if (i < NR_IRQS) {
rtl_irq_desc = irq_to_desc(i);
spin_lock_irqsave(rtl_irq_desc->lock, flags);
action = rtl_irq_desc->action;
if (!action)
goto skip;
seq_printf(p, "%3d: ", i);
seq_printf(p, "%10u ", kstat_irqs(i));
seq_printf(p, " %14s", rtl_irq_desc->chip->name);
seq_printf(p, " %s (0x%lx)", action->name, action->flags);
for (action=action->next; action; action = action->next)
seq_printf(p, ", %s (0x%lx)", action->name, action->flags);
seq_putc(p, '\n');
skip:
spin_unlock_irqrestore(rtl_irq_desc->lock, flags);
} else if (i == NR_IRQS) {
#ifdef CONFIG_CPU_RLX5281
u32 hw_int, vec_int;
static int first_dump = 1;
static int hw_int_off, vec_int_off;
#endif
#ifdef CONFIG_RTL_819X_SWCORE
extern int cnt_swcore;
extern int cnt_swcore_tx;
extern int cnt_swcore_rx;
extern int cnt_swcore_link;
extern int cnt_swcore_err;
#endif
seq_printf(p, "\n");
#if defined(CONFIG_RTK_VOIP) || defined(CONFIG_RTL_819X)
for (j=0; j<ARRAY_SIZE(irq_err_count); j++)
seq_printf(p, "ER%d: %10u\n", j, atomic_read(&irq_err_count[j]));
#else
seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
#endif
#ifdef CONFIG_CPU_RLX5281
get_int_counts(&hw_int, &vec_int);
if (first_dump)
{
first_dump = 0;
hw_int_off = 0;
vec_int_off = 0;
for (j=0; j<NR_IRQS; j++)
{
rtl_irq_desc = irq_to_desc(j);
if (rtl_irq_desc->action == NULL)
continue;
if (strcmp(rtl_irq_desc->chip->name, "RLX") == 0)
hw_int_off += kstat_irqs(j);
else if (strcmp(rtl_irq_desc->chip->name, "RLX LOPI") == 0)
vec_int_off += kstat_irqs(j);
else if (strcmp(rtl_irq_desc->chip->name, "ICTL") == 0)
hw_int_off += kstat_irqs(j);
}
// rock: use sw counter to calc hw counter offset on first time
// (first dump info is sw info)
hw_int_off -= hw_int;
vec_int_off -= vec_int;
}
seq_printf(p, "\n HW: %10u\n", hw_int + hw_int_off);
seq_printf(p, "VEC: %10u\n", vec_int + vec_int_off);
#endif
#ifdef CONFIG_RTL_819X_SWCORE
seq_printf(p, "\n SW: %10u\n", cnt_swcore);
seq_printf(p, " TX: %10u\n", cnt_swcore_tx);
seq_printf(p, " RX: %10u\n", cnt_swcore_rx);
seq_printf(p, "LNK: %10u\n", cnt_swcore_link);
seq_printf(p, "ERR: %10u\n", cnt_swcore_err);
#endif
}
return 0;
}
#if defined(CONFIG_RTK_VOIP) || defined(CONFIG_RTL_819X)
asmlinkage void spurious_interrupt(int i)
{
atomic_inc(&irq_err_count[i]);
}
#else
asmlinkage void spurious_interrupt()
{
atomic_inc(&irq_err_count);
}
#endif
void __init init_IRQ(void)
{
extern void bsp_irq_init(void);
int i;
#ifdef CONFIG_KGDB
if (kgdb_early_setup)
return;
#endif
for (i = 0; i < NR_IRQS; i++)
set_irq_noprobe(i);
bsp_irq_init();
#ifdef CONFIG_KGDB
if (!kgdb_early_setup)
kgdb_early_setup = 1;
#endif
#if defined(CONFIG_RTK_VOIP) || defined(CONFIG_RTL_819X)
for (i=0;i<SPURIOS_INT_MAX;i++) {
atomic_set(&irq_err_count[i], 0);
}
#endif
}
|