mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-09-09 08:17:53 -06:00
hw/intc/loongarch_pch: Add kernel irqchip realize function
Function kvm_pic_realize() is added if kvm_irqchip_in_kernel() return true. It is to notify KVM kernel to create and initialize PCH PCI device in kernel mode. Reviewed-by: Song Gao <gaosong@loongson.cn> Signed-off-by: Bibo Mao <maobibo@loongson.cn> Message-ID: <20250606063033.2557365-8-maobibo@loongson.cn> Signed-off-by: Song Gao <gaosong@loongson.cn>
This commit is contained in:
parent
5b0e05b902
commit
b758e28974
4 changed files with 53 additions and 4 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include "qemu/log.h"
|
#include "qemu/log.h"
|
||||||
#include "hw/irq.h"
|
#include "hw/irq.h"
|
||||||
#include "hw/intc/loongarch_pch_pic.h"
|
#include "hw/intc/loongarch_pch_pic.h"
|
||||||
|
#include "system/kvm.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "qapi/error.h"
|
#include "qapi/error.h"
|
||||||
|
|
||||||
|
@ -275,10 +276,15 @@ static void loongarch_pic_realize(DeviceState *dev, Error **errp)
|
||||||
|
|
||||||
qdev_init_gpio_out(dev, s->parent_irq, s->irq_num);
|
qdev_init_gpio_out(dev, s->parent_irq, s->irq_num);
|
||||||
qdev_init_gpio_in(dev, pch_pic_irq_handler, s->irq_num);
|
qdev_init_gpio_in(dev, pch_pic_irq_handler, s->irq_num);
|
||||||
memory_region_init_io(&s->iomem, OBJECT(dev),
|
|
||||||
&loongarch_pch_pic_ops,
|
if (kvm_irqchip_in_kernel()) {
|
||||||
s, TYPE_LOONGARCH_PIC, VIRT_PCH_REG_SIZE);
|
kvm_pic_realize(dev, errp);
|
||||||
sysbus_init_mmio(sbd, &s->iomem);
|
} else {
|
||||||
|
memory_region_init_io(&s->iomem, OBJECT(dev),
|
||||||
|
&loongarch_pch_pic_ops,
|
||||||
|
s, TYPE_LOONGARCH_PIC, VIRT_PCH_REG_SIZE);
|
||||||
|
sysbus_init_mmio(sbd, &s->iomem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loongarch_pic_class_init(ObjectClass *klass, const void *data)
|
static void loongarch_pic_class_init(ObjectClass *klass, const void *data)
|
||||||
|
|
38
hw/intc/loongarch_pic_kvm.c
Normal file
38
hw/intc/loongarch_pic_kvm.c
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
/*
|
||||||
|
* LoongArch kvm pch pic interrupt support
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 Loongson Technology Corporation Limited
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qemu/osdep.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
|
#include "hw/boards.h"
|
||||||
|
#include "hw/intc/loongarch_pch_pic.h"
|
||||||
|
#include "hw/loongarch/virt.h"
|
||||||
|
#include "hw/pci-host/ls7a.h"
|
||||||
|
#include "system/kvm.h"
|
||||||
|
|
||||||
|
void kvm_pic_realize(DeviceState *dev, Error **errp)
|
||||||
|
{
|
||||||
|
LoongarchPICState *lps = LOONGARCH_PIC(dev);
|
||||||
|
uint64_t pch_pic_base = VIRT_PCH_REG_BASE;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = kvm_create_device(kvm_state, KVM_DEV_TYPE_LOONGARCH_PCHPIC, false);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "Create KVM_LOONGARCH_PCHPIC failed: %s\n",
|
||||||
|
strerror(-ret));
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
lps->dev_fd = ret;
|
||||||
|
ret = kvm_device_access(lps->dev_fd, KVM_DEV_LOONGARCH_PCH_PIC_GRP_CTRL,
|
||||||
|
KVM_DEV_LOONGARCH_PCH_PIC_CTRL_INIT,
|
||||||
|
&pch_pic_base, true, NULL);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "KVM_LOONGARCH_PCH_PIC_INIT failed: %s\n",
|
||||||
|
strerror(-ret));
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,6 +74,8 @@ specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: files('loongarch_ipi.c'))
|
||||||
specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_LOONGARCH_IPI'],
|
specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_LOONGARCH_IPI'],
|
||||||
if_true: files('loongarch_ipi_kvm.c'))
|
if_true: files('loongarch_ipi_kvm.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_PIC', if_true: files('loongarch_pch_pic.c', 'loongarch_pic_common.c'))
|
||||||
|
specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_LOONGARCH_PCH_PIC'],
|
||||||
|
if_true: files('loongarch_pic_kvm.c'))
|
||||||
specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_MSI', if_true: files('loongarch_pch_msi.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_LOONGARCH_EXTIOI', if_true: files('loongarch_extioi.c', 'loongarch_extioi_common.c'))
|
||||||
specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_LOONGARCH_EXTIOI'],
|
specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_LOONGARCH_EXTIOI'],
|
||||||
|
|
|
@ -16,6 +16,7 @@ OBJECT_DECLARE_TYPE(LoongarchPICState, LoongarchPICClass, LOONGARCH_PIC)
|
||||||
|
|
||||||
struct LoongarchPICState {
|
struct LoongarchPICState {
|
||||||
LoongArchPICCommonState parent_obj;
|
LoongArchPICCommonState parent_obj;
|
||||||
|
int dev_fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LoongarchPICClass {
|
struct LoongarchPICClass {
|
||||||
|
@ -25,4 +26,6 @@ struct LoongarchPICClass {
|
||||||
ResettablePhases parent_phases;
|
ResettablePhases parent_phases;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void kvm_pic_realize(DeviceState *dev, Error **errp);
|
||||||
|
|
||||||
#endif /* HW_LOONGARCH_PCH_PIC_H */
|
#endif /* HW_LOONGARCH_PCH_PIC_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue