blob: 6c08ef95756c6f3eeea8fe8ed5bf591d2675147a [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 <err.h>
24#include <sys/types.h>
25#include <kernel/thread.h>
26#include <platform.h>
27#include <platform/interrupts.h>
28#include <platform/at91sam7.h>
29#include <arch/arm.h>
30
31static int do_nothing()
32{
33 return INT_NO_RESCHEDULE;
34}
35
36void platform_init_interrupts(void)
37{
38 AT91AIC *aic = AT91AIC_ADDR;
39 int n;
40
41 for(n = 0; n < 31; n++) {
42 aic->SVR[n] = (unsigned) do_nothing;
43 }
44 aic->SPU = (unsigned) do_nothing;
45}
46
47
48status_t mask_interrupt(unsigned int vector, bool *oldstate)
49{
50 AT91AIC *aic = AT91AIC_ADDR;
51
52 if(vector > 31) return ERR_INVALID_ARGS;
53
54 if(oldstate) {
55 enter_critical_section();
56 *oldstate = aic->IMR & (1 << vector) ? 1 : 0;
57 aic->IDCR = (1 << vector);
58 exit_critical_section();
59 } else {
60 aic->IDCR = (1 << vector);
61 }
62
63 return NO_ERROR;
64}
65
66status_t unmask_interrupt(unsigned int vector, bool *oldstate)
67{
68 AT91AIC *aic = AT91AIC_ADDR;
69 if(vector > 31) return ERR_INVALID_ARGS;
70
71 if(oldstate) {
72 enter_critical_section();
73 *oldstate = aic->IMR & (1 << vector) ? 1 : 0;
74 aic->IECR = (1 << vector);
75 exit_critical_section();
76 } else {
77 aic->IECR = (1 << vector);
78 }
79
80 return NO_ERROR;
81}
82
83void platform_irq(struct arm_iframe *frame)
84{
85 AT91AIC *aic = AT91AIC_ADDR;
86 int_handler func;
87 enum handler_return ret;
88
89 inc_critical_section();
90
91 func = (int_handler) aic->IVR;
92// dprintf("platform_irq() -> %p\n", func);
93
94 ret = func(0);
95
96 aic->EOICR = (unsigned) aic;
97
98 if(ret == INT_RESCHEDULE) {
99 thread_preempt();
100 }
101
102 dec_critical_section();
103}
104
105void platform_fiq(struct arm_iframe *frame)
106{
107}
108
109void register_int_handler(unsigned int vector, int_handler handler, void *arg)
110{
111 AT91AIC *aic = AT91AIC_ADDR;
112 if(vector > 31) return;
113 aic->SVR[vector] = (unsigned) handler;
114}