mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
hw/intc/loongarch_extioi: Add kernel irqchip realize function
Function kvm_extioi_realize() is added if kvm_irqchip_in_kernel is set. It is to create and initialize ExtIOI device in kernel mode. Reviewed-by: Song Gao <gaosong@loongson.cn> Signed-off-by: Bibo Mao <maobibo@loongson.cn> Message-ID: <20250606063033.2557365-2-maobibo@loongson.cn> Signed-off-by: Song Gao <gaosong@loongson.cn>
This commit is contained in:
+19
-12
@@ -12,6 +12,7 @@
|
||||
#include "hw/irq.h"
|
||||
#include "hw/loongarch/virt.h"
|
||||
#include "system/address-spaces.h"
|
||||
#include "system/kvm.h"
|
||||
#include "hw/intc/loongarch_extioi.h"
|
||||
#include "trace.h"
|
||||
|
||||
@@ -351,23 +352,29 @@ static void loongarch_extioi_realize(DeviceState *dev, Error **errp)
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < EXTIOI_IRQS; i++) {
|
||||
sysbus_init_irq(sbd, &s->irq[i]);
|
||||
}
|
||||
|
||||
qdev_init_gpio_in(dev, extioi_setirq, EXTIOI_IRQS);
|
||||
memory_region_init_io(&s->extioi_system_mem, OBJECT(s), &extioi_ops,
|
||||
s, "extioi_system_mem", 0x900);
|
||||
sysbus_init_mmio(sbd, &s->extioi_system_mem);
|
||||
|
||||
if (s->features & BIT(EXTIOI_HAS_VIRT_EXTENSION)) {
|
||||
memory_region_init_io(&s->virt_extend, OBJECT(s), &extioi_virt_ops,
|
||||
s, "extioi_virt", EXTIOI_VIRT_SIZE);
|
||||
sysbus_init_mmio(sbd, &s->virt_extend);
|
||||
s->features |= EXTIOI_VIRT_HAS_FEATURES;
|
||||
} else {
|
||||
s->status |= BIT(EXTIOI_ENABLE);
|
||||
}
|
||||
|
||||
if (kvm_irqchip_in_kernel()) {
|
||||
kvm_extioi_realize(dev, errp);
|
||||
} else {
|
||||
for (i = 0; i < EXTIOI_IRQS; i++) {
|
||||
sysbus_init_irq(sbd, &s->irq[i]);
|
||||
}
|
||||
|
||||
qdev_init_gpio_in(dev, extioi_setirq, EXTIOI_IRQS);
|
||||
memory_region_init_io(&s->extioi_system_mem, OBJECT(s), &extioi_ops,
|
||||
s, "extioi_system_mem", 0x900);
|
||||
sysbus_init_mmio(sbd, &s->extioi_system_mem);
|
||||
if (s->features & BIT(EXTIOI_HAS_VIRT_EXTENSION)) {
|
||||
memory_region_init_io(&s->virt_extend, OBJECT(s), &extioi_virt_ops,
|
||||
s, "extioi_virt", EXTIOI_VIRT_SIZE);
|
||||
sysbus_init_mmio(sbd, &s->virt_extend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void loongarch_extioi_unrealize(DeviceState *dev)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* LoongArch EXTIOI interrupt kvm support
|
||||
*
|
||||
* Copyright (C) 2025 Loongson Technology Corporation Limited
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/typedefs.h"
|
||||
#include "hw/intc/loongarch_extioi.h"
|
||||
#include "linux/kvm.h"
|
||||
#include "qapi/error.h"
|
||||
#include "system/kvm.h"
|
||||
|
||||
void kvm_extioi_realize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
LoongArchExtIOICommonState *lecs = LOONGARCH_EXTIOI_COMMON(dev);
|
||||
LoongArchExtIOIState *les = LOONGARCH_EXTIOI(dev);
|
||||
int ret;
|
||||
|
||||
ret = kvm_create_device(kvm_state, KVM_DEV_TYPE_LOONGARCH_EIOINTC, false);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "create KVM_LOONGARCH_EIOINTC failed: %s\n",
|
||||
strerror(-ret));
|
||||
abort();
|
||||
}
|
||||
|
||||
les->dev_fd = ret;
|
||||
ret = kvm_device_access(les->dev_fd, KVM_DEV_LOONGARCH_EXTIOI_GRP_CTRL,
|
||||
KVM_DEV_LOONGARCH_EXTIOI_CTRL_INIT_NUM_CPU,
|
||||
&lecs->num_cpu, true, NULL);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "KVM_LOONGARCH_EXTIOI_INIT_NUM_CPU failed: %s\n",
|
||||
strerror(-ret));
|
||||
abort();
|
||||
}
|
||||
|
||||
ret = kvm_device_access(les->dev_fd, KVM_DEV_LOONGARCH_EXTIOI_GRP_CTRL,
|
||||
KVM_DEV_LOONGARCH_EXTIOI_CTRL_INIT_FEATURE,
|
||||
&lecs->features, true, NULL);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "KVM_LOONGARCH_EXTIOI_INIT_FEATURE failed: %s\n",
|
||||
strerror(-ret));
|
||||
abort();
|
||||
}
|
||||
}
|
||||
@@ -74,3 +74,5 @@ specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: files('loongarch_ipi.c'))
|
||||
specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarch_pch_pic.c', 'loongarch_pic_common.c'))
|
||||
specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_MSI', if_true: files('loongarch_pch_msi.c'))
|
||||
specific_ss.add(when: 'CONFIG_LOONGARCH_EXTIOI', if_true: files('loongarch_extioi.c', 'loongarch_extioi_common.c'))
|
||||
specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_LOONGARCH_EXTIOI'],
|
||||
if_true: files('loongarch_extioi_kvm.c'))
|
||||
|
||||
@@ -15,6 +15,7 @@ OBJECT_DECLARE_TYPE(LoongArchExtIOIState, LoongArchExtIOIClass, LOONGARCH_EXTIOI
|
||||
|
||||
struct LoongArchExtIOIState {
|
||||
LoongArchExtIOICommonState parent_obj;
|
||||
int dev_fd;
|
||||
};
|
||||
|
||||
struct LoongArchExtIOIClass {
|
||||
@@ -25,4 +26,6 @@ struct LoongArchExtIOIClass {
|
||||
ResettablePhases parent_phases;
|
||||
};
|
||||
|
||||
void kvm_extioi_realize(DeviceState *dev, Error **errp);
|
||||
|
||||
#endif /* LOONGARCH_EXTIOI_H */
|
||||
|
||||
Reference in New Issue
Block a user