forked from trusty-ia/trusty_platform_sand
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterrupts.c
More file actions
168 lines (137 loc) · 3.92 KB
/
interrupts.c
File metadata and controls
168 lines (137 loc) · 3.92 KB
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
/*******************************************************************************
* Copyright (c) 2015 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#include <err.h>
#include <lib/sm.h>
#include <arch/local_apic.h>
#ifdef ENABLE_FPU
#include <arch/fpu.h>
#endif
#include <kernel/thread.h>
#include <platform/interrupts.h>
#include <platform/sand.h>
#include <lk/init.h>
static spin_lock_t lock;
void x86_gpf_handler(x86_iframe_t *frame);
void x86_invop_handler(x86_iframe_t *frame);
void x86_unhandled_exception(x86_iframe_t *frame);
#ifdef ARCH_X86_64
void x86_pfe_handler(x86_iframe_t *frame);
#endif
struct int_handler_struct {
int_handler handler;
void *arg;
};
static struct int_handler_struct int_handler_table[INT_VECTORS];
#define PIC1_DATA 0x21
#define PIC2_DATA 0xA1
static char master_pic, slave_pic;
/*
* Diabled PIC beofre use the processor Local APIC and IOAPIC.
* Interrupt 8/9 (not exception) triggered by PIC when enabling
* on QEMU platform, interrupt is triggered by PIC.
*/
static void disable_pic(void) {
/* save PIC value */
master_pic = inp(PIC1_DATA);
slave_pic = inp(PIC2_DATA);
/* disable all IRQs */
outp(PIC1_DATA, 0xff);
outp(PIC2_DATA, 0xff);
}
void restore_pic(void)
{
outp(PIC1_DATA, master_pic);
outp(PIC2_DATA, slave_pic);
}
LK_INIT_HOOK_FLAGS(restore_pic, (lk_init_hook)restore_pic,
LK_INIT_LEVEL_LAST-1, LK_INIT_FLAG_PRIMARY_CPU);
void platform_init_interrupts(void)
{
/*
* Mask all interrputs before LK bootup
*/
disable_pic();
x86_set_cr8(0xF);
}
status_t mask_interrupt(unsigned int vector)
{
if (vector >= INT_VECTORS)
return ERR_INVALID_ARGS;
return NO_ERROR;
}
void platform_mask_irqs(void)
{
}
status_t unmask_interrupt(unsigned int vector)
{
if (vector >= INT_VECTORS)
return ERR_INVALID_ARGS;
return NO_ERROR;
}
extern enum handler_return sm_handle_irq(void);
enum handler_return platform_irq(x86_iframe_t *frame)
{
/* get the current vector */
unsigned int vector = frame->vector;
THREAD_STATS_INC(interrupts);
/* deliver the interrupt */
enum handler_return ret = INT_NO_RESCHEDULE;
/* EOI should be issued by ISR */
if (int_handler_table[vector].handler) {
ret = int_handler_table[vector].
handler(int_handler_table[vector].arg);
} else {
FW_INT_TO_NS(vector);
ret = sm_handle_irq();
}
return ret;
}
void register_int_handler(unsigned int vector, int_handler handler, void *arg)
{
if (vector >= INT_VECTORS)
panic("register_int_handler: vector out of range %d\n", vector);
spin_lock_saved_state_t state;
spin_lock_irqsave(&lock, state);
int_handler_table[vector].arg = arg;
int_handler_table[vector].handler = handler;
spin_unlock_irqrestore(&lock, state);
}
/*
* Stubs to resolve compilations errors. These and other
* such functions implemented under flags like SM_LIB need
* to be implemented
*/
status_t sm_intc_fiq_enter(void)
{
return 0;
}
void sm_intc_fiq_exit(void)
{
}
long smc_intc_get_next_irq(smc32_args_t *args)
{
long vector;
for (vector = args->params[0]; vector<INT_VECTORS; vector++)
{
if (int_handler_table[vector].handler && (INT_RESCH != vector))
return vector;
}
return -1;
}
long smc_intc_request_fiq(smc32_args_t *args)
{
return NO_ERROR;
}