2007-09-17 01:08:06 +04:00
|
|
|
/*
|
2007-06-03 15:13:39 +04:00
|
|
|
* ColdFire Interrupt Controller emulation.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 CodeSourcery.
|
|
|
|
*
|
2011-06-26 06:21:35 +04:00
|
|
|
* This code is licensed under the GPL
|
2007-06-03 15:13:39 +04:00
|
|
|
*/
|
2019-05-23 17:35:07 +03:00
|
|
|
|
2016-01-26 21:17:23 +03:00
|
|
|
#include "qemu/osdep.h"
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 08:31:58 +03:00
|
|
|
#include "qapi/error.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2020-05-26 12:40:52 +03:00
|
|
|
#include "qemu/log.h"
|
2016-01-19 23:51:44 +03:00
|
|
|
#include "cpu.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.h"
|
2017-02-12 17:41:35 +03:00
|
|
|
#include "hw/sysbus.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/m68k/mcf.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2007-06-03 15:13:39 +04:00
|
|
|
|
2017-02-12 17:41:35 +03:00
|
|
|
#define TYPE_MCF_INTC "mcf-intc"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(mcf_intc_state, MCF_INTC)
|
2017-02-12 17:41:35 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct mcf_intc_state {
|
2017-02-12 17:41:35 +03:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2011-11-24 17:31:15 +04:00
|
|
|
MemoryRegion iomem;
|
2007-06-03 15:13:39 +04:00
|
|
|
uint64_t ipr;
|
|
|
|
uint64_t imr;
|
|
|
|
uint64_t ifr;
|
|
|
|
uint64_t enabled;
|
|
|
|
uint8_t icr[64];
|
2013-01-18 17:15:09 +04:00
|
|
|
M68kCPU *cpu;
|
2007-06-03 15:13:39 +04:00
|
|
|
int active_vector;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2007-06-03 15:13:39 +04:00
|
|
|
|
|
|
|
static void mcf_intc_update(mcf_intc_state *s)
|
|
|
|
{
|
|
|
|
uint64_t active;
|
|
|
|
int i;
|
|
|
|
int best;
|
|
|
|
int best_level;
|
|
|
|
|
|
|
|
active = (s->ipr | s->ifr) & s->enabled & ~s->imr;
|
|
|
|
best_level = 0;
|
|
|
|
best = 64;
|
|
|
|
if (active) {
|
|
|
|
for (i = 0; i < 64; i++) {
|
|
|
|
if ((active & 1) != 0 && s->icr[i] >= best_level) {
|
|
|
|
best_level = s->icr[i];
|
|
|
|
best = i;
|
|
|
|
}
|
|
|
|
active >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s->active_vector = ((best == 64) ? 24 : (best + 64));
|
2013-01-18 17:20:52 +04:00
|
|
|
m68k_set_irq_level(s->cpu, best_level, s->active_vector);
|
2007-06-03 15:13:39 +04:00
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t mcf_intc_read(void *opaque, hwaddr addr,
|
2011-11-24 17:31:15 +04:00
|
|
|
unsigned size)
|
2007-06-03 15:13:39 +04:00
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
mcf_intc_state *s = (mcf_intc_state *)opaque;
|
|
|
|
offset = addr & 0xff;
|
|
|
|
if (offset >= 0x40 && offset < 0x80) {
|
|
|
|
return s->icr[offset - 0x40];
|
|
|
|
}
|
|
|
|
switch (offset) {
|
|
|
|
case 0x00:
|
|
|
|
return (uint32_t)(s->ipr >> 32);
|
|
|
|
case 0x04:
|
|
|
|
return (uint32_t)s->ipr;
|
|
|
|
case 0x08:
|
|
|
|
return (uint32_t)(s->imr >> 32);
|
|
|
|
case 0x0c:
|
|
|
|
return (uint32_t)s->imr;
|
|
|
|
case 0x10:
|
|
|
|
return (uint32_t)(s->ifr >> 32);
|
|
|
|
case 0x14:
|
|
|
|
return (uint32_t)s->ifr;
|
|
|
|
case 0xe0: /* SWIACK. */
|
|
|
|
return s->active_vector;
|
|
|
|
case 0xe1: case 0xe2: case 0xe3: case 0xe4:
|
|
|
|
case 0xe5: case 0xe6: case 0xe7:
|
|
|
|
/* LnIACK */
|
2020-05-26 12:40:52 +03:00
|
|
|
qemu_log_mask(LOG_UNIMP, "%s: LnIACK not implemented (offset 0x%02x)\n",
|
|
|
|
__func__, offset);
|
|
|
|
/* fallthru */
|
2007-06-03 15:13:39 +04:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void mcf_intc_write(void *opaque, hwaddr addr,
|
2011-11-24 17:31:15 +04:00
|
|
|
uint64_t val, unsigned size)
|
2007-06-03 15:13:39 +04:00
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
mcf_intc_state *s = (mcf_intc_state *)opaque;
|
|
|
|
offset = addr & 0xff;
|
|
|
|
if (offset >= 0x40 && offset < 0x80) {
|
|
|
|
int n = offset - 0x40;
|
|
|
|
s->icr[n] = val;
|
|
|
|
if (val == 0)
|
|
|
|
s->enabled &= ~(1ull << n);
|
|
|
|
else
|
|
|
|
s->enabled |= (1ull << n);
|
|
|
|
mcf_intc_update(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (offset) {
|
|
|
|
case 0x00: case 0x04:
|
|
|
|
/* Ignore IPR writes. */
|
|
|
|
return;
|
|
|
|
case 0x08:
|
|
|
|
s->imr = (s->imr & 0xffffffff) | ((uint64_t)val << 32);
|
|
|
|
break;
|
|
|
|
case 0x0c:
|
|
|
|
s->imr = (s->imr & 0xffffffff00000000ull) | (uint32_t)val;
|
|
|
|
break;
|
2015-06-19 16:43:24 +03:00
|
|
|
case 0x1c:
|
|
|
|
if (val & 0x40) {
|
|
|
|
s->imr = ~0ull;
|
|
|
|
} else {
|
|
|
|
s->imr |= (0x1ull << (val & 0x3f));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x1d:
|
|
|
|
if (val & 0x40) {
|
|
|
|
s->imr = 0ull;
|
|
|
|
} else {
|
|
|
|
s->imr &= ~(0x1ull << (val & 0x3f));
|
|
|
|
}
|
|
|
|
break;
|
2007-06-03 15:13:39 +04:00
|
|
|
default:
|
2020-05-26 12:40:52 +03:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%02x\n",
|
|
|
|
__func__, offset);
|
|
|
|
return;
|
2007-06-03 15:13:39 +04:00
|
|
|
}
|
|
|
|
mcf_intc_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mcf_intc_set_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
mcf_intc_state *s = (mcf_intc_state *)opaque;
|
|
|
|
if (irq >= 64)
|
|
|
|
return;
|
|
|
|
if (level)
|
|
|
|
s->ipr |= 1ull << irq;
|
|
|
|
else
|
|
|
|
s->ipr &= ~(1ull << irq);
|
|
|
|
mcf_intc_update(s);
|
|
|
|
}
|
|
|
|
|
2017-02-12 17:41:35 +03:00
|
|
|
static void mcf_intc_reset(DeviceState *dev)
|
2007-06-03 15:13:39 +04:00
|
|
|
{
|
2017-02-12 17:41:35 +03:00
|
|
|
mcf_intc_state *s = MCF_INTC(dev);
|
|
|
|
|
2007-06-03 15:13:39 +04:00
|
|
|
s->imr = ~0ull;
|
|
|
|
s->ipr = 0;
|
|
|
|
s->ifr = 0;
|
|
|
|
s->enabled = 0;
|
|
|
|
memset(s->icr, 0, 64);
|
|
|
|
s->active_vector = 24;
|
|
|
|
}
|
|
|
|
|
2011-11-24 17:31:15 +04:00
|
|
|
static const MemoryRegionOps mcf_intc_ops = {
|
|
|
|
.read = mcf_intc_read,
|
|
|
|
.write = mcf_intc_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-06-03 15:13:39 +04:00
|
|
|
};
|
|
|
|
|
2017-02-12 17:41:35 +03:00
|
|
|
static void mcf_intc_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
mcf_intc_state *s = MCF_INTC(obj);
|
|
|
|
|
|
|
|
memory_region_init_io(&s->iomem, obj, &mcf_intc_ops, s, "mcf", 0x100);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mcf_intc_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
|
|
|
|
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
|
|
|
dc->reset = mcf_intc_reset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo mcf_intc_gate_info = {
|
|
|
|
.name = TYPE_MCF_INTC,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(mcf_intc_state),
|
|
|
|
.instance_init = mcf_intc_instance_init,
|
|
|
|
.class_init = mcf_intc_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void mcf_intc_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&mcf_intc_gate_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(mcf_intc_register_types)
|
|
|
|
|
2011-11-24 17:31:15 +04:00
|
|
|
qemu_irq *mcf_intc_init(MemoryRegion *sysmem,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr base,
|
2013-01-18 17:15:09 +04:00
|
|
|
M68kCPU *cpu)
|
2007-06-03 15:13:39 +04:00
|
|
|
{
|
2017-02-12 17:41:35 +03:00
|
|
|
DeviceState *dev;
|
2007-06-03 15:13:39 +04:00
|
|
|
mcf_intc_state *s;
|
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 08:31:58 +03:00
|
|
|
dev = qdev_new(TYPE_MCF_INTC);
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 08:32:34 +03:00
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
|
2017-02-12 17:41:35 +03:00
|
|
|
|
|
|
|
s = MCF_INTC(dev);
|
2013-01-18 17:15:09 +04:00
|
|
|
s->cpu = cpu;
|
2007-06-03 15:13:39 +04:00
|
|
|
|
2011-11-24 17:31:15 +04:00
|
|
|
memory_region_add_subregion(sysmem, base, &s->iomem);
|
2007-06-03 15:13:39 +04:00
|
|
|
|
|
|
|
return qemu_allocate_irqs(mcf_intc_set_irq, s, 64);
|
|
|
|
}
|