blob: 225d8100fe700176ce861f4fcb53b8a5cdd6fcae [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <sys/types.h>
24#include <debug.h>
25#include <err.h>
26#include <reg.h>
27#include <kernel/thread.h>
28#include <platform/interrupts.h>
29#include <arch/ops.h>
30#include <arch/arm.h>
31#include "platform_p.h"
32#include <platform/omap3.h>
33
34struct int_handler_struct {
35 int_handler handler;
36 void *arg;
37};
38
39static struct int_handler_struct int_handler_table[INT_VECTORS];
40
41#define vectorToController(vector) ((vector) / 32)
42
43void platform_init_interrupts(void)
44{
45 unsigned int i;
46
47 // reset the controller
48 *REG32(INTC_SYSCONFIG) = 0x2; // start a reset
49 while ((*REG32(INTC_SYSSTATUS) & 0x1) == 0)
50 ;
51
52 // mask all interrupts
53 *REG32(INTC_MIR(0)) = 0xffffffff;
54 *REG32(INTC_MIR(1)) = 0xffffffff;
55 *REG32(INTC_MIR(2)) = 0xffffffff;
56
57 // set up each of the interrupts
58 for (i = 0; i < INT_VECTORS; i++) {
59 // set each vector up as high priority IRQ
60 *REG32(INTC_ILR(i)) = 0;
61 //*ICReg(i / 32, INTCON_ILR_BASE + 4*(i%32)) = ((level_trigger[i/32] & (1<<(i%32))) ? (1<<1) : (0<<1)) | 0;
62 }
63
64 // disable the priority threshold
65 *REG32(INTC_THRESHOLD) = 0xff;
66
67 // clear any pending sw interrupts
68 *REG32(INTC_ISR_CLEAR(0)) = 0xffffffff;
69 *REG32(INTC_ISR_CLEAR(1)) = 0xffffffff;
70 *REG32(INTC_ISR_CLEAR(2)) = 0xffffffff;
71
72 // globally unmask interrupts
73 *REG32(INTC_CONTROL) = 3; // reset and enable the controller
74}
75
76status_t mask_interrupt(unsigned int vector, bool *oldstate)
77{
78 if (vector >= INT_VECTORS)
79 return ERR_INVALID_ARGS;
80
81// dprintf("%s: vector %d\n", __PRETTY_FUNCTION__, vector);
82
83 enter_critical_section();
84
85 if (oldstate)
86 *oldstate = false;
87
88 *REG32(INTC_MIR_SET(vectorToController(vector))) = 1 << (vector % 32);
89
90 exit_critical_section();
91
92 return NO_ERROR;
93}
94
95
96void platform_mask_irqs(void)
97{
98 int i;
99 for (i=0; i<INT_VECTORS; i++)
100 mask_interrupt(i, NULL);
101}
102
103status_t unmask_interrupt(unsigned int vector, bool *oldstate)
104{
105 if (vector >= INT_VECTORS)
106 return ERR_INVALID_ARGS;
107
108// dprintf("%s: vector %d\n", __PRETTY_FUNCTION__, vector);
109
110 enter_critical_section();
111
112 if (oldstate)
113 *oldstate = false;
114
115 *REG32(INTC_MIR_CLEAR(vectorToController(vector))) = 1 << (vector % 32);
116
117 exit_critical_section();
118
119 return NO_ERROR;
120}
121
122enum handler_return platform_irq(struct arm_iframe *frame)
123{
124 // get the current vector
125 unsigned int vector;
126
127 // read the currently active IRQ
128 vector = *REG32(INTC_SIR_IRQ) & 0x7f;
129
130// TRACEF("spsr 0x%x, pc 0x%x, currthread %p, vector %d, handler %p\n", frame->spsr, frame->pc, current_thread, vector, int_handler_table[vector].handler);
131
132#if THREAD_STATS
133 thread_stats.interrupts++;
134#endif
135
136 // deliver the interrupt
137 enum handler_return ret;
138
139 ret = INT_NO_RESCHEDULE;
140 if (int_handler_table[vector].handler)
141 ret = int_handler_table[vector].handler(int_handler_table[vector].arg);
142
143 // ack the interrupt
144 *REG32(INTC_CONTROL) = 0x1;
145
146 return ret;
147}
148
149void platform_fiq(struct arm_iframe *frame)
150{
151 PANIC_UNIMPLEMENTED;
152}
153
154void register_int_handler(unsigned int vector, int_handler handler, void *arg)
155{
156 if (vector >= INT_VECTORS)
157 panic("register_int_handler: vector out of range %d\n", vector);
158
159 enter_critical_section();
160
161 int_handler_table[vector].arg = arg;
162 int_handler_table[vector].handler = handler;
163
164 exit_critical_section();
165}
166
167