From: Helge Deller <deller@kernel.org>
To: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@gmail.com>
Cc: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,
Laurent Vivier <laurent@vivier.eu>,
deller@gmx.de, Song Gao <gaosong@loongson.cn>,
Bibo Mao <maobibo@loongson.cn>,
Jiaxun Yang <jiaxun.yang@flygoat.com>
Subject: [PULL 2/4] linux-user: Implement /proc/cpuinfo for loongarch cpus
Date: Thu, 18 Jun 2026 23:54:09 +0200 [thread overview]
Message-ID: <20260618215411.22057-3-deller@kernel.org> (raw)
In-Reply-To: <20260618215411.22057-1-deller@kernel.org>
From: Helge Deller <deller@gmx.de>
Mimic the entries for /proc/cpuinfo to what can be seen on the debian
porterbox loomis.debian.org.
Cc: Song Gao <gaosong@loongson.cn>
Cc: Bibo Mao <maobibo@loongson.cn>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Helge Deller <deller@gmx.de>
---
linux-user/loongarch64/elfload.c | 20 +++++++
linux-user/loongarch64/target_proc.h | 79 +++++++++++++++++++++++++++-
2 files changed, 98 insertions(+), 1 deletion(-)
diff --git a/linux-user/loongarch64/elfload.c b/linux-user/loongarch64/elfload.c
index e53957e36d..2242f20202 100644
--- a/linux-user/loongarch64/elfload.c
+++ b/linux-user/loongarch64/elfload.c
@@ -28,6 +28,26 @@ enum {
HWCAP_LOONGARCH_LBT_MIPS = (1 << 12),
};
+const char *elf_hwcap_str(uint32_t bit)
+{
+ static const char *hwcap_str[] = {
+ [__builtin_ctz(HWCAP_LOONGARCH_CPUCFG )] = "cpucfg",
+ [__builtin_ctz(HWCAP_LOONGARCH_LAM )] = "lam",
+ [__builtin_ctz(HWCAP_LOONGARCH_UAL )] = "lam_bh",
+ [__builtin_ctz(HWCAP_LOONGARCH_FPU )] = "fpu",
+ [__builtin_ctz(HWCAP_LOONGARCH_LSX )] = "lsx",
+ [__builtin_ctz(HWCAP_LOONGARCH_LASX )] = "lasx",
+ [__builtin_ctz(HWCAP_LOONGARCH_CRC32 )] = "crc32",
+ [__builtin_ctz(HWCAP_LOONGARCH_COMPLEX )] = "complex",
+ [__builtin_ctz(HWCAP_LOONGARCH_CRYPTO )] = "crypto",
+ [__builtin_ctz(HWCAP_LOONGARCH_LVZ )] = "lvz",
+ [__builtin_ctz(HWCAP_LOONGARCH_LBT_X86 )] = "lbt_x86",
+ [__builtin_ctz(HWCAP_LOONGARCH_LBT_ARM )] = "lbt_arm",
+ [__builtin_ctz(HWCAP_LOONGARCH_LBT_MIPS)] = "lbt_mips",
+ };
+
+ return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
+}
abi_ulong get_elf_hwcap(CPUState *cs)
{
LoongArchCPU *cpu = LOONGARCH_CPU(cs);
diff --git a/linux-user/loongarch64/target_proc.h b/linux-user/loongarch64/target_proc.h
index 43fe29ca72..f739520fab 100644
--- a/linux-user/loongarch64/target_proc.h
+++ b/linux-user/loongarch64/target_proc.h
@@ -1 +1,78 @@
-/* No target-specific /proc support */
+/*
+ * Loongson specific proc functions for linux-user
+ *
+ * Copyright (c) 2026 Helge Deller
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef LOONGARCH_TARGET_PROC_H
+#define LOONGARCH_TARGET_PROC_H
+
+static int open_cpuinfo(CPUArchState *cpu_env, int fd)
+{
+ uint32_t elf_hwcap = get_elf_hwcap(env_cpu(cpu_env));
+ uint32_t prid, ser_id, pabits, vabits, i, n, num_cpus;
+ bool is_64bit = is_la64(cpu_env);
+ const char *hwcap_str;
+ struct timespec res;
+ double freq_mhz;
+
+#if TARGET_LONG_BITS == 32
+ pabits = 31;
+ vabits = 31;
+#else
+ pabits = FIELD_EX32(cpu_env->cpucfg[1], CPUCFG1, PALEN);
+ vabits = FIELD_EX32(cpu_env->cpucfg[1], CPUCFG1, VALEN);
+#endif
+
+ if (clock_getres(CLOCK_REALTIME, &res) == -1) {
+ res.tv_nsec = 1;
+ }
+ freq_mhz = 1000.0 / res.tv_nsec;
+
+ ser_id = FIELD_EX32(cpu_env->cpucfg[0], CPUCFG0, SERID);
+ prid = FIELD_EX32(cpu_env->cpucfg[0], CPUCFG0, PRID);
+
+ dprintf(fd, "system type\t\t: generic-loongson-machine\n");
+
+ num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+ for (n = 0; n < num_cpus; n++) {
+ dprintf(fd, "\nprocessor\t\t: %d\n", n);
+ dprintf(fd, "package\t\t\t: 0\n");
+ dprintf(fd, "core\t\t\t: %d\n", n);
+ dprintf(fd, "global_id\t\t: %d\n", n);
+ dprintf(fd, "CPU Family\t\t: Loongson-%dbit\n", is_64bit ? 64 : 32);
+ dprintf(fd, "Model Name\t\t: QEMU_user-v" QEMU_VERSION "\n");
+ dprintf(fd, "PRID\t\t\t: %s (%08x)\n",
+ ser_id == PRID_SERIES_LA464 ? "LA464" :
+ ser_id == PRID_SERIES_LA132 ? "LA132" : "Unknown",
+ cpu_env->cpucfg[0]);
+ dprintf(fd, "CPU Revision\t\t: 0x%02x\n", prid);
+ dprintf(fd, "FPU Revision\t\t: 0x%02x\n",
+ FIELD_EX32(cpu_env->cpucfg[2], CPUCFG2, FP_VER));
+ dprintf(fd, "CPU MHz\t\t\t: %.2f\n", freq_mhz);
+ dprintf(fd, "Address Sizes\t\t: %d bits physical, %d bits virtual\n",
+ pabits + 1, vabits + 1);
+
+ dprintf(fd, "ISA\t\t\t:%s", " loongarch32r loongarch32s");
+ if (is_64bit) {
+ dprintf(fd, " loongarch64");
+ }
+
+ dprintf(fd, "\nFeatures\t\t:");
+ for (i = 0; i < sizeof(elf_hwcap) * 8; i++) {
+ if (!(elf_hwcap & (1 << i))) {
+ continue;
+ }
+ hwcap_str = elf_hwcap_str(i);
+ if (hwcap_str) {
+ dprintf(fd, " %s", hwcap_str);
+ }
+ }
+ dprintf(fd, "\nHardware Watchpoint\t: no\n");
+ }
+ return 0;
+}
+#define HAVE_ARCH_PROC_CPUINFO
+
+#endif /* LOONGARCH_TARGET_PROC_H */
--
2.54.0
next prev parent reply other threads:[~2026-06-18 21:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 21:54 [PULL 0/4] Linux user patches Helge Deller
2026-06-18 21:54 ` [PULL 1/4] linux-user: Fix AT_PHDR when program headers are relocated into their own segment Helge Deller
2026-06-18 21:54 ` Helge Deller [this message]
2026-06-18 21:54 ` [PULL 3/4] linux-user: Implement /proc/cpuinfo for m68k CPU Helge Deller
2026-06-18 21:54 ` [PULL 4/4] linux-user/xtensa: fix unlock of uninitialized frame pointer on sigreturn Helge Deller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260618215411.22057-3-deller@kernel.org \
--to=deller@kernel.org \
--cc=deller@gmx.de \
--cc=gaosong@loongson.cn \
--cc=jiaxun.yang@flygoat.com \
--cc=laurent@vivier.eu \
--cc=maobibo@loongson.cn \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.