From nobody Sun Nov 10 02:03:05 2024 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 1704857731669175.56332527701738; Tue, 9 Jan 2024 19:35:31 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2EC681B5F; Tue, 9 Jan 2024 22:35:30 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id EEBF61C5A; Tue, 9 Jan 2024 22:24:36 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 5BCA71BD6; Tue, 9 Jan 2024 22:24:17 -0500 (EST) 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 78A1B1BCF for ; Tue, 9 Jan 2024 22:22:14 -0500 (EST) Received: by mx1.osci.io (Postfix, from userid 994) id 4EF2D2210B; Tue, 9 Jan 2024 22:22:14 -0500 (EST) 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)) (No client certificate requested) by mx1.osci.io (Postfix) with ESMTPS id AA5EA220FC for ; Tue, 9 Jan 2024 22:22:13 -0500 (EST) Received: by mx3.osci.io (Postfix, from userid 990) id 3800230721D5; Tue, 9 Jan 2024 21:21:13 -0600 (CST) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx3.osci.io (Postfix) with ESMTP id 45A9130721D7 for ; Tue, 9 Jan 2024 21:21:07 -0600 (CST) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8CxrOggDZ5lILcDAA--.3246S3; Wed, 10 Jan 2024 11:21:04 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx+90YDZ5lPBoKAA--.27070S7; Wed, 10 Jan 2024 11:21:03 +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: [PATCH 1/4] Add loongarch cpu support Date: Wed, 10 Jan 2024 11:07:50 +0800 Message-Id: <20240110030812.878812-1-lixianglai@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bx+90YDZ5lPBoKAA--.27070S7 X-CM-SenderInfo: 5ol0xt5qjotxo6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Message-ID-Hash: 7FKXNPFV3SES2T7LGE23EAJI7SLZ2LL7 X-Message-ID-Hash: 7FKXNPFV3SES2T7LGE23EAJI7SLZ2LL7 X-MailFrom: SRS0=i89f=IU=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, xianglai li 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: 1704857733873100001 From: xianglai li Add loongarch cpu support, Define new cpu type 'loongarch64' and implement it's driver functions. Signed-off-by: "Xianglai Li" Signed-off-by: Xianglai Li --- src/cpu/cpu.c | 2 + src/cpu/cpu_loongarch.c | 80 ++++++++++++++++++++++++++++++++++++ src/cpu/cpu_loongarch.h | 25 +++++++++++ src/cpu/meson.build | 1 + src/qemu/qemu_capabilities.c | 2 + src/qemu/qemu_domain.c | 4 ++ src/util/virarch.c | 2 + src/util/virarch.h | 4 ++ 8 files changed, 120 insertions(+) create mode 100644 src/cpu/cpu_loongarch.c create mode 100644 src/cpu/cpu_loongarch.h diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index bc43aa4e93..1e7c879ca5 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -27,6 +27,7 @@ #include "cpu_ppc64.h" #include "cpu_s390.h" #include "cpu_arm.h" +#include "cpu_loongarch.h" #include "cpu_riscv64.h" #include "capabilities.h" =20 @@ -41,6 +42,7 @@ static struct cpuArchDriver *drivers[] =3D { &cpuDriverS390, &cpuDriverArm, &cpuDriverRiscv64, + &cpuDriverLoongArch, }; =20 =20 diff --git a/src/cpu/cpu_loongarch.c b/src/cpu/cpu_loongarch.c new file mode 100644 index 0000000000..48f9fef5ea --- /dev/null +++ b/src/cpu/cpu_loongarch.c @@ -0,0 +1,80 @@ +/* + * cpu_loongarch.c: CPU driver for 64-bit LOONGARCH CPUs + * + * Copyright (C) 2024 Loongson Technology. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "virlog.h" +#include "viralloc.h" +#include "cpu.h" +#include "virstring.h" +#include "cpu_map.h" +#include "virbuffer.h" + +#define VIR_FROM_THIS VIR_FROM_CPU + +VIR_LOG_INIT("cpu.cpu_loongarch"); + +static const virArch archs[] =3D { VIR_ARCH_LOONGARCH64 }; + +static virCPUCompareResult +virCPULoongArchCompare(virCPUDef *host G_GNUC_UNUSED, + virCPUDef *cpu G_GNUC_UNUSED, + bool failIncompatible G_GNUC_UNUSED) +{ + return VIR_CPU_COMPARE_IDENTICAL; +} + +static int +virCPULoongArchUpdate(virCPUDef *guest, + const virCPUDef *host ATTRIBUTE_UNUSED, + bool relative G_GNUC_UNUSED) +{ + /* + * - host-passthrough doesn't even get here + * - host-model is used for host CPU running in a compatibility mode a= nd + * it needs to remain unchanged + * - custom doesn't support any optional features, there's nothing to + * update + */ + + if (guest->mode =3D=3D VIR_CPU_MODE_CUSTOM) + guest->match =3D VIR_CPU_MATCH_EXACT; + + return 0; +} + +struct cpuArchDriver cpuDriverLoongArch =3D { + .name =3D "LoongArch", + .arch =3D archs, + .narch =3D G_N_ELEMENTS(archs), + .compare =3D virCPULoongArchCompare, + .decode =3D NULL, + .encode =3D NULL, + .dataFree =3D NULL, + .baseline =3D NULL, + .update =3D virCPULoongArchUpdate, + .getModels =3D NULL, +}; diff --git a/src/cpu/cpu_loongarch.h b/src/cpu/cpu_loongarch.h new file mode 100644 index 0000000000..4bc1c0cd8f --- /dev/null +++ b/src/cpu/cpu_loongarch.h @@ -0,0 +1,25 @@ +/* + * cpu_loongarch.h: CPU driver for 64-bit LOONGARCH CPUs + * + * Copyright (C) 2024 Loongson Technology. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "cpu.h" + +extern struct cpuArchDriver cpuDriverLoongArch; diff --git a/src/cpu/meson.build b/src/cpu/meson.build index 55396903b9..141230e380 100644 --- a/src/cpu/meson.build +++ b/src/cpu/meson.build @@ -1,6 +1,7 @@ cpu_sources =3D [ 'cpu.c', 'cpu_arm.c', + 'cpu_loongarch.c', 'cpu_map.c', 'cpu_ppc64.c', 'cpu_riscv64.c', diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 83119e871a..f2339d6013 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2665,6 +2665,8 @@ static const char *preferredMachines[] =3D NULL, /* VIR_ARCH_ITANIUM (doesn't exist in QEMU any more) */ "lm32-evr", /* VIR_ARCH_LM32 */ =20 + "virt", /* VIR_ARCH_LOONGARCH64 */ + "mcf5208evb", /* VIR_ARCH_M68K */ "petalogix-s3adsp1800", /* VIR_ARCH_MICROBLAZE */ "petalogix-s3adsp1800", /* VIR_ARCH_MICROBLAZEEL */ diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 896aa8394f..0cea0b323a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4222,6 +4222,10 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, addPCIRoot =3D true; break; =20 + case VIR_ARCH_LOONGARCH64: + addPCIeRoot =3D true; + break; + case VIR_ARCH_ARMV7B: case VIR_ARCH_CRIS: case VIR_ARCH_ITANIUM: diff --git a/src/util/virarch.c b/src/util/virarch.c index 01e520de73..74b7ec6f1b 100644 --- a/src/util/virarch.c +++ b/src/util/virarch.c @@ -51,6 +51,8 @@ static const struct virArchData { { "ia64", 64, VIR_ARCH_LITTLE_ENDIAN }, { "lm32", 32, VIR_ARCH_BIG_ENDIAN }, =20 + { "loongarch64", 64, VIR_ARCH_LITTLE_ENDIAN }, + { "m68k", 32, VIR_ARCH_BIG_ENDIAN }, { "microblaze", 32, VIR_ARCH_BIG_ENDIAN }, { "microblazeel", 32, VIR_ARCH_LITTLE_ENDIAN}, diff --git a/src/util/virarch.h b/src/util/virarch.h index 747f77c48e..c033e5c68d 100644 --- a/src/util/virarch.h +++ b/src/util/virarch.h @@ -36,6 +36,8 @@ typedef enum { VIR_ARCH_ITANIUM, /* Itanium 64 LE https://en.wikipedia.org/w= iki/Itanium */ VIR_ARCH_LM32, /* MilkyMist 32 BE https://en.wikipedia.org/w= iki/Milkymist */ =20 + VIR_ARCH_LOONGARCH64, /* LoongArch 64 LE */ + VIR_ARCH_M68K, /* m68k 32 BE https://en.wikipedia.org/w= iki/Motorola_68000_family */ VIR_ARCH_MICROBLAZE, /* Microblaze 32 BE https://en.wikipedia.org/w= iki/MicroBlaze */ VIR_ARCH_MICROBLAZEEL, /* Microblaze 32 LE https://en.wikipedia.org/w= iki/MicroBlaze */ @@ -106,6 +108,8 @@ typedef enum { #define ARCH_IS_SH4(arch) ((arch) =3D=3D VIR_ARCH_SH4 ||\ (arch) =3D=3D VIR_ARCH_SH4EB) =20 +#define ARCH_IS_LOONGARCH(arch) ((arch) =3D=3D VIR_ARCH_LOONGARCH64) + typedef enum { VIR_ARCH_LITTLE_ENDIAN, VIR_ARCH_BIG_ENDIAN, --=20 2.39.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org