From nobody Wed Jan 15 17:00:45 2025 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1710992002179458.3796687930959; Wed, 20 Mar 2024 20:33:22 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 044D51D7B; Wed, 20 Mar 2024 23:33:20 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 969401D38; Wed, 20 Mar 2024 23:32:22 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 8B0BA1D7B; Wed, 20 Mar 2024 23:32:14 -0400 (EDT) Received: from mx1.osci.io (polly.osci.io [8.43.85.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 82126212D for ; Wed, 20 Mar 2024 23:31:26 -0400 (EDT) Received: by mx1.osci.io (Postfix, from userid 994) id 33A6F22395; Wed, 20 Mar 2024 23:31:26 -0400 (EDT) Received: from mx3.osci.io (carla.osci.io [IPv6:2607:f0d0:1e02:35::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by mx1.osci.io (Postfix) with ESMTPS id 95889221F6 for ; Wed, 20 Mar 2024 23:31:22 -0400 (EDT) Received: by mx3.osci.io (Postfix, from userid 990) id 1BCAB30721DB; Wed, 20 Mar 2024 22:30:51 -0500 (CDT) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx3.osci.io (Postfix) with ESMTP id 14F6130721D8 for ; Wed, 20 Mar 2024 22:30:45 -0500 (CDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8BxefDeqftlwKcbAA--.1635S3; Thu, 21 Mar 2024 11:30:38 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxf8_VqftlE2JfAA--.54088S4; Thu, 21 Mar 2024 11:30:37 +0800 (CST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: Xianglai Li To: devel@lists.libvirt.org Subject: [libvirt PATCH V4 2/4] Support for loongarch64 in the QEMU driver Date: Thu, 21 Mar 2024 11:30:27 +0800 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cxf8_VqftlE2JfAA--.54088S4 X-CM-SenderInfo: 5ol0xt5qjotxo6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Message-ID-Hash: AQZDMMGKNSZIHU75JC5S34WS2ZYQN2T7 X-Message-ID-Hash: AQZDMMGKNSZIHU75JC5S34WS2ZYQN2T7 X-MailFrom: SRS0=o1cm=K3=loongson.cn=lixianglai@osci.io X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: maobibo@loongson.cn, lichao@loongson.cn, jiyin@redhat.com, lixianglai@loongson.cn X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1710992002587100001 Implement support for loongarch64 in the QEMU driver. Signed-off-by: Xianglai Li --- src/qemu/qemu_capabilities.c | 7 +++--- src/qemu/qemu_command.c | 6 +++-- src/qemu/qemu_domain.c | 43 ++++++++++++++++++++++++++++++++---- src/qemu/qemu_domain.h | 1 + src/qemu/qemu_validate.c | 1 + 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index fe008d170c..21f93c6774 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1146,7 +1146,8 @@ virQEMUCapsInitGuestFromBinary(virCaps *caps, NULL, NULL, 0, NULL); } =20 - if ((ARCH_IS_X86(guestarch) || guestarch =3D=3D VIR_ARCH_AARCH64)) + if (ARCH_IS_X86(guestarch) || guestarch =3D=3D VIR_ARCH_AARCH64 || + ARCH_IS_LOONGARCH(guestarch)) virCapabilitiesAddGuestFeatureWithToggle(guest, VIR_CAPS_GUEST_FEA= TURE_TYPE_ACPI, true, true); =20 @@ -2696,7 +2697,7 @@ static const char *preferredMachines[] =3D NULL, /* VIR_ARCH_ITANIUM (doesn't exist in QEMU any more) */ "lm32-evr", /* VIR_ARCH_LM32 */ =20 - NULL, /* VIR_ARCH_LOONGARCH64 */ + "virt", /* VIR_ARCH_LOONGARCH64 */ "mcf5208evb", /* VIR_ARCH_M68K */ "petalogix-s3adsp1800", /* VIR_ARCH_MICROBLAZE */ "petalogix-s3adsp1800", /* VIR_ARCH_MICROBLAZEEL */ @@ -3771,7 +3772,7 @@ virQEMUCapsInitCPUModel(virQEMUCaps *qemuCaps, } else if (ARCH_IS_X86(qemuCaps->arch)) { ret =3D virQEMUCapsInitCPUModelX86(qemuCaps, type, modelInfo, cpu, migratable); - } else if (ARCH_IS_ARM(qemuCaps->arch)) { + } else if (ARCH_IS_ARM(qemuCaps->arch) || ARCH_IS_LOONGARCH(qemuCaps->= arch)) { ret =3D 2; } =20 diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2bb1b6a0e7..0ca77bc9d7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9186,9 +9186,11 @@ qemuChrIsPlatformDevice(const virDomainDef *def, } } =20 - if (ARCH_IS_RISCV(def->os.arch)) { + if (ARCH_IS_RISCV(def->os.arch) || + ARCH_IS_LOONGARCH(def->os.arch)) { =20 - /* 16550a (used by riscv/virt guests) is a platform device */ + /* 16550a (used by the virt machine type on some architectures) + * is a platform device */ if (chr->deviceType =3D=3D VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL && chr->targetType =3D=3D VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTE= M && chr->targetModel =3D=3D VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_165= 50A) { diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 4e98b06529..6b869797a8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4117,7 +4117,7 @@ qemuDomainGetSCSIControllerModel(const virDomainDef *= def, =20 if (qemuDomainIsPSeries(def)) return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_IBMVSCSI; - if (ARCH_IS_S390(def->os.arch)) + if (ARCH_IS_S390(def->os.arch) || qemuDomainIsLoongArchVirt(def)) return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI; if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_LSI)) return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC; @@ -4263,10 +4263,13 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *drive= r, addPCIRoot =3D true; break; =20 + case VIR_ARCH_LOONGARCH64: + addPCIeRoot =3D true; + break; + case VIR_ARCH_CRIS: case VIR_ARCH_ITANIUM: case VIR_ARCH_LM32: - case VIR_ARCH_LOONGARCH64: case VIR_ARCH_M68K: case VIR_ARCH_MICROBLAZE: case VIR_ARCH_MICROBLAZEEL: @@ -5437,6 +5440,7 @@ qemuDomainDefaultNetModel(const virDomainDef *def, /* When there are no backwards compatibility concerns getting in * the way, virtio is a good default */ if (ARCH_IS_S390(def->os.arch) || + qemuDomainIsLoongArchVirt(def) || qemuDomainIsRISCVVirt(def)) { return VIR_DOMAIN_NET_MODEL_VIRTIO; } @@ -5680,6 +5684,9 @@ qemuDomainControllerDefPostParse(virDomainControllerD= ef *cont, cont->model =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_X= HCI; else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) cont->model =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XH= CI; + } else if (ARCH_IS_LOONGARCH(def->os.arch)) { + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XHCI)) + cont->model =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_X= HCI; } } /* forbid usb model 'qusb1' and 'qusb2' in this kind of hyperviosr= */ @@ -5779,7 +5786,9 @@ qemuDomainChrDefPostParse(virDomainChrDef *chr, chr->targetType =3D VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA; } else if (qemuDomainIsPSeries(def)) { chr->targetType =3D VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VI= O; - } else if (qemuDomainIsARMVirt(def) || qemuDomainIsRISCVVirt(def))= { + } else if (qemuDomainIsARMVirt(def) || + qemuDomainIsLoongArchVirt(def) || + qemuDomainIsRISCVVirt(def)) { chr->targetType =3D VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM; } else if (ARCH_IS_S390(def->os.arch)) { chr->targetType =3D VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SCLP; @@ -5805,7 +5814,8 @@ qemuDomainChrDefPostParse(virDomainChrDef *chr, case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM: if (qemuDomainIsARMVirt(def)) { chr->targetModel =3D VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL= 011; - } else if (qemuDomainIsRISCVVirt(def)) { + } else if (qemuDomainIsLoongArchVirt(def) || + qemuDomainIsRISCVVirt(def)) { chr->targetModel =3D VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_16= 550A; } break; @@ -5977,6 +5987,7 @@ qemuDomainDefaultVideoDevice(const virDomainDef *def, if (ARCH_IS_PPC64(def->os.arch)) return VIR_DOMAIN_VIDEO_TYPE_VGA; if (qemuDomainIsARMVirt(def) || + qemuDomainIsLoongArchVirt(def) || qemuDomainIsRISCVVirt(def) || ARCH_IS_S390(def->os.arch)) { return VIR_DOMAIN_VIDEO_TYPE_VIRTIO; @@ -9030,6 +9041,22 @@ qemuDomainMachineIsPSeries(const char *machine, } =20 =20 +static bool +qemuDomainMachineIsLoongArchVirt(const char *machine, + const virArch arch) +{ + if (!ARCH_IS_LOONGARCH(arch)) + return false; + + if (STREQ(machine, "virt") || + STRPREFIX(machine, "virt-")) { + return true; + } + + return false; +} + + static bool qemuDomainMachineIsMipsMalta(const char *machine, const virArch arch) @@ -9123,6 +9150,13 @@ qemuDomainIsMipsMalta(const virDomainDef *def) } =20 =20 +bool +qemuDomainIsLoongArchVirt(const virDomainDef *def) +{ + return qemuDomainMachineIsLoongArchVirt(def->os.machine, def->os.arch); +} + + bool qemuDomainHasPCIRoot(const virDomainDef *def) { @@ -9209,6 +9243,7 @@ qemuDomainSupportsPCIMultibus(const virDomainDef *def) /* In some cases, support for multibus is limited to some machine * types */ if (qemuDomainIsARMVirt(def) || + qemuDomainIsLoongArchVirt(def) || qemuDomainIsRISCVVirt(def)) { return true; } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 626df6338f..bd37cb245a 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -828,6 +828,7 @@ bool qemuDomainIsQ35(const virDomainDef *def); bool qemuDomainIsI440FX(const virDomainDef *def); bool qemuDomainIsS390CCW(const virDomainDef *def); bool qemuDomainIsARMVirt(const virDomainDef *def); +bool qemuDomainIsLoongArchVirt(const virDomainDef *def); bool qemuDomainIsRISCVVirt(const virDomainDef *def); bool qemuDomainIsPSeries(const virDomainDef *def); bool qemuDomainIsMipsMalta(const virDomainDef *def); diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 6a73d02050..b096312d1c 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2064,6 +2064,7 @@ qemuValidateDomainChrDef(const virDomainChrDef *dev, isCompatible =3D false; } if (dev->targetModel =3D=3D VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL= _16550A && + !qemuDomainIsLoongArchVirt(def) && !qemuDomainIsRISCVVirt(def)) { isCompatible =3D false; } --=20 2.39.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org