]>
Commit | Line | Data |
---|---|---|
2328826b MF |
1 | /* |
2 | * Copyright (c) 2011, Max Filippov, Open Source and Linux Lab. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are met: | |
7 | * * Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * * Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * * Neither the name of the Open Source and Linux Lab nor the | |
13 | * names of its contributors may be used to endorse or promote products | |
14 | * derived from this software without specific prior written permission. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | */ | |
27 | ||
09aae23d | 28 | #include "qemu/osdep.h" |
33c11879 | 29 | #include "cpu.h" |
83c9f4ca | 30 | #include "hw/hw.h" |
1de7afc9 PB |
31 | #include "qemu/log.h" |
32 | #include "qemu/timer.h" | |
2328826b | 33 | |
5bfcb36e | 34 | void check_interrupts(CPUXtensaState *env) |
b994e91b | 35 | { |
92fddfbd | 36 | CPUState *cs = env_cpu(env); |
b994e91b MF |
37 | int minlevel = xtensa_get_cintlevel(env); |
38 | uint32_t int_set_enabled = env->sregs[INTSET] & env->sregs[INTENABLE]; | |
39 | int level; | |
40 | ||
b994e91b MF |
41 | for (level = env->config->nlevel; level > minlevel; --level) { |
42 | if (env->config->level_mask[level] & int_set_enabled) { | |
43 | env->pending_irq_level = level; | |
c3affe56 | 44 | cpu_interrupt(cs, CPU_INTERRUPT_HARD); |
b994e91b MF |
45 | qemu_log_mask(CPU_LOG_INT, |
46 | "%s level = %d, cintlevel = %d, " | |
47 | "pc = %08x, a0 = %08x, ps = %08x, " | |
48 | "intset = %08x, intenable = %08x, " | |
49 | "ccount = %08x\n", | |
50 | __func__, level, xtensa_get_cintlevel(env), | |
51 | env->pc, env->regs[0], env->sregs[PS], | |
52 | env->sregs[INTSET], env->sregs[INTENABLE], | |
53 | env->sregs[CCOUNT]); | |
54 | return; | |
55 | } | |
56 | } | |
57 | env->pending_irq_level = 0; | |
d8ed887b | 58 | cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); |
b994e91b MF |
59 | } |
60 | ||
61 | static void xtensa_set_irq(void *opaque, int irq, int active) | |
62 | { | |
5bfcb36e | 63 | CPUXtensaState *env = opaque; |
b994e91b MF |
64 | |
65 | if (irq >= env->config->ninterrupt) { | |
66 | qemu_log("%s: bad IRQ %d\n", __func__, irq); | |
67 | } else { | |
68 | uint32_t irq_bit = 1 << irq; | |
69 | ||
70 | if (active) { | |
fa92bd4a | 71 | atomic_or(&env->sregs[INTSET], irq_bit); |
b994e91b | 72 | } else if (env->config->interrupt[irq].inttype == INTTYPE_LEVEL) { |
fa92bd4a | 73 | atomic_and(&env->sregs[INTSET], ~irq_bit); |
b994e91b MF |
74 | } |
75 | ||
76 | check_interrupts(env); | |
77 | } | |
78 | } | |
79 | ||
b994e91b MF |
80 | static void xtensa_ccompare_cb(void *opaque) |
81 | { | |
59a71f75 MF |
82 | XtensaCcompareTimer *ccompare = opaque; |
83 | CPUXtensaState *env = ccompare->env; | |
84 | unsigned i = ccompare - env->ccompare; | |
890c6333 | 85 | |
3f75038a | 86 | qemu_set_irq(env->irq_inputs[env->config->timerint[i]], 1); |
b994e91b MF |
87 | } |
88 | ||
17a86b0e MF |
89 | static void xtensa_set_runstall(void *opaque, int irq, int active) |
90 | { | |
91 | CPUXtensaState *env = opaque; | |
92 | xtensa_runstall(env, active); | |
93 | } | |
94 | ||
5bfcb36e | 95 | void xtensa_irq_init(CPUXtensaState *env) |
b994e91b | 96 | { |
66f03d7e | 97 | unsigned i; |
59a71f75 | 98 | |
66f03d7e MF |
99 | env->irq_inputs = qemu_allocate_irqs(xtensa_set_irq, env, |
100 | env->config->ninterrupt); | |
101 | if (xtensa_option_enabled(env->config, XTENSA_OPTION_TIMER_INTERRUPT)) { | |
59a71f75 MF |
102 | env->time_base = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
103 | env->ccount_base = env->sregs[CCOUNT]; | |
104 | for (i = 0; i < env->config->nccompare; ++i) { | |
105 | env->ccompare[i].env = env; | |
106 | env->ccompare[i].timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, | |
107 | xtensa_ccompare_cb, env->ccompare + i); | |
108 | } | |
b994e91b | 109 | } |
66f03d7e MF |
110 | for (i = 0; i < env->config->nextint; ++i) { |
111 | unsigned irq = env->config->extint[i]; | |
112 | ||
113 | env->ext_irq_inputs[i] = env->irq_inputs[irq]; | |
114 | } | |
17a86b0e | 115 | env->runstall_irq = qemu_allocate_irq(xtensa_set_runstall, env, 0); |
b994e91b | 116 | } |
b8929a54 | 117 | |
66f03d7e | 118 | qemu_irq *xtensa_get_extints(CPUXtensaState *env) |
b8929a54 | 119 | { |
66f03d7e | 120 | return env->ext_irq_inputs; |
b8929a54 | 121 | } |
17a86b0e MF |
122 | |
123 | qemu_irq xtensa_get_runstall(CPUXtensaState *env) | |
124 | { | |
125 | return env->runstall_irq; | |
126 | } |