2008-03-14 09:04:24 +08:00
|
|
|
/*
|
|
|
|
* QEMU ETRAX Interrupt Controller.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Edgar E. Iglesias, Axis Communications AB.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "hw.h"
|
2009-03-06 07:01:23 +08:00
|
|
|
#include "pc.h"
|
2008-06-10 07:33:30 +08:00
|
|
|
#include "etraxfs.h"
|
2008-03-14 09:04:24 +08:00
|
|
|
|
|
|
|
#define D(x)
|
|
|
|
|
2009-05-05 18:38:39 +08:00
|
|
|
#define R_RW_MASK 0
|
|
|
|
#define R_R_VECT 1
|
|
|
|
#define R_R_MASKED_VECT 2
|
|
|
|
#define R_R_NMI 3
|
|
|
|
#define R_R_GURU 4
|
|
|
|
#define R_MAX 5
|
|
|
|
|
2009-05-05 18:41:35 +08:00
|
|
|
struct fs_pic_state
|
2008-03-14 09:04:24 +08:00
|
|
|
{
|
|
|
|
CPUState *env;
|
2009-05-05 18:38:39 +08:00
|
|
|
uint32_t regs[R_MAX];
|
2008-03-14 09:04:24 +08:00
|
|
|
};
|
|
|
|
|
2009-05-05 18:41:35 +08:00
|
|
|
static void pic_update(struct fs_pic_state *fs)
|
2009-01-07 21:30:41 +08:00
|
|
|
{
|
|
|
|
CPUState *env = fs->env;
|
|
|
|
uint32_t vector = 0;
|
2009-05-05 18:38:39 +08:00
|
|
|
int i;
|
2009-01-07 21:30:41 +08:00
|
|
|
|
2009-05-05 18:38:39 +08:00
|
|
|
fs->regs[R_R_MASKED_VECT] = fs->regs[R_R_VECT] & fs->regs[R_RW_MASK];
|
2009-01-07 21:30:41 +08:00
|
|
|
|
|
|
|
/* The ETRAX interrupt controller signals interrupts to teh core
|
|
|
|
through an interrupt request wire and an irq vector bus. If
|
|
|
|
multiple interrupts are simultaneously active it chooses vector
|
|
|
|
0x30 and lets the sw choose the priorities. */
|
2009-05-05 18:38:39 +08:00
|
|
|
if (fs->regs[R_R_MASKED_VECT]) {
|
|
|
|
uint32_t mv = fs->regs[R_R_MASKED_VECT];
|
2009-01-07 21:30:41 +08:00
|
|
|
for (i = 0; i < 31; i++) {
|
|
|
|
if (mv & 1) {
|
|
|
|
vector = 0x31 + i;
|
|
|
|
/* Check for multiple interrupts. */
|
|
|
|
if (mv > 1)
|
|
|
|
vector = 0x30;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mv >>= 1;
|
|
|
|
}
|
|
|
|
if (vector) {
|
|
|
|
env->interrupt_vector = vector;
|
|
|
|
D(printf("%s vector=%x\n", __func__, vector));
|
|
|
|
cpu_interrupt(env, CPU_INTERRUPT_HARD);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
env->interrupt_vector = 0;
|
|
|
|
cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
|
|
|
|
D(printf("%s reset irqs\n", __func__));
|
|
|
|
}
|
2008-03-14 09:04:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t pic_readl (void *opaque, target_phys_addr_t addr)
|
|
|
|
{
|
2009-05-05 18:41:35 +08:00
|
|
|
struct fs_pic_state *fs = opaque;
|
2008-03-14 09:04:24 +08:00
|
|
|
uint32_t rval;
|
|
|
|
|
2009-05-05 18:38:39 +08:00
|
|
|
rval = fs->regs[addr >> 2];
|
2008-03-14 09:04:24 +08:00
|
|
|
D(printf("%s %x=%x\n", __func__, addr, rval));
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pic_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
|
|
|
|
{
|
2009-05-05 18:41:35 +08:00
|
|
|
struct fs_pic_state *fs = opaque;
|
2008-03-14 09:04:24 +08:00
|
|
|
D(printf("%s addr=%x val=%x\n", __func__, addr, value));
|
2009-05-05 18:38:39 +08:00
|
|
|
|
|
|
|
if (addr == R_RW_MASK) {
|
|
|
|
fs->regs[R_RW_MASK] = value;
|
|
|
|
pic_update(fs);
|
2008-03-14 09:04:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static CPUReadMemoryFunc *pic_read[] = {
|
2009-01-07 21:30:41 +08:00
|
|
|
NULL, NULL,
|
2008-03-14 09:04:24 +08:00
|
|
|
&pic_readl,
|
|
|
|
};
|
|
|
|
|
|
|
|
static CPUWriteMemoryFunc *pic_write[] = {
|
2009-01-07 21:30:41 +08:00
|
|
|
NULL, NULL,
|
2008-03-14 09:04:24 +08:00
|
|
|
&pic_writel,
|
|
|
|
};
|
|
|
|
|
2009-03-06 07:01:23 +08:00
|
|
|
void pic_info(Monitor *mon)
|
2008-03-14 09:04:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-03-06 07:01:23 +08:00
|
|
|
void irq_info(Monitor *mon)
|
2008-03-14 09:04:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-06-10 07:33:30 +08:00
|
|
|
static void nmi_handler(void *opaque, int irq, int level)
|
|
|
|
{
|
2009-05-05 18:41:35 +08:00
|
|
|
struct fs_pic_state *fs = (void *)opaque;
|
2008-06-10 07:33:30 +08:00
|
|
|
CPUState *env = fs->env;
|
|
|
|
uint32_t mask;
|
|
|
|
|
|
|
|
mask = 1 << irq;
|
|
|
|
if (level)
|
2009-05-05 18:38:39 +08:00
|
|
|
fs->regs[R_R_NMI] |= mask;
|
2008-06-10 07:33:30 +08:00
|
|
|
else
|
2009-05-05 18:38:39 +08:00
|
|
|
fs->regs[R_R_NMI] &= ~mask;
|
2008-06-10 07:33:30 +08:00
|
|
|
|
2009-05-05 18:38:39 +08:00
|
|
|
if (fs->regs[R_R_NMI])
|
2008-06-10 07:33:30 +08:00
|
|
|
cpu_interrupt(env, CPU_INTERRUPT_NMI);
|
|
|
|
else
|
|
|
|
cpu_reset_interrupt(env, CPU_INTERRUPT_NMI);
|
|
|
|
}
|
|
|
|
|
2009-05-16 06:23:15 +08:00
|
|
|
static void irq_handler(void *opaque, int irq, int level)
|
2008-06-10 07:33:30 +08:00
|
|
|
{
|
2009-05-16 06:23:15 +08:00
|
|
|
struct fs_pic_state *fs = (void *)opaque;
|
|
|
|
|
|
|
|
if (irq >= 30)
|
|
|
|
return nmi_handler(opaque, irq, level);
|
|
|
|
|
|
|
|
irq -= 1;
|
|
|
|
fs->regs[R_R_VECT] &= ~(1 << irq);
|
|
|
|
fs->regs[R_R_VECT] |= (!!level << irq);
|
|
|
|
pic_update(fs);
|
2008-06-10 07:33:30 +08:00
|
|
|
}
|
|
|
|
|
2009-05-16 06:23:15 +08:00
|
|
|
qemu_irq *etraxfs_pic_init(CPUState *env, target_phys_addr_t base)
|
2008-03-14 09:04:24 +08:00
|
|
|
{
|
2009-05-05 18:41:35 +08:00
|
|
|
struct fs_pic_state *fs = NULL;
|
2009-05-16 06:23:15 +08:00
|
|
|
qemu_irq *irq;
|
2008-03-14 09:04:24 +08:00
|
|
|
int intr_vect_regs;
|
|
|
|
|
2009-05-16 06:23:15 +08:00
|
|
|
fs = qemu_mallocz(sizeof *fs);
|
2008-06-10 07:33:30 +08:00
|
|
|
fs->env = env;
|
2009-05-16 06:23:15 +08:00
|
|
|
irq = qemu_allocate_irqs(irq_handler, fs, 32);
|
2008-03-14 09:04:24 +08:00
|
|
|
|
|
|
|
intr_vect_regs = cpu_register_io_memory(0, pic_read, pic_write, fs);
|
2009-05-05 18:38:39 +08:00
|
|
|
cpu_register_physical_memory(base, R_MAX * 4, intr_vect_regs);
|
2009-05-16 06:23:15 +08:00
|
|
|
return irq;
|
2008-03-14 09:04:24 +08:00
|
|
|
}
|