在 2025/7/15 上午9:02, Bibo Mao 写道:
emm, I had tested again , this may be a bug , here tcg_allowed is not set so the tcg_enabled() not work, the same with kvm_enabled()On 2025/7/11 下午4:59, Song Gao wrote:I think it will be better if tcg_enabled() is used here, since CONFIG_TCG and CONFIG_KVM is enabled by default. It should be supported in KVM mode now. It is suggested in V4 review process :)Avecintc feature is added in LoongArchVirtMachinState, and it is used to check whether virt machine supports the advanced interrupt controller and by default set avecintc with ON_OFF_AUTO_ON. LoongArchVirtMachineState adds misc_feature and misc_status for misc features and status. and set the default avec feature bit. Signed-off-by: Song Gao <gaos...@loongson.cn> --- hw/loongarch/virt.c | 30 ++++++++++++++++++++++++++++++ include/hw/loongarch/virt.h | 14 ++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index b15ada2078..112cf9a9db 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -47,6 +47,27 @@ #include "hw/virtio/virtio-iommu.h" #include "qemu/error-report.h"+static void virt_get_avecintc(Object *obj, Visitor *v, const char *name,+ void *opaque, Error **errp) +{ + LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(obj); + OnOffAuto avecintc = lvms->avecintc; + + visit_type_OnOffAuto(v, name, &avecintc, errp); + +}+static void virt_set_avecintc(Object *obj, Visitor *v, const char *name,+ void *opaque, Error **errp) +{ + LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(obj); + + visit_type_OnOffAuto(v, name, &lvms->avecintc, errp); + if (lvms->avecintc == ON_OFF_AUTO_OFF) { + lvms->misc_feature &= ~BIT(IOCSRF_AVEC); + lvms->misc_status &= ~BIT(IOCSRM_AVEC_EN); + } +} +static void virt_get_veiointc(Object *obj, Visitor *v, const char *name,void *opaque, Error **errp) { @@ -846,6 +867,9 @@ static void virt_initfn(Object *obj) if (tcg_enabled()) { lvms->veiointc = ON_OFF_AUTO_OFF; } + + lvms->misc_feature = BIT(IOCSRF_AVEC); + lvms->avecintc = ON_OFF_AUTO_ON; lvms->acpi = ON_OFF_AUTO_AUTO; lvms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6); lvms->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8);@@ -1238,6 +1262,12 @@ static void virt_class_init(ObjectClass *oc, const void *data)NULL, NULL); object_class_property_set_description(oc, "v-eiointc","Enable Virt Extend I/O Interrupt Controller.");+#ifdef CONFIG_TCG
Thanks., Song Gao
Regads Bibo Mao+ object_class_property_add(oc, "avecintc", "OnOffAuto", + virt_get_avecintc, virt_set_avecintc, NULL, NULL); + object_class_property_set_description(oc, "avecintc", + "Enable Advance Interrupt Controller."); +#endif machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); machine_class_allow_dynamic_sysbus_dev(mc, TYPE_UEFI_VARS_SYSBUS); #ifdef CONFIG_TPM diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h index 7120b46714..68b8e92e99 100644 --- a/include/hw/loongarch/virt.h +++ b/include/hw/loongarch/virt.h @@ -23,6 +23,7 @@ #define IOCSRF_DVFSV1 7 #define IOCSRF_GMOD 9 #define IOCSRF_VM 11 +#define IOCSRF_AVEC 15 #define VERSION_REG 0x0 #define FEATURE_REG 0x8 @@ -31,6 +32,7 @@ #define MISC_FUNC_REG 0x420 #define IOCSRM_EXTIOI_EN 48 #define IOCSRM_EXTIOI_INT_ENCODE 49 +#define IOCSRM_AVEC_EN 51 #define LOONGARCH_MAX_CPUS 256 @@ -69,6 +71,7 @@ struct LoongArchVirtMachineState { Notifier powerdown_notifier; OnOffAuto acpi; OnOffAuto veiointc; + OnOffAuto avecintc; char *oem_id; char *oem_table_id; DeviceState *acpi_ged; @@ -84,6 +87,8 @@ struct LoongArchVirtMachineState { DeviceState *extioi; struct memmap_entry *memmap_table; unsigned int memmap_entries; + uint64_t misc_feature; + uint64_t misc_status; }; #define TYPE_LOONGARCH_VIRT_MACHINE MACHINE_TYPE_NAME("virt")@@ -91,6 +96,15 @@ OBJECT_DECLARE_SIMPLE_TYPE(LoongArchVirtMachineState, LOONGARCH_VIRT_MACHINE)void virt_acpi_setup(LoongArchVirtMachineState *lvms); void virt_fdt_setup(LoongArchVirtMachineState *lvms); +static inline bool virt_has_avecintc(LoongArchVirtMachineState *lvms) +{ + if (!(lvms->misc_feature & BIT(IOCSRF_AVEC))) { + return false; + } + + return true; +} +static inline bool virt_is_veiointc_enabled(LoongArchVirtMachineState *lvms){ if (lvms->veiointc == ON_OFF_AUTO_OFF) {