From patchwork Thu Sep 12 20:55:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 828064 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E940F1C242F; Thu, 12 Sep 2024 20:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174589; cv=none; b=DpVMpFd/2Sl0Qgh2AkPUPwav6twUuTostZSsLuWMkZMHolAZzBdler8O1mjEJQhsrd6XNdeh9Z53jKZ5CjFMYznCf8cO2LrDjK10Scy1M9zTIbQ6Cth3za6z4PYqXPnh3zUuIQTA8fv1Be8stw6fs24q2ygF80tj5P5BfCzKi9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174589; c=relaxed/simple; bh=7kW0y1NHB2fQVkpctuFfg0V/Ye36qaSzqoLCC/fpVB4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jZJvxz21LIUlFMDZiyaWkSO0I6fP1WnOJGAUXrpzFoIQG6JT4QjP5F5eDsukIweFAHNXH/lFmB3tPzjxZfaw0wDEeWqiKnlFpl42/F4VBo60MwcQwoYwnQiO1Vpr5/BsyEeKGr9RDC2IjaJqt1CMDcKISuKSHec32LCDWIFr1Xc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=fjynIgDq; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=R19YsL+N; arc=none smtp.client-ip=103.168.172.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="fjynIgDq"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="R19YsL+N" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id 27D0B13804B6; Thu, 12 Sep 2024 16:56:26 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 12 Sep 2024 16:56:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1726174586; x=1726260986; bh=DnUm5Y215poN8ylXsIUu+Ch7S5y7gO7zCsEWwSS402c=; b= fjynIgDqHTOAmbJRcWG7VL0BbSWUY8Ct5Ux0nAUyDPo+gO2udJkLt+BeqC0pomN2 bxgdTxCgL1eYcHj6XOGZDNac5aiZ9zy/1uyj6AM3umyb0G1rqmVgORE0GwsB25WU W02/nfYuXFpcO4ynmAGHT1bKaToOK+BEIQpAra+JdFmFZWFGQa3oKjhBXMCP2JxX V8sptCE5wNzMMFfEZOwozLpWpqUp7BudgYGRYMC1Eksdexsk/9tKA6xC/zMc9K6y w0Ja+XIIIQKLSQOQ8v1KVvHmo02nCPPyWB3BlUB29FlYOCR3HHTfoJjNETgFigiL WwPk51k+ZEy40852tgnNyQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1726174586; x= 1726260986; bh=DnUm5Y215poN8ylXsIUu+Ch7S5y7gO7zCsEWwSS402c=; b=R 19YsL+N23shVwA0ZPoFqId4MMahxRw6duMuO+YeT2pgHUYy9kfwfh9VEN6BCu0xt JeGViOqul/uRnK6kOpNGmZCiXb2ZSKTIrfQueHk94VeukcHoI+OE49+Te6NxB9oU dqcxn4lqjgwfby/ypNDBMqMgDyVVYtnnFdx7oNMsAH8bYCFHNO6ojGmER8ZErNpS BwG6b7FY2ya35a+PphOIviOnzTuvAX0NVqedBTUhulhCLemfZZtEIRlBaNeFGAcF lbwzQNyfYV3QGv8tPVcHfjaFucqadAHA99+iuvPH59FrFPUtXY+7KOC6YpdNNmsG bzmZ5EseiCrulP/+Sd3Vg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedgudehjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheplfhirgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflh ihghhorghtrdgtohhmqeenucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleff keegudeghfdtuddugefhueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorght rdgtohhmpdhnsggprhgtphhtthhopeduvddpmhhouggvpehsmhhtphhouhhtpdhrtghpth htoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepthhglhigsehlihhnuhhtrhhonhhigidruggvpdhrtghpthhtoheplhhoohhngh grrhgthheslhhishhtshdrlhhinhhugidruggvvhdprhgtphhtthhopehlihhnuhigqdhp mhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehkvhhmsehvghgvrhdrkh gvrhhnvghlrdhorhhgpdhrtghpthhtohepthhssghoghgvnhgusegrlhhphhgrrdhfrhgr nhhkvghnrdguvgdprhgtphhtthhopehjihgrgihunhdrhigrnhhgsehflhihghhorghtrd gtohhmpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthho pegthhgvnhhhuhgrtggriheskhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 16:56:24 -0400 (EDT) From: Jiaxun Yang Date: Thu, 12 Sep 2024 21:55:55 +0100 Subject: [PATCH v2 2/4] LoongArch: cpu-probe: Move IOCSR probing out of cpu_probe_common Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240912-iocsr-v2-2-e88f75b37da4@flygoat.com> References: <20240912-iocsr-v2-0-e88f75b37da4@flygoat.com> In-Reply-To: <20240912-iocsr-v2-0-e88f75b37da4@flygoat.com> To: Huacai Chen , WANG Xuerui , "Rafael J. Wysocki" , Viresh Kumar , Thomas Gleixner , Thomas Bogendoerfer Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-mips@vger.kernel.org, kvm@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3242; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=7kW0y1NHB2fQVkpctuFfg0V/Ye36qaSzqoLCC/fpVB4=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrTHocU3ejmOtMsxTnnyNtZr+vuZNk8z1zbzTvwewVtY7 irbzrWso5SFQYyLQVZMkSVEQKlvQ+PFBdcfZP2BmcPKBDKEgYtTACbilMXI8MTB6JWZlsr+hhca ZjfPGnzivZKqu2LC6emXG3YWqBo7TmNkmL2vM5FppiPzzA27/EVcHpfmXdjDmfi9IORY2Jdlu87 KcwAA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 IOCSR register definition appears to be a platform specific spec instead of architecture spec, even for Loongson CPUs there is no guarantee that IOCSR will always present. Thus it's dangerous to perform IOCSR probing without checking CPU type and instruction availability. Signed-off-by: Jiaxun Yang --- arch/loongarch/kernel/cpu-probe.c | 50 +++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/arch/loongarch/kernel/cpu-probe.c b/arch/loongarch/kernel/cpu-probe.c index 5dc8ca3c4387..d1a9bb77145f 100644 --- a/arch/loongarch/kernel/cpu-probe.c +++ b/arch/loongarch/kernel/cpu-probe.c @@ -182,22 +182,6 @@ static void cpu_probe_common(struct cpuinfo_loongarch *c) if (config & CPUCFG6_PMP) c->options |= LOONGARCH_CPU_PMP; - config = iocsr_read32(LOONGARCH_IOCSR_FEATURES); - if (config & IOCSRF_CSRIPI) - c->options |= LOONGARCH_CPU_CSRIPI; - if (config & IOCSRF_EXTIOI) - c->options |= LOONGARCH_CPU_EXTIOI; - if (config & IOCSRF_FREQSCALE) - c->options |= LOONGARCH_CPU_SCALEFREQ; - if (config & IOCSRF_FLATMODE) - c->options |= LOONGARCH_CPU_FLATMODE; - if (config & IOCSRF_EIODECODE) - c->options |= LOONGARCH_CPU_EIODECODE; - if (config & IOCSRF_AVEC) - c->options |= LOONGARCH_CPU_AVECINT; - if (config & IOCSRF_VM) - c->options |= LOONGARCH_CPU_HYPERVISOR; - config = csr_read32(LOONGARCH_CSR_ASID); config = (config & CSR_ASID_BIT) >> CSR_ASID_BIT_SHIFT; asid_mask = GENMASK(config - 1, 0); @@ -240,15 +224,10 @@ static char cpu_full_name[MAX_NAME_LEN] = " - "; static inline void cpu_probe_loongson(struct cpuinfo_loongarch *c, unsigned int cpu) { + uint32_t config; + const char *core_name = "Unknown"; uint64_t *vendor = (void *)(&cpu_full_name[VENDOR_OFFSET]); uint64_t *cpuname = (void *)(&cpu_full_name[CPUNAME_OFFSET]); - const char *core_name = "Unknown"; - - if (!__cpu_full_name[cpu]) - __cpu_full_name[cpu] = cpu_full_name; - - *vendor = iocsr_read64(LOONGARCH_IOCSR_VENDOR); - *cpuname = iocsr_read64(LOONGARCH_IOCSR_CPUNAME); switch (c->processor_id & PRID_SERIES_MASK) { case PRID_SERIES_LA132: @@ -290,6 +269,31 @@ static inline void cpu_probe_loongson(struct cpuinfo_loongarch *c, unsigned int } pr_info("%s Processor probed (%s Core)\n", __cpu_family[cpu], core_name); + + if (c->options & LOONGARCH_CPU_IOCSR) + return; + + *vendor = iocsr_read64(LOONGARCH_IOCSR_VENDOR); + *cpuname = iocsr_read64(LOONGARCH_IOCSR_CPUNAME); + + if (!__cpu_full_name[cpu]) + __cpu_full_name[cpu] = cpu_full_name; + + config = iocsr_read32(LOONGARCH_IOCSR_FEATURES); + if (config & IOCSRF_CSRIPI) + c->options |= LOONGARCH_CPU_CSRIPI; + if (config & IOCSRF_EXTIOI) + c->options |= LOONGARCH_CPU_EXTIOI; + if (config & IOCSRF_FREQSCALE) + c->options |= LOONGARCH_CPU_SCALEFREQ; + if (config & IOCSRF_FLATMODE) + c->options |= LOONGARCH_CPU_FLATMODE; + if (config & IOCSRF_EIODECODE) + c->options |= LOONGARCH_CPU_EIODECODE; + if (config & IOCSRF_AVEC) + c->options |= LOONGARCH_CPU_AVECINT; + if (config & IOCSRF_VM) + c->options |= LOONGARCH_CPU_HYPERVISOR; } #ifdef CONFIG_64BIT