From patchwork Sat Sep 16 22:01:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 723631 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp1033088wro; Sat, 16 Sep 2023 15:03:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IED0hpY2ZPjpj3PJnCmF/r2wq1OpkLBQxTwkegjPIe1EwUTBaHXxJr8qETkaVd8w7lT2q75 X-Received: by 2002:a05:6870:d153:b0:1d5:3fd3:390a with SMTP id f19-20020a056870d15300b001d53fd3390amr6531436oac.49.1694901806708; Sat, 16 Sep 2023 15:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694901806; cv=none; d=google.com; s=arc-20160816; b=OVAWN6AbyGBIyj5D6eHjMqiGslSn4Mn1oTmIOWasSSOgc2MLoYIbbT5sWZV16SIS0c vgFreepZc3MA8vcsLurIK9NRDy+t6ewH2FyMidh77oidVQQvRIVEuGoPvKNNoHA0i7rQ 73sa1wXgXwJza+tBFTRskPxqAlSE8jHZrH+BiRwOH9nEtC6D7af8NPflRf002Xqa4ztt HPkJvXfqRXreyWON3kgR+OLjsUfZeyVrgnIsPNuf9HXos4Ih0VOQi2RbfKn9I2ZRjZa6 qKmR1GTId4trePTJCvoMZMRErHiJzQeNO1mx39SaGxmv/N5d8Y8v35eKzxDSWlW/eOQo LROg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qK9dl2HMki8c/cc1ceaRkDQQeJ1Zz081BcJFrsyjAmw=; fh=ll3XkfyLycYodSF2dSurSb0crBEObgQmKfp9udf3myk=; b=sj8i44zOYU4NrKjOMKO63puA5PGqwbrw+OcENAs/IbH/5wFz/lEHnA94MoLee1KibW pVBomqy3a2FW3geiyMBMZlUCuyYXSkQPlahY03r0lkuaTYjfrCu+w+aVfOvmoJuaepvb +gE2II2em/Rbilf2NQrk6j5k7I7LujXK+4utV/cI1Z2zyHsZDeuPKePEseMq6Q2iE5IX whkc0+RuFZWOdCOyqhnkhH0pJpBLd/sQh+lvdyvDmSsDPW32EULiRsTPAvC2WcxPejiO NfNox8YaVR9d1WGGFi70cruU4PDsLHnVrEzFGsQ8jGxWBJYPtf++yX4bHiVNQnPXF1pv j/Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="d/h9xQF5"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s12-20020a0cdc0c000000b0064c4bd3c6absi2269598qvk.360.2023.09.16.15.03.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 16 Sep 2023 15:03:26 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="d/h9xQF5"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhdMW-0006Hs-FJ; Sat, 16 Sep 2023 18:02:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qhdMU-0006Gm-QB for qemu-devel@nongnu.org; Sat, 16 Sep 2023 18:01:58 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qhdMT-00047I-4X for qemu-devel@nongnu.org; Sat, 16 Sep 2023 18:01:58 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1c3f97f2239so29854755ad.0 for ; Sat, 16 Sep 2023 15:01:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694901715; x=1695506515; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qK9dl2HMki8c/cc1ceaRkDQQeJ1Zz081BcJFrsyjAmw=; b=d/h9xQF5AR0NCZb6Kw5ekJZu7Nr0YkNg8lDdvOMMEhQlHp7O+x1V1XDyNOqJPwhBcB Fb9cEqR1Qsk6muS2+O5Hl9ZCR6OmmqsTU0l82gr386TOTVVpv9vL+sM0V18idtKt7b2V 1wMFQlhzz6adghWv0R4EudE1dVrkLEdj2aKan+wuIQ0KFDeGP7kO/jD0x8BsnW05IwQF 8hlnbm7JKUuL+VpsO+QiqhpiHSe+rP/iVxcycdD39rXX53Iy7i4N/5u5D8tKGPNEKeCm 4w8OE8XuG8T8pRq6myomwRO7apONAqILrlOR0GOFZiK53w8gMo4z0tEyXqueRD3l2fSD 4p3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694901715; x=1695506515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qK9dl2HMki8c/cc1ceaRkDQQeJ1Zz081BcJFrsyjAmw=; b=SStZfpv61854CtFXRTcGSVI2zckaBcoEbZ8G2PU8IlYxguBYcXLmStF+BfeMAjBGpK VFizvOsHZDO05ZBmh0qWDPEjbAYKjkx2Ud2B1hqbdWq83RpTSV/aN39Yl+wj9tXYUZXZ ulDzNwq0bB/9eVK5WwAKnOEsI6lSZcNrdMfLMrjvhUsBTi/8JmOeTaeys2jurHUw4heR tmOr+z6C9Hliu7o42V12OWuR/+gEfuZAHW6b3AgXO9Z+knsntpvurfqGDnZHkvyl9Ig7 1DapTeszkXioZFQDjvJLg7iU5Ypyt5mLdKI1Hpz4UteW7a+m/1VhvYue6woZQWncE0la AdbQ== X-Gm-Message-State: AOJu0YzH3JiH4Ktr4YW+e5Q0/to4M1jntpvqeN9KmuerQc9A7BJ1zOtS UUTpH6H8ySgkTgpmVZqrwUIKpIKBoBz4N/p13T8= X-Received: by 2002:a17:903:186:b0:1bd:aeb3:9504 with SMTP id z6-20020a170903018600b001bdaeb39504mr7095687plg.15.1694901715664; Sat, 16 Sep 2023 15:01:55 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id q3-20020a170902788300b001b531e8a000sm5707763pll.157.2023.09.16.15.01.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 15:01:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name, c@jia.je, gaosong@loongson.cn, yangxiaojuan@loongson.cn Subject: [PATCH 3/7] util: Add cpuinfo for loongarch64 Date: Sat, 16 Sep 2023 15:01:47 -0700 Message-Id: <20230916220151.526140-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230916220151.526140-1-richard.henderson@linaro.org> References: <20230916220151.526140-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson Reviewed-by: Jiajie Chen --- host/include/loongarch64/host/cpuinfo.h | 21 +++++++++++++++ util/cpuinfo-loongarch.c | 35 +++++++++++++++++++++++++ util/meson.build | 2 ++ 3 files changed, 58 insertions(+) create mode 100644 host/include/loongarch64/host/cpuinfo.h create mode 100644 util/cpuinfo-loongarch.c diff --git a/host/include/loongarch64/host/cpuinfo.h b/host/include/loongarch64/host/cpuinfo.h new file mode 100644 index 0000000000..fab664a10b --- /dev/null +++ b/host/include/loongarch64/host/cpuinfo.h @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * Host specific cpu identification for LoongArch + */ + +#ifndef HOST_CPUINFO_H +#define HOST_CPUINFO_H + +#define CPUINFO_ALWAYS (1u << 0) /* so cpuinfo is nonzero */ +#define CPUINFO_LSX (1u << 1) + +/* Initialized with a constructor. */ +extern unsigned cpuinfo; + +/* + * We cannot rely on constructor ordering, so other constructors must + * use the function interface rather than the variable above. + */ +unsigned cpuinfo_init(void); + +#endif /* HOST_CPUINFO_H */ diff --git a/util/cpuinfo-loongarch.c b/util/cpuinfo-loongarch.c new file mode 100644 index 0000000000..08b6d7460c --- /dev/null +++ b/util/cpuinfo-loongarch.c @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * Host specific cpu identification for LoongArch. + */ + +#include "qemu/osdep.h" +#include "host/cpuinfo.h" + +#ifdef CONFIG_GETAUXVAL +# include +#else +# include "elf.h" +#endif +#include + +unsigned cpuinfo; + +/* Called both as constructor and (possibly) via other constructors. */ +unsigned __attribute__((constructor)) cpuinfo_init(void) +{ + unsigned info = cpuinfo; + unsigned long hwcap; + + if (info) { + return info; + } + + hwcap = qemu_getauxval(AT_HWCAP); + + info = CPUINFO_ALWAYS; + info |= (hwcap & HWCAP_LOONGARCH_LSX ? CPUINFO_LSX : 0); + + cpuinfo = info; + return info; +} diff --git a/util/meson.build b/util/meson.build index c4827fd70a..b136f02aa0 100644 --- a/util/meson.build +++ b/util/meson.build @@ -112,6 +112,8 @@ if cpu == 'aarch64' util_ss.add(files('cpuinfo-aarch64.c')) elif cpu in ['x86', 'x86_64'] util_ss.add(files('cpuinfo-i386.c')) +elif cpu == 'loongarch64' + util_ss.add(files('cpuinfo-loongarch.c')) elif cpu in ['ppc', 'ppc64'] util_ss.add(files('cpuinfo-ppc.c')) endif