|
@@ -12,28 +12,73 @@
|
|
#include "migration/vmstate.h"
|
|
#include "migration/vmstate.h"
|
|
#include "target/loongarch/cpu.h"
|
|
#include "target/loongarch/cpu.h"
|
|
|
|
|
|
|
|
+static ExtIOICore *loongarch_extioi_get_cpu(LoongArchExtIOICommonState *s,
|
|
|
|
+ DeviceState *dev)
|
|
|
|
+{
|
|
|
|
+ CPUClass *k = CPU_GET_CLASS(dev);
|
|
|
|
+ uint64_t arch_id = k->get_arch_id(CPU(dev));
|
|
|
|
+ int i;
|
|
|
|
+
|
|
|
|
+ for (i = 0; i < s->num_cpu; i++) {
|
|
|
|
+ if (s->cpu[i].arch_id == arch_id) {
|
|
|
|
+ return &s->cpu[i];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return NULL;
|
|
|
|
+}
|
|
|
|
+
|
|
static void loongarch_extioi_cpu_plug(HotplugHandler *hotplug_dev,
|
|
static void loongarch_extioi_cpu_plug(HotplugHandler *hotplug_dev,
|
|
DeviceState *dev, Error **errp)
|
|
DeviceState *dev, Error **errp)
|
|
{
|
|
{
|
|
|
|
+ LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(hotplug_dev);
|
|
Object *obj = OBJECT(dev);
|
|
Object *obj = OBJECT(dev);
|
|
|
|
+ ExtIOICore *core;
|
|
|
|
+ int pin, index;
|
|
|
|
|
|
if (!object_dynamic_cast(obj, TYPE_LOONGARCH_CPU)) {
|
|
if (!object_dynamic_cast(obj, TYPE_LOONGARCH_CPU)) {
|
|
warn_report("LoongArch extioi: Invalid %s device type",
|
|
warn_report("LoongArch extioi: Invalid %s device type",
|
|
object_get_typename(obj));
|
|
object_get_typename(obj));
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ core = loongarch_extioi_get_cpu(s, dev);
|
|
|
|
+ if (!core) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ core->cpu = CPU(dev);
|
|
|
|
+ index = core - s->cpu;
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * connect extioi irq to the cpu irq
|
|
|
|
+ * cpu_pin[LS3A_INTC_IP + 2 : 2] <= intc_pin[LS3A_INTC_IP : 0]
|
|
|
|
+ */
|
|
|
|
+ for (pin = 0; pin < LS3A_INTC_IP; pin++) {
|
|
|
|
+ qdev_connect_gpio_out(DEVICE(s), index * LS3A_INTC_IP + pin,
|
|
|
|
+ qdev_get_gpio_in(dev, pin + 2));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
static void loongarch_extioi_cpu_unplug(HotplugHandler *hotplug_dev,
|
|
static void loongarch_extioi_cpu_unplug(HotplugHandler *hotplug_dev,
|
|
DeviceState *dev, Error **errp)
|
|
DeviceState *dev, Error **errp)
|
|
{
|
|
{
|
|
|
|
+ LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(hotplug_dev);
|
|
Object *obj = OBJECT(dev);
|
|
Object *obj = OBJECT(dev);
|
|
|
|
+ ExtIOICore *core;
|
|
|
|
|
|
if (!object_dynamic_cast(obj, TYPE_LOONGARCH_CPU)) {
|
|
if (!object_dynamic_cast(obj, TYPE_LOONGARCH_CPU)) {
|
|
warn_report("LoongArch extioi: Invalid %s device type",
|
|
warn_report("LoongArch extioi: Invalid %s device type",
|
|
object_get_typename(obj));
|
|
object_get_typename(obj));
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ core = loongarch_extioi_get_cpu(s, dev);
|
|
|
|
+ if (!core) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ core->cpu = NULL;
|
|
}
|
|
}
|
|
|
|
|
|
static void loongarch_extioi_common_realize(DeviceState *dev, Error **errp)
|
|
static void loongarch_extioi_common_realize(DeviceState *dev, Error **errp)
|