2
* QEMU ETRAX Interrupt Controller.
4
* Copyright (c) 2008 Edgar E. Iglesias, Axis Communications AB.
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to deal
8
* in the Software without restriction, including without limitation the rights
9
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
* copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33
target_phys_addr_t base;
36
/* Active interrupt lines. */
38
/* Active lines, gated through the mask. */
39
uint32_t r_masked_vect;
44
static uint32_t pic_readb (void *opaque, target_phys_addr_t addr)
48
static uint32_t pic_readw (void *opaque, target_phys_addr_t addr)
53
static uint32_t pic_readl (void *opaque, target_phys_addr_t addr)
55
struct fs_pic_state_t *fs = opaque;
58
/* Transform this to a relative addr. */
69
rval = fs->r_masked_vect;
78
cpu_abort(fs->env, "invalid PIC register.\n");
82
D(printf("%s %x=%x\n", __func__, addr, rval));
87
pic_writeb (void *opaque, target_phys_addr_t addr, uint32_t value)
92
pic_writew (void *opaque, target_phys_addr_t addr, uint32_t value)
97
pic_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
99
struct fs_pic_state_t *fs = opaque;
100
D(printf("%s addr=%x val=%x\n", __func__, addr, value));
101
/* Transform this to a relative addr. */
112
fs->r_masked_vect = value;
121
cpu_abort(fs->env, "invalid PIC register.\n");
126
static CPUReadMemoryFunc *pic_read[] = {
132
static CPUWriteMemoryFunc *pic_write[] = {
146
static void etraxfs_pic_handler(void *opaque, int irq, int level)
148
struct fs_pic_state_t *fs = (void *)opaque;
149
CPUState *env = fs->env;
153
D(printf("%s irq=%d level=%d mask=%x v=%x mv=%x\n",
154
__func__, irq, level,
155
fs->rw_mask, fs->r_vect, fs->r_masked_vect));
158
fs->r_vect &= ~(1 << irq);
159
fs->r_vect |= (!!level << irq);
160
fs->r_masked_vect = fs->r_vect & fs->rw_mask;
162
/* The ETRAX interrupt controller signals interrupts to teh core
163
through an interrupt request wire and an irq vector bus. If
164
multiple interrupts are simultaneously active it chooses vector
165
0x30 and lets the sw choose the priorities. */
166
if (fs->r_masked_vect) {
167
uint32_t mv = fs->r_masked_vect;
168
for (i = 0; i < 31; i++) {
171
/* Check for multiple interrupts. */
179
env->interrupt_vector = vector;
180
D(printf("%s vector=%x\n", __func__, vector));
181
cpu_interrupt(env, CPU_INTERRUPT_HARD);
184
env->interrupt_vector = 0;
185
cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
186
D(printf("%s reset irqs\n", __func__));
190
qemu_irq *etraxfs_pic_init(CPUState *env, target_phys_addr_t base)
192
struct fs_pic_state_t *fs;
196
fs = qemu_mallocz(sizeof *fs);
201
pic = qemu_allocate_irqs(etraxfs_pic_handler, fs, 30);
203
intr_vect_regs = cpu_register_io_memory(0, pic_read, pic_write, fs);
204
cpu_register_physical_memory(base, 0x14, intr_vect_regs);