2007-10-05 01:53:55 +04:00
|
|
|
/*
|
|
|
|
* SuperH interrupt controller module
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Magnus Damm
|
|
|
|
* Based on sh_timer.c and arm_timer.c by Paul Brook
|
|
|
|
* Copyright (c) 2005-2006 CodeSourcery.
|
|
|
|
*
|
2011-06-26 06:21:35 +04:00
|
|
|
* This code is licensed under the GPL.
|
2007-10-05 01:53:55 +04:00
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:19 +03:00
|
|
|
#include "qemu/osdep.h"
|
2021-10-30 00:02:09 +03:00
|
|
|
#include "qemu/log.h"
|
2016-01-19 23:51:44 +03:00
|
|
|
#include "cpu.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/sh4/sh_intc.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/sh4/sh.h"
|
2021-10-30 00:02:09 +03:00
|
|
|
#include "trace.h"
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2007-12-02 09:18:24 +03:00
|
|
|
void sh_intc_toggle_source(struct intc_source *source,
|
2021-10-30 00:02:09 +03:00
|
|
|
int enable_adj, int assert_adj)
|
2007-12-02 09:18:24 +03:00
|
|
|
{
|
|
|
|
int enable_changed = 0;
|
|
|
|
int pending_changed = 0;
|
|
|
|
int old_pending;
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if (source->enable_count == source->enable_max && enable_adj == -1) {
|
2007-12-02 09:18:24 +03:00
|
|
|
enable_changed = -1;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-12-02 09:18:24 +03:00
|
|
|
source->enable_count += enable_adj;
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if (source->enable_count == source->enable_max) {
|
2007-12-02 09:18:24 +03:00
|
|
|
enable_changed = 1;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-12-02 09:18:24 +03:00
|
|
|
source->asserted += assert_adj;
|
|
|
|
|
|
|
|
old_pending = source->pending;
|
|
|
|
source->pending = source->asserted &&
|
|
|
|
(source->enable_count == source->enable_max);
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if (old_pending != source->pending) {
|
2007-12-02 09:18:24 +03:00
|
|
|
pending_changed = 1;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-12-02 09:18:24 +03:00
|
|
|
if (pending_changed) {
|
|
|
|
if (source->pending) {
|
|
|
|
source->parent->pending++;
|
2013-01-18 18:03:43 +04:00
|
|
|
if (source->parent->pending == 1) {
|
2013-05-30 00:29:20 +04:00
|
|
|
cpu_interrupt(first_cpu, CPU_INTERRUPT_HARD);
|
2013-01-18 18:03:43 +04:00
|
|
|
}
|
2013-01-18 01:30:20 +04:00
|
|
|
} else {
|
2007-12-02 09:18:24 +03:00
|
|
|
source->parent->pending--;
|
2013-01-18 01:30:20 +04:00
|
|
|
if (source->parent->pending == 0) {
|
2013-05-30 00:29:20 +04:00
|
|
|
cpu_reset_interrupt(first_cpu, CPU_INTERRUPT_HARD);
|
2013-01-18 01:30:20 +04:00
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-12-02 09:18:24 +03:00
|
|
|
}
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if (enable_changed || assert_adj || pending_changed) {
|
|
|
|
trace_sh_intc_sources(source->parent->pending, source->asserted,
|
|
|
|
source->enable_count, source->enable_max,
|
|
|
|
source->vect, source->asserted ? "asserted " :
|
|
|
|
assert_adj ? "deasserted" : "",
|
|
|
|
enable_changed == 1 ? "enabled " :
|
|
|
|
enable_changed == -1 ? "disabled " : "",
|
|
|
|
source->pending ? "pending" : "");
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-12-02 09:18:24 +03:00
|
|
|
}
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
static void sh_intc_set_irq(void *opaque, int n, int level)
|
2008-11-22 00:06:42 +03:00
|
|
|
{
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_desc *desc = opaque;
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_source *source = &desc->sources[n];
|
2008-11-22 00:06:42 +03:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if (level && !source->asserted) {
|
|
|
|
sh_intc_toggle_source(source, 0, 1);
|
|
|
|
} else if (!level && source->asserted) {
|
|
|
|
sh_intc_toggle_source(source, 0, -1);
|
|
|
|
}
|
2008-11-22 00:06:42 +03:00
|
|
|
}
|
|
|
|
|
2007-12-02 09:18:24 +03:00
|
|
|
int sh_intc_get_pending_vector(struct intc_desc *desc, int imask)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* slow: use a linked lists of pending sources instead */
|
|
|
|
/* wrong: take interrupt priority into account (one list per priority) */
|
|
|
|
|
|
|
|
if (imask == 0x0f) {
|
|
|
|
return -1; /* FIXME, update code to include priority per source */
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < desc->nr_sources; i++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_source *source = &desc->sources[i];
|
2007-12-02 09:18:24 +03:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if (source->pending) {
|
2021-10-30 00:02:09 +03:00
|
|
|
trace_sh_intc_pending(desc->pending, source->vect);
|
2007-12-02 09:18:24 +03:00
|
|
|
return source->vect;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-12-02 09:18:24 +03:00
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
g_assert_not_reached();
|
2007-12-02 09:18:24 +03:00
|
|
|
}
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
typedef enum {
|
|
|
|
INTC_MODE_NONE,
|
|
|
|
INTC_MODE_DUAL_SET,
|
|
|
|
INTC_MODE_DUAL_CLR,
|
|
|
|
INTC_MODE_ENABLE_REG,
|
|
|
|
INTC_MODE_MASK_REG,
|
|
|
|
} SHIntCMode;
|
|
|
|
#define INTC_MODE_IS_PRIO 0x80
|
|
|
|
|
|
|
|
static SHIntCMode sh_intc_mode(unsigned long address, unsigned long set_reg,
|
|
|
|
unsigned long clr_reg)
|
2007-10-05 01:53:55 +04:00
|
|
|
{
|
2021-10-30 00:02:09 +03:00
|
|
|
if (address != A7ADDR(set_reg) && address != A7ADDR(clr_reg)) {
|
2007-10-05 01:53:55 +04:00
|
|
|
return INTC_MODE_NONE;
|
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
if (set_reg && clr_reg) {
|
|
|
|
return address == A7ADDR(set_reg) ?
|
|
|
|
INTC_MODE_DUAL_SET : INTC_MODE_DUAL_CLR;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
return set_reg ? INTC_MODE_ENABLE_REG : INTC_MODE_MASK_REG;
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_intc_locate(struct intc_desc *desc,
|
2021-10-30 00:02:09 +03:00
|
|
|
unsigned long address,
|
|
|
|
unsigned long **datap,
|
|
|
|
intc_enum **enums,
|
|
|
|
unsigned int *first,
|
|
|
|
unsigned int *width,
|
|
|
|
unsigned int *modep)
|
2007-10-05 01:53:55 +04:00
|
|
|
{
|
2021-10-30 00:02:09 +03:00
|
|
|
SHIntCMode mode;
|
|
|
|
unsigned int i;
|
2007-10-05 01:53:55 +04:00
|
|
|
|
|
|
|
/* this is slow but works for now */
|
|
|
|
|
|
|
|
if (desc->mask_regs) {
|
|
|
|
for (i = 0; i < desc->nr_mask_regs; i++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_mask_reg *mr = &desc->mask_regs[i];
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
mode = sh_intc_mode(address, mr->set_reg, mr->clr_reg);
|
2021-10-30 00:02:09 +03:00
|
|
|
if (mode != INTC_MODE_NONE) {
|
|
|
|
*modep = mode;
|
|
|
|
*datap = &mr->value;
|
|
|
|
*enums = mr->enum_ids;
|
|
|
|
*first = mr->reg_width - 1;
|
|
|
|
*width = 1;
|
|
|
|
return;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (desc->prio_regs) {
|
|
|
|
for (i = 0; i < desc->nr_prio_regs; i++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_prio_reg *pr = &desc->prio_regs[i];
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
mode = sh_intc_mode(address, pr->set_reg, pr->clr_reg);
|
2021-10-30 00:02:09 +03:00
|
|
|
if (mode != INTC_MODE_NONE) {
|
|
|
|
*modep = mode | INTC_MODE_IS_PRIO;
|
|
|
|
*datap = &pr->value;
|
|
|
|
*enums = pr->enum_ids;
|
|
|
|
*first = pr->reg_width / pr->field_width - 1;
|
|
|
|
*width = pr->field_width;
|
|
|
|
return;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
g_assert_not_reached();
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
2007-12-02 09:18:24 +03:00
|
|
|
static void sh_intc_toggle_mask(struct intc_desc *desc, intc_enum id,
|
2021-10-30 00:02:09 +03:00
|
|
|
int enable, int is_group)
|
2007-10-05 01:53:55 +04:00
|
|
|
{
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_source *source = &desc->sources[id];
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if (!id) {
|
2021-10-30 00:02:09 +03:00
|
|
|
return;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
if (!source->next_enum_id && (!source->enable_max || !source->vect)) {
|
2021-10-30 00:02:09 +03:00
|
|
|
qemu_log_mask(LOG_UNIMP,
|
|
|
|
"sh_intc: reserved interrupt source %d modified\n", id);
|
2021-10-30 00:02:09 +03:00
|
|
|
return;
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if (source->vect) {
|
2007-12-02 09:18:24 +03:00
|
|
|
sh_intc_toggle_source(source, enable ? 1 : -1, 0);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
|
|
|
|
if ((is_group || !source->vect) && source->next_enum_id) {
|
2007-12-02 09:18:24 +03:00
|
|
|
sh_intc_toggle_mask(desc, source->next_enum_id, enable, 1);
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!source->vect) {
|
2021-10-30 00:02:09 +03:00
|
|
|
trace_sh_intc_set(id, !!enable);
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
static uint64_t sh_intc_read(void *opaque, hwaddr offset, unsigned size)
|
2007-10-05 01:53:55 +04:00
|
|
|
{
|
|
|
|
struct intc_desc *desc = opaque;
|
2021-10-30 00:02:09 +03:00
|
|
|
intc_enum *enum_ids;
|
|
|
|
unsigned int first;
|
|
|
|
unsigned int width;
|
|
|
|
unsigned int mode;
|
2007-10-05 01:53:55 +04:00
|
|
|
unsigned long *valuep;
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
sh_intc_locate(desc, (unsigned long)offset, &valuep,
|
2021-10-30 00:02:09 +03:00
|
|
|
&enum_ids, &first, &width, &mode);
|
2021-10-30 00:02:09 +03:00
|
|
|
trace_sh_intc_read(size, (uint64_t)offset, *valuep);
|
2007-10-05 01:53:55 +04:00
|
|
|
return *valuep;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void sh_intc_write(void *opaque, hwaddr offset,
|
2011-11-17 17:23:01 +04:00
|
|
|
uint64_t value, unsigned size)
|
2007-10-05 01:53:55 +04:00
|
|
|
{
|
|
|
|
struct intc_desc *desc = opaque;
|
2021-10-30 00:02:09 +03:00
|
|
|
intc_enum *enum_ids;
|
|
|
|
unsigned int first;
|
|
|
|
unsigned int width;
|
|
|
|
unsigned int mode;
|
2007-10-05 01:53:55 +04:00
|
|
|
unsigned long *valuep;
|
2021-10-30 00:02:09 +03:00
|
|
|
unsigned int k;
|
2007-10-05 01:53:55 +04:00
|
|
|
unsigned long mask;
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
trace_sh_intc_write(size, (uint64_t)offset, value);
|
2021-10-30 00:02:09 +03:00
|
|
|
sh_intc_locate(desc, (unsigned long)offset, &valuep,
|
2021-10-30 00:02:09 +03:00
|
|
|
&enum_ids, &first, &width, &mode);
|
2007-10-05 01:53:55 +04:00
|
|
|
switch (mode) {
|
2021-10-30 00:02:09 +03:00
|
|
|
case INTC_MODE_ENABLE_REG | INTC_MODE_IS_PRIO:
|
|
|
|
break;
|
|
|
|
case INTC_MODE_DUAL_SET:
|
|
|
|
value |= *valuep;
|
|
|
|
break;
|
|
|
|
case INTC_MODE_DUAL_CLR:
|
|
|
|
value = *valuep & ~value;
|
|
|
|
break;
|
|
|
|
default:
|
2021-10-30 00:02:09 +03:00
|
|
|
g_assert_not_reached();
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (k = 0; k <= first; k++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
mask = (1 << width) - 1;
|
|
|
|
mask <<= (first - k) * width;
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if ((*valuep & mask) != (value & mask)) {
|
|
|
|
sh_intc_toggle_mask(desc, enum_ids[k], value & mask, 0);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*valuep = value;
|
|
|
|
}
|
|
|
|
|
2012-02-25 16:37:13 +04:00
|
|
|
static const MemoryRegionOps sh_intc_ops = {
|
2011-11-17 17:23:01 +04:00
|
|
|
.read = sh_intc_read,
|
|
|
|
.write = sh_intc_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-10-05 01:53:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void sh_intc_register_source(struct intc_desc *desc,
|
2021-10-30 00:02:09 +03:00
|
|
|
intc_enum source,
|
|
|
|
struct intc_group *groups,
|
|
|
|
int nr_groups)
|
2007-10-05 01:53:55 +04:00
|
|
|
{
|
|
|
|
unsigned int i, k;
|
2021-10-30 00:02:09 +03:00
|
|
|
intc_enum id;
|
2007-10-05 01:53:55 +04:00
|
|
|
|
|
|
|
if (desc->mask_regs) {
|
|
|
|
for (i = 0; i < desc->nr_mask_regs; i++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_mask_reg *mr = &desc->mask_regs[i];
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
for (k = 0; k < ARRAY_SIZE(mr->enum_ids); k++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
id = mr->enum_ids[k];
|
|
|
|
if (id && id == source) {
|
|
|
|
desc->sources[id].enable_max++;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (desc->prio_regs) {
|
|
|
|
for (i = 0; i < desc->nr_prio_regs; i++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_prio_reg *pr = &desc->prio_regs[i];
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
for (k = 0; k < ARRAY_SIZE(pr->enum_ids); k++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
id = pr->enum_ids[k];
|
|
|
|
if (id && id == source) {
|
|
|
|
desc->sources[id].enable_max++;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (groups) {
|
|
|
|
for (i = 0; i < nr_groups; i++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_group *gr = &groups[i];
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
for (k = 0; k < ARRAY_SIZE(gr->enum_ids); k++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
id = gr->enum_ids[k];
|
|
|
|
if (id && id == source) {
|
|
|
|
desc->sources[id].enable_max++;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void sh_intc_register_sources(struct intc_desc *desc,
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_vect *vectors,
|
|
|
|
int nr_vectors,
|
|
|
|
struct intc_group *groups,
|
|
|
|
int nr_groups)
|
2007-10-05 01:53:55 +04:00
|
|
|
{
|
|
|
|
unsigned int i, k;
|
2021-10-30 00:02:09 +03:00
|
|
|
intc_enum id;
|
2007-10-05 01:53:55 +04:00
|
|
|
struct intc_source *s;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_vectors; i++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_vect *vect = &vectors[i];
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
sh_intc_register_source(desc, vect->enum_id, groups, nr_groups);
|
2021-10-30 00:02:09 +03:00
|
|
|
id = vect->enum_id;
|
|
|
|
if (id) {
|
|
|
|
s = &desc->sources[id];
|
2011-07-20 22:56:35 +04:00
|
|
|
s->vect = vect->vect;
|
2021-10-30 00:02:09 +03:00
|
|
|
trace_sh_intc_register("source", vect->enum_id, s->vect,
|
|
|
|
s->enable_count, s->enable_max);
|
2011-07-20 22:56:35 +04:00
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (groups) {
|
|
|
|
for (i = 0; i < nr_groups; i++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_group *gr = &groups[i];
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
id = gr->enum_id;
|
|
|
|
s = &desc->sources[id];
|
2021-10-30 00:02:09 +03:00
|
|
|
s->next_enum_id = gr->enum_ids[0];
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
for (k = 1; k < ARRAY_SIZE(gr->enum_ids); k++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
if (gr->enum_ids[k]) {
|
|
|
|
id = gr->enum_ids[k - 1];
|
|
|
|
s = &desc->sources[id];
|
|
|
|
s->next_enum_id = gr->enum_ids[k];
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
trace_sh_intc_register("group", gr->enum_id, 0xffff,
|
|
|
|
s->enable_count, s->enable_max);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
static unsigned int sh_intc_register(MemoryRegion *sysmem,
|
|
|
|
struct intc_desc *desc,
|
|
|
|
const unsigned long address,
|
|
|
|
const char *type,
|
|
|
|
const char *action,
|
|
|
|
const unsigned int index)
|
|
|
|
{
|
|
|
|
char name[60];
|
|
|
|
MemoryRegion *iomem, *iomem_p4, *iomem_a7;
|
|
|
|
|
|
|
|
if (!address) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
iomem = &desc->iomem;
|
2021-10-30 00:02:09 +03:00
|
|
|
iomem_p4 = &desc->iomem_aliases[index];
|
2021-10-30 00:02:09 +03:00
|
|
|
iomem_a7 = iomem_p4 + 1;
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "intc-%s-%s-%s", type, action, "p4");
|
|
|
|
memory_region_init_alias(iomem_p4, NULL, name, iomem, A7ADDR(address), 4);
|
|
|
|
memory_region_add_subregion(sysmem, P4ADDR(address), iomem_p4);
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "intc-%s-%s-%s", type, action, "a7");
|
|
|
|
memory_region_init_alias(iomem_a7, NULL, name, iomem, A7ADDR(address), 4);
|
|
|
|
memory_region_add_subregion(sysmem, A7ADDR(address), iomem_a7);
|
|
|
|
|
|
|
|
/* used to increment aliases index */
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2011-11-17 17:23:01 +04:00
|
|
|
int sh_intc_init(MemoryRegion *sysmem,
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_desc *desc,
|
|
|
|
int nr_sources,
|
|
|
|
struct intc_mask_reg *mask_regs,
|
|
|
|
int nr_mask_regs,
|
|
|
|
struct intc_prio_reg *prio_regs,
|
|
|
|
int nr_prio_regs)
|
2007-10-05 01:53:55 +04:00
|
|
|
{
|
2011-11-17 17:23:01 +04:00
|
|
|
unsigned int i, j;
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2007-12-02 09:18:24 +03:00
|
|
|
desc->pending = 0;
|
2007-10-05 01:53:55 +04:00
|
|
|
desc->nr_sources = nr_sources;
|
|
|
|
desc->mask_regs = mask_regs;
|
|
|
|
desc->nr_mask_regs = nr_mask_regs;
|
|
|
|
desc->prio_regs = prio_regs;
|
|
|
|
desc->nr_prio_regs = nr_prio_regs;
|
2021-10-30 00:02:09 +03:00
|
|
|
/* Allocate 4 MemoryRegions per register (2 actions * 2 aliases) */
|
2011-11-17 17:23:01 +04:00
|
|
|
desc->iomem_aliases = g_new0(MemoryRegion,
|
|
|
|
(nr_mask_regs + nr_prio_regs) * 4);
|
2021-10-30 00:02:09 +03:00
|
|
|
desc->sources = g_new0(struct intc_source, nr_sources);
|
|
|
|
for (i = 0; i < nr_sources; i++) {
|
|
|
|
desc->sources[i].parent = desc;
|
2007-12-02 09:18:24 +03:00
|
|
|
}
|
2008-11-22 00:06:42 +03:00
|
|
|
desc->irqs = qemu_allocate_irqs(sh_intc_set_irq, desc, nr_sources);
|
2021-10-30 00:02:09 +03:00
|
|
|
memory_region_init_io(&desc->iomem, NULL, &sh_intc_ops, desc, "intc",
|
|
|
|
0x100000000ULL);
|
2021-10-30 00:02:09 +03:00
|
|
|
j = 0;
|
2007-10-05 01:53:55 +04:00
|
|
|
if (desc->mask_regs) {
|
|
|
|
for (i = 0; i < desc->nr_mask_regs; i++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_mask_reg *mr = &desc->mask_regs[i];
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
j += sh_intc_register(sysmem, desc, mr->set_reg, "mask", "set", j);
|
|
|
|
j += sh_intc_register(sysmem, desc, mr->clr_reg, "mask", "clr", j);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (desc->prio_regs) {
|
|
|
|
for (i = 0; i < desc->nr_prio_regs; i++) {
|
2021-10-30 00:02:09 +03:00
|
|
|
struct intc_prio_reg *pr = &desc->prio_regs[i];
|
2007-10-05 01:53:55 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
j += sh_intc_register(sysmem, desc, pr->set_reg, "prio", "set", j);
|
|
|
|
j += sh_intc_register(sysmem, desc, pr->clr_reg, "prio", "clr", j);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-10-05 01:53:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-12-07 21:49:57 +03:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
/*
|
|
|
|
* Assert level <n> IRL interrupt.
|
|
|
|
* 0:deassert. 1:lowest priority,... 15:highest priority
|
|
|
|
*/
|
2008-12-07 21:49:57 +03:00
|
|
|
void sh_intc_set_irl(void *opaque, int n, int level)
|
|
|
|
{
|
|
|
|
struct intc_source *s = opaque;
|
|
|
|
int i, irl = level ^ 15;
|
2021-10-30 00:02:09 +03:00
|
|
|
intc_enum id = s->next_enum_id;
|
|
|
|
|
|
|
|
for (i = 0; id; id = s->next_enum_id, i++) {
|
|
|
|
s = &s->parent->sources[id];
|
2021-10-30 00:02:09 +03:00
|
|
|
if (i == irl) {
|
2021-10-30 00:02:09 +03:00
|
|
|
sh_intc_toggle_source(s, s->enable_count ? 0 : 1,
|
|
|
|
s->asserted ? 0 : 1);
|
2021-10-30 00:02:09 +03:00
|
|
|
} else if (s->asserted) {
|
|
|
|
sh_intc_toggle_source(s, 0, -1);
|
|
|
|
}
|
2008-12-07 21:49:57 +03:00
|
|
|
}
|
|
|
|
}
|