From patchwork Sat Sep 7 10:17:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 826532 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 1545F2B9B1; Sat, 7 Sep 2024 10:17:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725704232; cv=none; b=LgEVUaJ+va+TgUWC7M36V93MvPhj/UQNczWW098coT/ltaMM9+LdLdbeBTpVjiQ2GeJbn1sDQhe3lsl2rC35ftlM0+zdijr8DMZOkjejUlJPXmj0iCY1V+S1372e9yQ+mPU0rvaFqWhB52XnNoRiAf746bGSiq+I8ibGS9UQA5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725704232; c=relaxed/simple; bh=wNTWbaQ3JwwfsBAMFy/hbQ4QwVJklrQxDjLfp0v17+I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pQJMUEQDXjAXrfo17cyCRrk5YvW4TdP8D+T9yle4psgrUMOxa3rIWAiKA3RAl9wR3D1p/5ILjXIbdoxj6zgP5enVhJsLtmHSF2pbVLmLio6GFJc0FiVJP/OnutGNhe7M3snKLpgKJ7Edtx6R90mefyP11tDac0aNYbVtCzhdw9g= 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=wakxfG+K; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BEPvx2xU; arc=none smtp.client-ip=103.168.172.150 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="wakxfG+K"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BEPvx2xU" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 3AFEC1380232; Sat, 7 Sep 2024 06:17:10 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Sat, 07 Sep 2024 06:17:10 -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=1725704230; x=1725790630; bh=zpvJucUqs7I/38ybPNaItJ/O65uxnCT7g9kZGtXgeRE=; b= wakxfG+KM1Jh+ZBGYBmgyVxtOem0RBnis1HbyaxckmKH2kJzVcOszWSiL6Sz6KAP SuGLQcBSz4ugs4cUmu/TJcGWHddXS6fYzWF+vXhA25o+YKjYQW3osZTbtHQY0aEZ SwZeayWyetFhdHT71+hg55F5BLhp5ijZPKF6Pz2Ca6MwANjLpBJTbS9gq7Ej34YM w8X1/m+5aEj2tI5uHwkAtL8tBnLDpL9P2fRm397TCbFemBrj5APKog6ZigFdzavc zq6OeGR48Sh80BFhBqmMeZ5ea11w8UsjZM5sljpB8koDjmNTuP5vzQ1AiEnKBizb jlDb57QcFi8onwUHo+MnpQ== 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=1725704230; x= 1725790630; bh=zpvJucUqs7I/38ybPNaItJ/O65uxnCT7g9kZGtXgeRE=; b=B EPvx2xUNjdZNbQepcyCa2IgFNnUIU/eMHC6DA+7NbnfARYn2tQNp9iiKMtRP4V3o g9TWYHRcS6OGOX3ryIV4qc9oIfJqVEmV+A1D7h3E2J1x3F4k1KPRTWkv4LrHNz+i 1Yp+4pQRl0yxXKgY+bz8Z+m+7vuTTTrvyxyzLu2BlfUA7EPbZtIeWmg8DkghnIY4 xbu2pXpsAdUQcOpbvWC69882cNXFqwbEB7XbaEE/d2W/ybO7GRLfS4XhfLNVr6HM pckOomUNWxhbbaEjwsiQ1gF/GW5yDQ+AfP3T/mld1pxi7eXt2DTU2GGxzQq1D2OM acqpuYNYVtzrf26BLUPCA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeifedgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdej necuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhi hgohgrthdrtghomheqnecuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffek gedugefhtdduudeghfeuveegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdr tghomhdpnhgspghrtghpthhtohepuddvpdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehkvhhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhglhigsehl ihhnuhhtrhhonhhigidruggvpdhrtghpthhtoheptghhvghnhhhurggtrghisehkvghrnh gvlhdrohhrghdprhgtphhtthhopehvihhrvghshhdrkhhumhgrrheslhhinhgrrhhordho rhhgpdhrtghpthhtoheplhhoohhnghgrrhgthheslhhishhtshdrlhhinhhugidruggvvh dprhgtphhtthhopehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmpdhrtghp thhtohepthhssghoghgvnhgusegrlhhphhgrrdhfrhgrnhhkvghnrdguvgdprhgtphhtth hopehkvghrnhgvlhesgigvnhdtnhdrnhgrmhgvpdhrtghpthhtoheplhhinhhugidqmhhi phhssehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Sep 2024 06:17:08 -0400 (EDT) From: Jiaxun Yang Date: Sat, 07 Sep 2024 11:17:03 +0100 Subject: [PATCH 1/5] LoongArch: Rename cpu_has_csr as cpu_has_iocsr Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240907-iocsr-v1-1-0c99b3334444@flygoat.com> References: <20240907-iocsr-v1-0-0c99b3334444@flygoat.com> In-Reply-To: <20240907-iocsr-v1-0-0c99b3334444@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=2334; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=wNTWbaQ3JwwfsBAMFy/hbQ4QwVJklrQxDjLfp0v17+I=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrQ7GkpTdvr/Phjcp7IvsXXKlsMMZ6+01e5Oqwmp+3825 Mwr9TNTOkpZGMS4GGTFFFlCBJT6NjReXHD9QdYfmDmsTCBDGLg4BWAiEj0M/531r/zcvdvmwtOn V+6+WhZ9qrg1Zs7eB7dW2Dzad2Pi98q7DP+zUivDDv8R1Y9lu3ItrU3pi9Y3znUcW+6XxpQtk73 4rZgHAA== X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 It meant to be IOCSR as CSR is not optional for LoongArch. Signed-off-by: Jiaxun Yang --- arch/loongarch/include/asm/cpu-features.h | 2 +- arch/loongarch/include/asm/cpu.h | 2 +- arch/loongarch/kernel/cpu-probe.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/loongarch/include/asm/cpu-features.h b/arch/loongarch/include/asm/cpu-features.h index 16a716f88a5c..0190ed28a647 100644 --- a/arch/loongarch/include/asm/cpu-features.h +++ b/arch/loongarch/include/asm/cpu-features.h @@ -50,7 +50,7 @@ #define cpu_has_lbt_arm cpu_opt(LOONGARCH_CPU_LBT_ARM) #define cpu_has_lbt_mips cpu_opt(LOONGARCH_CPU_LBT_MIPS) #define cpu_has_lbt (cpu_has_lbt_x86|cpu_has_lbt_arm|cpu_has_lbt_mips) -#define cpu_has_csr cpu_opt(LOONGARCH_CPU_CSR) +#define cpu_has_iocsr cpu_opt(LOONGARCH_CPU_IOCSR) #define cpu_has_tlb cpu_opt(LOONGARCH_CPU_TLB) #define cpu_has_watch cpu_opt(LOONGARCH_CPU_WATCH) #define cpu_has_vint cpu_opt(LOONGARCH_CPU_VINT) diff --git a/arch/loongarch/include/asm/cpu.h b/arch/loongarch/include/asm/cpu.h index 843f9c4ec980..7c44f4ede3a2 100644 --- a/arch/loongarch/include/asm/cpu.h +++ b/arch/loongarch/include/asm/cpu.h @@ -115,7 +115,7 @@ enum cpu_type_enum { #define LOONGARCH_CPU_LBT_ARM BIT_ULL(CPU_FEATURE_LBT_ARM) #define LOONGARCH_CPU_LBT_MIPS BIT_ULL(CPU_FEATURE_LBT_MIPS) #define LOONGARCH_CPU_TLB BIT_ULL(CPU_FEATURE_TLB) -#define LOONGARCH_CPU_CSR BIT_ULL(CPU_FEATURE_CSR) +#define LOONGARCH_CPU_IOCSR BIT_ULL(CPU_FEATURE_IOCSR) #define LOONGARCH_CPU_WATCH BIT_ULL(CPU_FEATURE_WATCH) #define LOONGARCH_CPU_VINT BIT_ULL(CPU_FEATURE_VINT) #define LOONGARCH_CPU_CSRIPI BIT_ULL(CPU_FEATURE_CSRIPI) diff --git a/arch/loongarch/kernel/cpu-probe.c b/arch/loongarch/kernel/cpu-probe.c index 14f0449f5452..4446616d497c 100644 --- a/arch/loongarch/kernel/cpu-probe.c +++ b/arch/loongarch/kernel/cpu-probe.c @@ -91,7 +91,7 @@ static void cpu_probe_common(struct cpuinfo_loongarch *c) unsigned int config; unsigned long asid_mask; - c->options = LOONGARCH_CPU_CPUCFG | LOONGARCH_CPU_CSR | + c->options = LOONGARCH_CPU_CPUCFG | LOONGARCH_CPU_IOCSR | LOONGARCH_CPU_TLB | LOONGARCH_CPU_VINT | LOONGARCH_CPU_WATCH; elf_hwcap = HWCAP_LOONGARCH_CPUCFG; From patchwork Sat Sep 7 10:17:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 826394 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 A93D415855B; Sat, 7 Sep 2024 10:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725704235; cv=none; b=QqLlOFx0u94qCIcti6HJ6ZLFn93ZmdyzCpwUccgHFRbR2fT/ON7muHa8BLAm5JfcTJPhbqboRilk8fOOnfKFWd/Aq24fax1XUGZRFbFSUNKYe/QMivMyrVoKXXXPRVrVb8C+KW6/NpfdbzTO9YcX6seEVMMZYdnmcSlFDxjMlb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725704235; c=relaxed/simple; bh=dGuxM8PZ+MkpKKAh5LWup1ti6kx4IwMUcMWFV7XToMY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZyyblTz6dQ36rH9uEA1g6pv9M1Aie3qBN5AcJtiJDAZOqSdNQ2Vrcwgqo5uKla3iBTTZeUOdrgM327/JftQzjCfELqmsoZvU3Y8EWy2Npk+NiFfJA03bhExnlytTUUcNm9Pxu1r/JO4iIf8QNg5IeAKXMH/Z2ll45YXu0PkUcIQ= 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=ESj2jLG/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=I4y2+nOL; arc=none smtp.client-ip=103.168.172.150 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="ESj2jLG/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="I4y2+nOL" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id EA3C61380313; Sat, 7 Sep 2024 06:17:11 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Sat, 07 Sep 2024 06:17:11 -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=1725704231; x=1725790631; bh=g18dTpnsZcS8drCZ6SuD1OxTNXBCkwaw+UxY/uw2PNw=; b= ESj2jLG/GfIvEZs1djVI9ihIWMmB8e4PI4Fe2UOfbSWwSAc/QDfK5O/SJ9CiOpJf hUTEo/PH4T6NK/vBNaaUHbIVl6jadmUcLLZv2TT4VlGDUojviGtuQ6jrvs9Pz5Dm 1KkRS+tCmpKIwyE1BqcCTb0AVbgq/gupxPMgQYB1a+MEwkOaPj5ifidO4mBNGQD8 9epHBKjavp3CWcFNoIFjODPHPLPlbKrPXggXt5uQmMLyq7cqMj7QfXcczI5wv6yP vg4hZnWXZVSSSc6+hryo7kt0NVYal4cpdFn6Mvrb+kgcCE/bLJCXcEHq8KLRxCB3 8f1TskXRrtzjkwrzZ1fxMA== 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=1725704231; x= 1725790631; bh=g18dTpnsZcS8drCZ6SuD1OxTNXBCkwaw+UxY/uw2PNw=; b=I 4y2+nOLZ0kIy4Y4nos+zZ1NS5wM9t3J+dfQOsfSHiUky61nL4wGSLdlT2F3V90kT hjc2FIc0PI1reJoVr1WAjQ1j6WlU88Lyu0+IIemBKKmqq9MEQQFzmWdRcMztGYqm EcxhMOj10UeK7k2lAi5Wv87tgO4fIZEqpGvEL1FkXxBumbvg63izNFqvQe/27vXV Kj5GQ3J9tLMFB8LkL7OZZZmFGd4R9okhe9I8k8EdTa37JAsW7WZyfBJHSd1z+RtQ YP9yhzsVXppCOHzMr4vfbIO1aRdQgvY386ojnMIpft8Gn3Wj5bXdD2cKQ97fIU8p he5kVqS/2iwBLFqUn4wcw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeifedgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdej necuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhi hgohgrthdrtghomheqnecuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffek gedugefhtdduudeghfeuveegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdr tghomhdpnhgspghrtghpthhtohepuddvpdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehkvhhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhglhigsehl ihhnuhhtrhhonhhigidruggvpdhrtghpthhtoheptghhvghnhhhurggtrghisehkvghrnh gvlhdrohhrghdprhgtphhtthhopehvihhrvghshhdrkhhumhgrrheslhhinhgrrhhordho rhhgpdhrtghpthhtoheplhhoohhnghgrrhgthheslhhishhtshdrlhhinhhugidruggvvh dprhgtphhtthhopehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmpdhrtghp thhtohepthhssghoghgvnhgusegrlhhphhgrrdhfrhgrnhhkvghnrdguvgdprhgtphhtth hopehkvghrnhgvlhesgigvnhdtnhdrnhgrmhgvpdhrtghpthhtoheplhhinhhugidqmhhi phhssehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Sep 2024 06:17:10 -0400 (EDT) From: Jiaxun Yang Date: Sat, 07 Sep 2024 11:17:04 +0100 Subject: [PATCH 2/5] LoongArch: Probe more CPU features from CPUCFG Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240907-iocsr-v1-2-0c99b3334444@flygoat.com> References: <20240907-iocsr-v1-0-0c99b3334444@flygoat.com> In-Reply-To: <20240907-iocsr-v1-0-0c99b3334444@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=4645; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=dGuxM8PZ+MkpKKAh5LWup1ti6kx4IwMUcMWFV7XToMY=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrQ7GkqmCz2jHJz9OBTndJn0lvxZ5drxo7fJYdUs8W929 gKTfj7qKGVhEONikBVTZAkRUOrb0HhxwfUHWX9g5rAygQxh4OIUgImwMTL8zz+yQW3asld6b7kP 1H+ZvC7+xsRnc27vap+8aOGsP3PnBD9jZHg/0SmIadtObqZ/s5LktK5ea+eWONr5ksGXxeG4os/ 8LawA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Probe ISA level, TLB, IOCSR information from CPUCFG to improve kernel resilience to different core implementations. Signed-off-by: Jiaxun Yang --- arch/loongarch/include/asm/cpu.h | 2 +- arch/loongarch/kernel/cpu-probe.c | 47 ++++++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/arch/loongarch/include/asm/cpu.h b/arch/loongarch/include/asm/cpu.h index 7c44f4ede3a2..31a2de821236 100644 --- a/arch/loongarch/include/asm/cpu.h +++ b/arch/loongarch/include/asm/cpu.h @@ -86,7 +86,7 @@ enum cpu_type_enum { #define CPU_FEATURE_LBT_ARM 11 /* CPU has ARM Binary Translation */ #define CPU_FEATURE_LBT_MIPS 12 /* CPU has MIPS Binary Translation */ #define CPU_FEATURE_TLB 13 /* CPU has TLB */ -#define CPU_FEATURE_CSR 14 /* CPU has CSR */ +#define CPU_FEATURE_IOCSR 14 /* CPU has IOCSR */ #define CPU_FEATURE_WATCH 15 /* CPU has watchpoint registers */ #define CPU_FEATURE_VINT 16 /* CPU has vectored interrupts */ #define CPU_FEATURE_CSRIPI 17 /* CPU has CSR-IPI */ diff --git a/arch/loongarch/kernel/cpu-probe.c b/arch/loongarch/kernel/cpu-probe.c index 4446616d497c..6a82ceb6e321 100644 --- a/arch/loongarch/kernel/cpu-probe.c +++ b/arch/loongarch/kernel/cpu-probe.c @@ -91,12 +91,23 @@ static void cpu_probe_common(struct cpuinfo_loongarch *c) unsigned int config; unsigned long asid_mask; - c->options = LOONGARCH_CPU_CPUCFG | LOONGARCH_CPU_IOCSR | - LOONGARCH_CPU_TLB | LOONGARCH_CPU_VINT | LOONGARCH_CPU_WATCH; + c->options = LOONGARCH_CPU_CPUCFG | LOONGARCH_CPU_VINT | + LOONGARCH_CPU_WATCH; elf_hwcap = HWCAP_LOONGARCH_CPUCFG; config = read_cpucfg(LOONGARCH_CPUCFG1); + + if (config & CPUCFG1_ISGR64) + set_isa(c, LOONGARCH_CPU_ISA_LA64); + else if (config & CPUCFG1_ISGR32) + set_isa(c, LOONGARCH_CPU_ISA_LA32S); + else + set_isa(c, LOONGARCH_CPU_ISA_LA32R); + if (config & CPUCFG1_PAGING) + c->options |= LOONGARCH_CPU_TLB; + if (config & CPUCFG1_IOCSR) + c->options |= LOONGARCH_CPU_IOCSR; if (config & CPUCFG1_UAL) { c->options |= LOONGARCH_CPU_UAL; elf_hwcap |= HWCAP_LOONGARCH_UAL; @@ -222,6 +233,7 @@ static inline void cpu_probe_loongson(struct cpuinfo_loongarch *c, unsigned int { 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; @@ -232,40 +244,43 @@ static inline void cpu_probe_loongson(struct cpuinfo_loongarch *c, unsigned int switch (c->processor_id & PRID_SERIES_MASK) { case PRID_SERIES_LA132: c->cputype = CPU_LOONGSON32; - set_isa(c, LOONGARCH_CPU_ISA_LA32S); __cpu_family[cpu] = "Loongson-32bit"; - pr_info("32-bit Loongson Processor probed (LA132 Core)\n"); + core_name = "LA132"; break; case PRID_SERIES_LA264: c->cputype = CPU_LOONGSON64; - set_isa(c, LOONGARCH_CPU_ISA_LA64); __cpu_family[cpu] = "Loongson-64bit"; - pr_info("64-bit Loongson Processor probed (LA264 Core)\n"); + core_name = "LA264"; break; case PRID_SERIES_LA364: c->cputype = CPU_LOONGSON64; - set_isa(c, LOONGARCH_CPU_ISA_LA64); __cpu_family[cpu] = "Loongson-64bit"; - pr_info("64-bit Loongson Processor probed (LA364 Core)\n"); + core_name = "LA364"; break; case PRID_SERIES_LA464: c->cputype = CPU_LOONGSON64; - set_isa(c, LOONGARCH_CPU_ISA_LA64); __cpu_family[cpu] = "Loongson-64bit"; - pr_info("64-bit Loongson Processor probed (LA464 Core)\n"); + core_name = "LA464"; break; case PRID_SERIES_LA664: c->cputype = CPU_LOONGSON64; - set_isa(c, LOONGARCH_CPU_ISA_LA64); __cpu_family[cpu] = "Loongson-64bit"; - pr_info("64-bit Loongson Processor probed (LA664 Core)\n"); + core_name = "LA664"; break; default: /* Default to 64 bit */ - c->cputype = CPU_LOONGSON64; - set_isa(c, LOONGARCH_CPU_ISA_LA64); - __cpu_family[cpu] = "Loongson-64bit"; - pr_info("64-bit Loongson Processor probed (Unknown Core)\n"); + if (c->isa_level & LOONGARCH_CPU_ISA_LA64) { + c->cputype = CPU_LOONGSON64; + __cpu_family[cpu] = "Loongson-64bit"; + } else if (c->isa_level & LOONGARCH_CPU_ISA_LA32S) { + c->cputype = CPU_LOONGSON32; + __cpu_family[cpu] = "Loongson-32bit"; + } else if (c->isa_level & LOONGARCH_CPU_ISA_LA32R) { + c->cputype = CPU_LOONGSON32; + __cpu_family[cpu] = "Loongson-32bit Reduced"; + } } + + pr_info("%s Processor probed (%s Core)\n", __cpu_family[cpu], core_name); } #ifdef CONFIG_64BIT From patchwork Sat Sep 7 10:17:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 826531 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 6DCA115A86E; Sat, 7 Sep 2024 10:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725704236; cv=none; b=VbUlFNgClOpvSVLXYrgo7Hx4HOoP297SzaB9kHbB9iUw+QdjyfFucb2SoPA0FDVulU73nEiG7txr4oZ5Y9FIQVXrdBeUZl77ewisp1/juXeIACm+V7wtMjupD0wiE8FoYD0rX82bQLmaG54+QeQA9/jFopndrIQiXRnlxUQT/0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725704236; c=relaxed/simple; bh=Yuy5vb8N7sg9vNnOgBImg2bFSxqr24R7vO2r2PeHy7I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jj9Nmm4Q+60aRD/9p7/0+3c4h+N9yKasUoMPLtATE5qYMJ+IR31Wxka/0PBatka7GpAb9zqFHpmiD/mChqBt+yeGVQJBk+dmKnnH1iIziialHl7TJYpRcL/jCRcrdlhorUK0gGbiYEdVrfiUIVXyVkiims3uoe4c5P4vAhlwohs= 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=x7zrx9+T; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ePpylAvi; arc=none smtp.client-ip=103.168.172.154 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="x7zrx9+T"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ePpylAvi" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id AB5C411402B4; Sat, 7 Sep 2024 06:17:13 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Sat, 07 Sep 2024 06:17:13 -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=1725704233; x=1725790633; bh=M3LRNb3so3CttnZ+QchME4peIjCeDSAzdbFQH8a41w0=; b= x7zrx9+TrLXnvkJW3WQCfbz0jVNqQXktyzc70fnUIYEJq/BkFzWE/HR5KEaDN3Gc LWA5KsyZtY0dedHneWXAD/VNwrxPg8yuzTecb1VzVotWKzKTEf3NzJSEiaiYxYDf kZ7jn/99viGxQXxQYWPUo0Tflk2AGvULP8NOBIpZS3tOfyy0YNzMV9zjOk4MPmaA BnP00d4nsT66zEnKKq4/a+UshB0laqoz1ws5X5QfkRdtnRllwma+MjtysgoGCNVS BkYEop63PohpfTfWqTseUeNjwrwmr7ntlHRGHmvEGLj/PaXydGRtUvI6ASBXhr1C bk7JD2z3c6DqGd1DBV327A== 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=1725704233; x= 1725790633; bh=M3LRNb3so3CttnZ+QchME4peIjCeDSAzdbFQH8a41w0=; b=e PpylAviiZZQfvGAe92WtIfY32Yrj5gAaqZ8dgpZZJXbmhCweRJVAdziU+LGUdftA GJkhDZtYSzqalRAZDmpWKKrPqZdZh8zGC4+9TVP4nTaR9UlVmZexqbOZb0dEnmT5 poG8b8E4sziK1GPMR7tmSrP7hyUOjV2+l1vef8VC63X+LZe9yjzAO9wrjUKTO9CE AiIR16Q39HZQJ32soA6Hwl0Q1r2cS7t0xJfGW8EHl7tInM5gGQSCKLCOUzgu3l0c l6fnsHCXWptAd4fiprNSC9RXp4blIaTfGcD5klVei4QtS5ir05OUEowCsJ7V3TdL 2GMNkItL+Wwiqb1oZ3whw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeifedgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdej necuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhi hgohgrthdrtghomheqnecuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffek gedugefhtdduudeghfeuveegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdr tghomhdpnhgspghrtghpthhtohepuddvpdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehkvhhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhglhigsehl ihhnuhhtrhhonhhigidruggvpdhrtghpthhtoheptghhvghnhhhurggtrghisehkvghrnh gvlhdrohhrghdprhgtphhtthhopehvihhrvghshhdrkhhumhgrrheslhhinhgrrhhordho rhhgpdhrtghpthhtoheplhhoohhnghgrrhgthheslhhishhtshdrlhhinhhugidruggvvh dprhgtphhtthhopehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmpdhrtghp thhtohepthhssghoghgvnhgusegrlhhphhgrrdhfrhgrnhhkvghnrdguvgdprhgtphhtth hopehkvghrnhgvlhesgigvnhdtnhdrnhgrmhgvpdhrtghpthhtoheplhhinhhugidqmhhi phhssehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Sep 2024 06:17:12 -0400 (EDT) From: Jiaxun Yang Date: Sat, 07 Sep 2024 11:17:05 +0100 Subject: [PATCH 3/5] 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: <20240907-iocsr-v1-3-0c99b3334444@flygoat.com> References: <20240907-iocsr-v1-0-0c99b3334444@flygoat.com> In-Reply-To: <20240907-iocsr-v1-0-0c99b3334444@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=3768; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=Yuy5vb8N7sg9vNnOgBImg2bFSxqr24R7vO2r2PeHy7I=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrQ7Gko++wMDu9nK155d1fMzSrEx9cyjbJezW47y7b939 eJPE4YnHaUsDGJcDLJiiiwhAkp9GxovLrj+IOsPzBxWJpAhDFycAjCRaXoM/2NVn36aJLcucY+Z hcNSpotmayZ2Pp8yYcf65Tr7t5R1zA5hZHjLKcS1V7n2zuYN13awaVjb5C0o71/QzGP5ws7Y+Pm 6fkYA 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 | 63 ++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/arch/loongarch/kernel/cpu-probe.c b/arch/loongarch/kernel/cpu-probe.c index 6a82ceb6e321..968b5a35a0d2 100644 --- a/arch/loongarch/kernel/cpu-probe.c +++ b/arch/loongarch/kernel/cpu-probe.c @@ -173,22 +173,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); @@ -231,16 +215,8 @@ static char cpu_full_name[MAX_NAME_LEN] = " - "; static inline void cpu_probe_loongson(struct cpuinfo_loongarch *c, unsigned int cpu) { - 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: c->cputype = CPU_LOONGSON32; @@ -283,6 +259,36 @@ 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); } +static inline void iocsr_probe_loongson(struct cpuinfo_loongarch *c, unsigned int cpu) +{ + uint64_t *vendor = (void *)(&cpu_full_name[VENDOR_OFFSET]); + uint64_t *cpuname = (void *)(&cpu_full_name[CPUNAME_OFFSET]); + unsigned int config; + + *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 /* For use by uaccess.h */ u64 __ua_limit; @@ -331,6 +337,15 @@ void cpu_probe(void) break; } + if (c->options & LOONGARCH_CPU_IOCSR) { + switch (c->cputype) { + case CPU_LOONGSON32: + case CPU_LOONGSON64: + iocsr_probe_loongson(c, cpu); + break; + } + } + BUG_ON(!__cpu_family[cpu]); BUG_ON(c->cputype == CPU_UNKNOWN); From patchwork Sat Sep 7 10:17:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 826393 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 35AD715A878; Sat, 7 Sep 2024 10:17:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725704238; cv=none; b=YzkNZcGGCg86zidYi9BbticPSLlunjWNOy1/kM450kIVXup4X6lr8uMlcv0hWI9C77rRK7uSqjmkrG/OBBeUjAs0t7TBiln68YWJ4tyGIMlITufndSLd2//GZ+LNNJt32geiKeJ72yLyDD+VuZhsSCaJi3YvLeQ5KJvWYcOONO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725704238; c=relaxed/simple; bh=qTANuJjbaL4aQguTFy385EVc0N0gx837J9fIakktZp8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Nvvvd1Twj+uyBrorrvRJoFDoV6+NIfa+jXtPQETIk4fvFmRb6Q2yJzi3V5FhxSr8u1FymfTWcxWCVcrXCEfEHRU8PBk4JzVBsGi3/YBnYaD6h1Eosi7mwhSCXlw6ks811xtpWxfRgT+Q6/KHD9aBPlneV4XhXg96cV+BHpQxJwg= 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=OiYqyC6e; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qkdE2f3+; arc=none smtp.client-ip=103.168.172.154 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="OiYqyC6e"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qkdE2f3+" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5D10211402E7; Sat, 7 Sep 2024 06:17:15 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Sat, 07 Sep 2024 06:17:15 -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=1725704235; x=1725790635; bh=jIdr+UcqUH9AyHj4ANUKLQsUXQtYA5mdgcOvgeUQQLA=; b= OiYqyC6eW6GPLQso1a0F9Xg8iCHJ4/HmScP+xuw9ydWbWk9tdX4+B1/9NNBu00is Qb/k+ClBI5ue4vg+eNNWl2Cti7XTaLG4en/N0ebFCN5BJLLFVJdNntbTqpx79+pe sNAB5ZuD5MacSSt1cEz+L2STIajpIgpFFJG0CHn6k2brlqioeLnYkUy8mxSLuPMH 2nZxCzTBVyoLTMVVivlyBoUejivCEPBMGP5X1X+EJz/1HyovVw+KznjGKKi5qwfF 5UTRUHygPgigKwSeRgKAHaYIYkDhQ/s/y32ChToWnuDwD86dpDNGAlYQLD9pCgvH BfYf6byUCiaNYZnv7wZ5Tg== 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=1725704235; x= 1725790635; bh=jIdr+UcqUH9AyHj4ANUKLQsUXQtYA5mdgcOvgeUQQLA=; b=q kdE2f3+M419Y7Q9lBbdb38G2+zZ+u2XT3imITCDD1Klw9VbEBh7rhrlZjR1FKYoh m0sx3xIKRxZgdNxAK1NT3l3X+oY7tp70eC+HqaPNdtvVl4chigNNFDGtMcNvQeCy RrRXCKKaTxV3r9Ee06QmbhUAXiCe2sUzbguf0fndEXLaeXPBrJem2yfzThBuK1Q6 5ZCSd1CEb9Mb52K1hny3x0InD8ulnlP00BiAUEvnj7Zhw6vt3Ut6evT2PvDY6ZqW H5nVQiCwFAgJUtraDwqiD11L+akqW8RPUnrltZUjy27bnVPALAhFKOmhF91x7qyk NwLmBMuy33x3JN5Tddn1g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeifedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdej necuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhi hgohgrthdrtghomheqnecuggftrfgrthhtvghrnhepgfeufeeuvefffedufeeuffffgeei veevuefhjeejgffhhfegtedvtdetjeegffeknecuffhomhgrihhnpehrvghlohgtrghtvg gpkhgvrhhnvghlrdhssgenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmpdhnsggprh gtphhtthhopeduvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepkhhvmhesvhhg vghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehtghhlgieslhhinhhuthhrohhnih igrdguvgdprhgtphhtthhopegthhgvnhhhuhgrtggriheskhgvrhhnvghlrdhorhhgpdhr tghpthhtohepvhhirhgvshhhrdhkuhhmrghrsehlihhnrghrohdrohhrghdprhgtphhtth hopehlohhonhhgrghrtghhsehlihhsthhsrdhlihhnuhigrdguvghvpdhrtghpthhtohep jhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomhdprhgtphhtthhopehtshgsoh hgvghnugesrghlphhhrgdrfhhrrghnkhgvnhdruggvpdhrtghpthhtohepkhgvrhhnvghl seigvghntdhnrdhnrghmvgdprhgtphhtthhopehlihhnuhigqdhmihhpshesvhhgvghrrd hkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Sep 2024 06:17:13 -0400 (EDT) From: Jiaxun Yang Date: Sat, 07 Sep 2024 11:17:06 +0100 Subject: [PATCH 4/5] LoongArch: Extract IOCSR definitions to standalone header Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240907-iocsr-v1-4-0c99b3334444@flygoat.com> References: <20240907-iocsr-v1-0-0c99b3334444@flygoat.com> In-Reply-To: <20240907-iocsr-v1-0-0c99b3334444@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=17830; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=qTANuJjbaL4aQguTFy385EVc0N0gx837J9fIakktZp8=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrQ7GkoiKcrXlsRvD/7x4tGPbw6vSqsYCpSr1OQc1yyU1 lCIZ9PoKGVhEONikBVTZAkRUOrb0HhxwfUHWX9g5rAygQxh4OIUgImE32VkWDS/cWWPwPWIj1+y 1G9oWEpf/RoxoTbLLcHl0PIJSz0y5Rj+KeaqZtolfX35m212+V+3x8+VGmJUCu7P8HjN/eM4/91 WbgA= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 As IOCSR is not a part of architecture specification, it is not really appropriate to define those stuff in loongarch.h. Extract those definitions to include/linux/loongson/iocsr.h, so that they can be shared with MIPS based Loongson systems as well. Signed-off-by: Jiaxun Yang --- MAINTAINERS | 1 + arch/loongarch/include/asm/loongarch.h | 90 -------------------------- arch/loongarch/kernel/cpu-probe.c | 7 +- arch/loongarch/kernel/relocate_kernel.S | 5 +- arch/loongarch/kernel/smp.c | 23 +++---- drivers/cpufreq/loongson3_cpufreq.c | 10 +-- drivers/irqchip/irq-loongarch-avec.c | 5 +- drivers/irqchip/irq-loongson-eiointc.c | 5 +- include/linux/loongson/iocsr.h | 110 ++++++++++++++++++++++++++++++++ 9 files changed, 141 insertions(+), 115 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 0a3d9e17295a..f0f4c427e9a3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13305,6 +13305,7 @@ F: Documentation/translations/zh_CN/arch/loongarch/ F: arch/loongarch/ F: drivers/*/*loongarch* F: drivers/cpufreq/loongson3_cpufreq.c +F: include/linux/loongson LOONGSON GPIO DRIVER M: Yinbo Zhu diff --git a/arch/loongarch/include/asm/loongarch.h b/arch/loongarch/include/asm/loongarch.h index 631d249b3ef2..83af801fe870 100644 --- a/arch/loongarch/include/asm/loongarch.h +++ b/arch/loongarch/include/asm/loongarch.h @@ -1049,84 +1049,6 @@ #define ESTATF_IP 0x00003fff -#define LOONGARCH_IOCSR_FEATURES 0x8 -#define IOCSRF_TEMP BIT_ULL(0) -#define IOCSRF_NODECNT BIT_ULL(1) -#define IOCSRF_MSI BIT_ULL(2) -#define IOCSRF_EXTIOI BIT_ULL(3) -#define IOCSRF_CSRIPI BIT_ULL(4) -#define IOCSRF_FREQCSR BIT_ULL(5) -#define IOCSRF_FREQSCALE BIT_ULL(6) -#define IOCSRF_DVFSV1 BIT_ULL(7) -#define IOCSRF_EIODECODE BIT_ULL(9) -#define IOCSRF_FLATMODE BIT_ULL(10) -#define IOCSRF_VM BIT_ULL(11) -#define IOCSRF_AVEC BIT_ULL(15) - -#define LOONGARCH_IOCSR_VENDOR 0x10 - -#define LOONGARCH_IOCSR_CPUNAME 0x20 - -#define LOONGARCH_IOCSR_NODECNT 0x408 - -#define LOONGARCH_IOCSR_MISC_FUNC 0x420 -#define IOCSR_MISC_FUNC_SOFT_INT BIT_ULL(10) -#define IOCSR_MISC_FUNC_TIMER_RESET BIT_ULL(21) -#define IOCSR_MISC_FUNC_EXT_IOI_EN BIT_ULL(48) -#define IOCSR_MISC_FUNC_AVEC_EN BIT_ULL(51) - -#define LOONGARCH_IOCSR_CPUTEMP 0x428 - -#define LOONGARCH_IOCSR_SMCMBX 0x51c - -/* PerCore CSR, only accessible by local cores */ -#define LOONGARCH_IOCSR_IPI_STATUS 0x1000 -#define LOONGARCH_IOCSR_IPI_EN 0x1004 -#define LOONGARCH_IOCSR_IPI_SET 0x1008 -#define LOONGARCH_IOCSR_IPI_CLEAR 0x100c -#define LOONGARCH_IOCSR_MBUF0 0x1020 -#define LOONGARCH_IOCSR_MBUF1 0x1028 -#define LOONGARCH_IOCSR_MBUF2 0x1030 -#define LOONGARCH_IOCSR_MBUF3 0x1038 - -#define LOONGARCH_IOCSR_IPI_SEND 0x1040 -#define IOCSR_IPI_SEND_IP_SHIFT 0 -#define IOCSR_IPI_SEND_CPU_SHIFT 16 -#define IOCSR_IPI_SEND_BLOCKING BIT(31) - -#define LOONGARCH_IOCSR_MBUF_SEND 0x1048 -#define IOCSR_MBUF_SEND_BLOCKING BIT_ULL(31) -#define IOCSR_MBUF_SEND_BOX_SHIFT 2 -#define IOCSR_MBUF_SEND_BOX_LO(box) (box << 1) -#define IOCSR_MBUF_SEND_BOX_HI(box) ((box << 1) + 1) -#define IOCSR_MBUF_SEND_CPU_SHIFT 16 -#define IOCSR_MBUF_SEND_BUF_SHIFT 32 -#define IOCSR_MBUF_SEND_H32_MASK 0xFFFFFFFF00000000ULL - -#define LOONGARCH_IOCSR_ANY_SEND 0x1158 -#define IOCSR_ANY_SEND_BLOCKING BIT_ULL(31) -#define IOCSR_ANY_SEND_CPU_SHIFT 16 -#define IOCSR_ANY_SEND_MASK_SHIFT 27 -#define IOCSR_ANY_SEND_BUF_SHIFT 32 -#define IOCSR_ANY_SEND_H32_MASK 0xFFFFFFFF00000000ULL - -/* Register offset and bit definition for CSR access */ -#define LOONGARCH_IOCSR_TIMER_CFG 0x1060 -#define LOONGARCH_IOCSR_TIMER_TICK 0x1070 -#define IOCSR_TIMER_CFG_RESERVED (_ULCAST_(1) << 63) -#define IOCSR_TIMER_CFG_PERIODIC (_ULCAST_(1) << 62) -#define IOCSR_TIMER_CFG_EN (_ULCAST_(1) << 61) -#define IOCSR_TIMER_MASK 0x0ffffffffffffULL -#define IOCSR_TIMER_INITVAL_RST (_ULCAST_(0xffff) << 48) - -#define LOONGARCH_IOCSR_EXTIOI_NODEMAP_BASE 0x14a0 -#define LOONGARCH_IOCSR_EXTIOI_IPMAP_BASE 0x14c0 -#define LOONGARCH_IOCSR_EXTIOI_EN_BASE 0x1600 -#define LOONGARCH_IOCSR_EXTIOI_BOUNCE_BASE 0x1680 -#define LOONGARCH_IOCSR_EXTIOI_ISR_BASE 0x1800 -#define LOONGARCH_IOCSR_EXTIOI_ROUTE_BASE 0x1c00 -#define IOCSR_EXTIOI_VECTOR_NUM 256 - #ifndef __ASSEMBLY__ static __always_inline u64 drdtime(void) @@ -1146,18 +1068,6 @@ static inline unsigned int get_csr_cpuid(void) return csr_read32(LOONGARCH_CSR_CPUID); } -static inline void csr_any_send(unsigned int addr, unsigned int data, - unsigned int data_mask, unsigned int cpu) -{ - uint64_t val = 0; - - val = IOCSR_ANY_SEND_BLOCKING | addr; - val |= (cpu << IOCSR_ANY_SEND_CPU_SHIFT); - val |= (data_mask << IOCSR_ANY_SEND_MASK_SHIFT); - val |= ((uint64_t)data << IOCSR_ANY_SEND_BUF_SHIFT); - iocsr_write64(val, LOONGARCH_IOCSR_ANY_SEND); -} - static inline unsigned int read_csr_excode(void) { return (csr_read32(LOONGARCH_CSR_ESTAT) & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT; diff --git a/arch/loongarch/kernel/cpu-probe.c b/arch/loongarch/kernel/cpu-probe.c index 968b5a35a0d2..6cd0d653d631 100644 --- a/arch/loongarch/kernel/cpu-probe.c +++ b/arch/loongarch/kernel/cpu-probe.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -265,13 +266,13 @@ static inline void iocsr_probe_loongson(struct cpuinfo_loongarch *c, unsigned in uint64_t *cpuname = (void *)(&cpu_full_name[CPUNAME_OFFSET]); unsigned int config; - *vendor = iocsr_read64(LOONGARCH_IOCSR_VENDOR); - *cpuname = iocsr_read64(LOONGARCH_IOCSR_CPUNAME); + *vendor = iocsr_read64(LOONGSON_IOCSR_VENDOR); + *cpuname = iocsr_read64(LOONGSON_IOCSR_CPUNAME); if (!__cpu_full_name[cpu]) __cpu_full_name[cpu] = cpu_full_name; - config = iocsr_read32(LOONGARCH_IOCSR_FEATURES); + config = iocsr_read32(LOONGSON_IOCSR_FEATURES); if (config & IOCSRF_CSRIPI) c->options |= LOONGARCH_CPU_CSRIPI; if (config & IOCSRF_EXTIOI) diff --git a/arch/loongarch/kernel/relocate_kernel.S b/arch/loongarch/kernel/relocate_kernel.S index 84e6de2fd973..ce40ba6b5975 100644 --- a/arch/loongarch/kernel/relocate_kernel.S +++ b/arch/loongarch/kernel/relocate_kernel.S @@ -5,6 +5,7 @@ * Copyright (C) 2022 Loongson Technology Corporation Limited */ +#include #include #include @@ -88,14 +89,14 @@ SYM_CODE_END(relocate_new_kernel) #ifdef CONFIG_SMP /* * Other CPUs should wait until code is relocated and - * then start at the entry point from LOONGARCH_IOCSR_MBUF0. + * then start at the entry point from LOONGSON_IOCSR_MBUF0. */ SYM_CODE_START(kexec_smp_wait) UNWIND_HINT_UNDEFINED 1: li.w t0, 0x100 /* wait for init loop */ 2: addi.w t0, t0, -1 /* limit mailbox access */ bnez t0, 2b - li.w t1, LOONGARCH_IOCSR_MBUF0 + li.w t1, LOONGSON_IOCSR_MBUF0 iocsrrd.w s0, t1 /* check PC as an indicator */ beqz s0, 1b iocsrrd.d s0, t1 /* get PC via mailbox */ diff --git a/arch/loongarch/kernel/smp.c b/arch/loongarch/kernel/smp.c index 4adbbef3450a..120865985376 100644 --- a/arch/loongarch/kernel/smp.c +++ b/arch/loongarch/kernel/smp.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -164,14 +165,14 @@ static void csr_mail_send(uint64_t data, int cpu, int mailbox) val |= (IOCSR_MBUF_SEND_BOX_HI(mailbox) << IOCSR_MBUF_SEND_BOX_SHIFT); val |= (cpu << IOCSR_MBUF_SEND_CPU_SHIFT); val |= (data & IOCSR_MBUF_SEND_H32_MASK); - iocsr_write64(val, LOONGARCH_IOCSR_MBUF_SEND); + iocsr_write64(val, LOONGSON_IOCSR_MBUF_SEND); /* Send low 32 bits */ val = IOCSR_MBUF_SEND_BLOCKING; val |= (IOCSR_MBUF_SEND_BOX_LO(mailbox) << IOCSR_MBUF_SEND_BOX_SHIFT); val |= (cpu << IOCSR_MBUF_SEND_CPU_SHIFT); val |= (data << IOCSR_MBUF_SEND_BUF_SHIFT); - iocsr_write64(val, LOONGARCH_IOCSR_MBUF_SEND); + iocsr_write64(val, LOONGSON_IOCSR_MBUF_SEND); }; static u32 ipi_read_clear(int cpu) @@ -179,9 +180,9 @@ static u32 ipi_read_clear(int cpu) u32 action; /* Load the ipi register to figure out what we're supposed to do */ - action = iocsr_read32(LOONGARCH_IOCSR_IPI_STATUS); + action = iocsr_read32(LOONGSON_IOCSR_IPI_STATUS); /* Clear the ipi register to clear the interrupt */ - iocsr_write32(action, LOONGARCH_IOCSR_IPI_CLEAR); + iocsr_write32(action, LOONGSON_IOCSR_IPI_CLEAR); wbflush(); return action; @@ -193,7 +194,7 @@ static void ipi_write_action(int cpu, u32 action) val = IOCSR_IPI_SEND_BLOCKING | action; val |= (cpu << IOCSR_IPI_SEND_CPU_SHIFT); - iocsr_write32(val, LOONGARCH_IOCSR_IPI_SEND); + iocsr_write32(val, LOONGSON_IOCSR_IPI_SEND); } static void loongson_send_ipi_single(int cpu, unsigned int action) @@ -322,7 +323,7 @@ void __init loongson_smp_setup(void) cpu_data[0].package = cpu_logical_map(0) / loongson_sysconf.cores_per_package; pv_ipi_init(); - iocsr_write32(0xffffffff, LOONGARCH_IOCSR_IPI_EN); + iocsr_write32(0xffffffff, LOONGSON_IOCSR_IPI_EN); pr_info("Detected %i available CPU(s)\n", loongson_sysconf.nr_cpus); } @@ -370,7 +371,7 @@ void loongson_init_secondary(void) change_csr_ecfg(ECFG0_IM, imask); - iocsr_write32(0xffffffff, LOONGARCH_IOCSR_IPI_EN); + iocsr_write32(0xffffffff, LOONGSON_IOCSR_IPI_EN); #ifdef CONFIG_NUMA numa_add_cpu(cpu); @@ -385,7 +386,7 @@ void loongson_init_secondary(void) void loongson_smp_finish(void) { local_irq_enable(); - iocsr_write64(0, LOONGARCH_IOCSR_MBUF0); + iocsr_write64(0, LOONGSON_IOCSR_MBUF0); pr_info("CPU#%d finished\n", smp_processor_id()); } @@ -435,12 +436,12 @@ void __noreturn arch_cpu_idle_dead(void) __smp_mb(); do { __asm__ __volatile__("idle 0\n\t"); - addr = iocsr_read64(LOONGARCH_IOCSR_MBUF0); + addr = iocsr_read64(LOONGSON_IOCSR_MBUF0); } while (addr == 0); local_irq_disable(); init_fn = (void *)TO_CACHE(addr); - iocsr_write32(0xffffffff, LOONGARCH_IOCSR_IPI_CLEAR); + iocsr_write32(0xffffffff, LOONGSON_IOCSR_IPI_CLEAR); init_fn(); BUG(); @@ -460,7 +461,7 @@ static int loongson_ipi_suspend(void) static void loongson_ipi_resume(void) { - iocsr_write32(0xffffffff, LOONGARCH_IOCSR_IPI_EN); + iocsr_write32(0xffffffff, LOONGSON_IOCSR_IPI_EN); } static struct syscore_ops loongson_ipi_syscore_ops = { diff --git a/drivers/cpufreq/loongson3_cpufreq.c b/drivers/cpufreq/loongson3_cpufreq.c index 6b5e6798d9a2..825324fcba57 100644 --- a/drivers/cpufreq/loongson3_cpufreq.c +++ b/drivers/cpufreq/loongson3_cpufreq.c @@ -182,7 +182,7 @@ static inline int do_service_request(u32 id, u32 info, u32 cmd, u32 val, u32 ext mutex_lock(&cpufreq_mutex[package]); - last.value = iocsr_read32(LOONGARCH_IOCSR_SMCMBX); + last.value = iocsr_read32(LOONGSON_IOCSR_SMCMBX); if (!last.complete) { mutex_unlock(&cpufreq_mutex[package]); return -EPERM; @@ -195,12 +195,12 @@ static inline int do_service_request(u32 id, u32 info, u32 cmd, u32 val, u32 ext msg.extra = extra; msg.complete = 0; - iocsr_write32(msg.value, LOONGARCH_IOCSR_SMCMBX); - iocsr_write32(iocsr_read32(LOONGARCH_IOCSR_MISC_FUNC) | IOCSR_MISC_FUNC_SOFT_INT, - LOONGARCH_IOCSR_MISC_FUNC); + iocsr_write32(msg.value, LOONGSON_IOCSR_SMCMBX); + iocsr_write32(iocsr_read32(LOONGSON_IOCSR_MISC_FUNC) | IOCSR_MISC_FUNC_SOFT_INT, + LOONGSON_IOCSR_MISC_FUNC); for (retries = 0; retries < 10000; retries++) { - msg.value = iocsr_read32(LOONGARCH_IOCSR_SMCMBX); + msg.value = iocsr_read32(LOONGSON_IOCSR_SMCMBX); if (msg.complete) break; diff --git a/drivers/irqchip/irq-loongarch-avec.c b/drivers/irqchip/irq-loongarch-avec.c index 0f6e465dd309..2452c6cc0aa1 100644 --- a/drivers/irqchip/irq-loongarch-avec.c +++ b/drivers/irqchip/irq-loongarch-avec.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -378,9 +379,9 @@ static int __init avecintc_init(struct irq_domain *parent) "irqchip/loongarch/avecintc:starting", avecintc_cpu_online, avecintc_cpu_offline); #endif - value = iocsr_read64(LOONGARCH_IOCSR_MISC_FUNC); + value = iocsr_read64(LOONGSON_IOCSR_MISC_FUNC); value |= IOCSR_MISC_FUNC_AVEC_EN; - iocsr_write64(value, LOONGARCH_IOCSR_MISC_FUNC); + iocsr_write64(value, LOONGSON_IOCSR_MISC_FUNC); return ret; diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c index e24db71a8783..6e81bf27914f 100644 --- a/drivers/irqchip/irq-loongson-eiointc.c +++ b/drivers/irqchip/irq-loongson-eiointc.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -52,9 +53,9 @@ static void eiointc_enable(void) { uint64_t misc; - misc = iocsr_read64(LOONGARCH_IOCSR_MISC_FUNC); + misc = iocsr_read64(LOONGSON_IOCSR_MISC_FUNC); misc |= IOCSR_MISC_FUNC_EXT_IOI_EN; - iocsr_write64(misc, LOONGARCH_IOCSR_MISC_FUNC); + iocsr_write64(misc, LOONGSON_IOCSR_MISC_FUNC); } static int cpu_to_eio_node(int cpu) diff --git a/include/linux/loongson/iocsr.h b/include/linux/loongson/iocsr.h new file mode 100644 index 000000000000..6654a904bcbe --- /dev/null +++ b/include/linux/loongson/iocsr.h @@ -0,0 +1,110 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020-2022 Loongson Technology Corporation Limited + * Copyright (C) 2024, Jiaxun Yang + */ + +#ifndef _LOONGSON_IOCSR_H +#define _LOONGSON_IOCSR_H + +#include +#include + +#ifdef CONFIG_LOONGARCH +#include +#endif + +#define LOONGSON_IOCSR_FEATURES 0x8 +#define IOCSRF_TEMP BIT_ULL(0) +#define IOCSRF_NODECNT BIT_ULL(1) +#define IOCSRF_MSI BIT_ULL(2) +#define IOCSRF_EXTIOI BIT_ULL(3) +#define IOCSRF_CSRIPI BIT_ULL(4) +#define IOCSRF_FREQCSR BIT_ULL(5) +#define IOCSRF_FREQSCALE BIT_ULL(6) +#define IOCSRF_DVFSV1 BIT_ULL(7) +#define IOCSRF_EIODECODE BIT_ULL(9) +#define IOCSRF_FLATMODE BIT_ULL(10) +#define IOCSRF_VM BIT_ULL(11) +#define IOCSRF_AVEC BIT_ULL(15) + +#define LOONGSON_IOCSR_VENDOR 0x10 + +#define LOONGSON_IOCSR_CPUNAME 0x20 + +#define LOONGSON_IOCSR_NODECNT 0x408 + +#define LOONGSON_IOCSR_MISC_FUNC 0x420 +#define IOCSR_MISC_FUNC_SOFT_INT BIT_ULL(10) +#define IOCSR_MISC_FUNC_TIMER_RESET BIT_ULL(21) +#define IOCSR_MISC_FUNC_EXT_IOI_EN BIT_ULL(48) +#define IOCSR_MISC_FUNC_AVEC_EN BIT_ULL(51) + +#define LOONGSON_IOCSR_CPUTEMP 0x428 + +#define LOONGSON_IOCSR_SMCMBX 0x51c + +/* PerCore CSR, only accessible by local cores */ +#define LOONGSON_IOCSR_IPI_STATUS 0x1000 +#define LOONGSON_IOCSR_IPI_EN 0x1004 +#define LOONGSON_IOCSR_IPI_SET 0x1008 +#define LOONGSON_IOCSR_IPI_CLEAR 0x100c +#define LOONGSON_IOCSR_MBUF0 0x1020 +#define LOONGSON_IOCSR_MBUF1 0x1028 +#define LOONGSON_IOCSR_MBUF2 0x1030 +#define LOONGSON_IOCSR_MBUF3 0x1038 + +#define LOONGSON_IOCSR_IPI_SEND 0x1040 +#define IOCSR_IPI_SEND_IP_SHIFT 0 +#define IOCSR_IPI_SEND_CPU_SHIFT 16 +#define IOCSR_IPI_SEND_BLOCKING BIT(31) + +#define LOONGSON_IOCSR_MBUF_SEND 0x1048 +#define IOCSR_MBUF_SEND_BLOCKING BIT_ULL(31) +#define IOCSR_MBUF_SEND_BOX_SHIFT 2 +#define IOCSR_MBUF_SEND_BOX_LO(box) (box << 1) +#define IOCSR_MBUF_SEND_BOX_HI(box) ((box << 1) + 1) +#define IOCSR_MBUF_SEND_CPU_SHIFT 16 +#define IOCSR_MBUF_SEND_BUF_SHIFT 32 +#define IOCSR_MBUF_SEND_H32_MASK 0xFFFFFFFF00000000ULL + +#define LOONGSON_IOCSR_ANY_SEND 0x1158 +#define IOCSR_ANY_SEND_BLOCKING BIT_ULL(31) +#define IOCSR_ANY_SEND_CPU_SHIFT 16 +#define IOCSR_ANY_SEND_MASK_SHIFT 27 +#define IOCSR_ANY_SEND_BUF_SHIFT 32 +#define IOCSR_ANY_SEND_H32_MASK 0xFFFFFFFF00000000ULL + +/* Register offset and bit definition for CSR access */ +#define LOONGSON_IOCSR_TIMER_CFG 0x1060 +#define LOONGSON_IOCSR_TIMER_TICK 0x1070 +#define IOCSR_TIMER_CFG_RESERVED (_ULCAST_(1) << 63) +#define IOCSR_TIMER_CFG_PERIODIC (_ULCAST_(1) << 62) +#define IOCSR_TIMER_CFG_EN (_ULCAST_(1) << 61) +#define IOCSR_TIMER_MASK 0x0ffffffffffffULL +#define IOCSR_TIMER_INITVAL_RST (_ULCAST_(0xffff) << 48) + +#define LOONGSON_IOCSR_EXTIOI_NODEMAP_BASE 0x14a0 +#define LOONGSON_IOCSR_EXTIOI_IPMAP_BASE 0x14c0 +#define LOONGSON_IOCSR_EXTIOI_EN_BASE 0x1600 +#define LOONGSON_IOCSR_EXTIOI_BOUNCE_BASE 0x1680 +#define LOONGSON_IOCSR_EXTIOI_ISR_BASE 0x1800 +#define LOONGSON_IOCSR_EXTIOI_ROUTE_BASE 0x1c00 +#define IOCSR_EXTIOI_VECTOR_NUM 256 + +#ifndef __ASSEMBLY__ +static inline void csr_any_send(unsigned int addr, unsigned int data, + unsigned int data_mask, unsigned int cpu) +{ + uint64_t val = 0; + + val = IOCSR_ANY_SEND_BLOCKING | addr; + val |= (cpu << IOCSR_ANY_SEND_CPU_SHIFT); + val |= (data_mask << IOCSR_ANY_SEND_MASK_SHIFT); + val |= ((uint64_t)data << IOCSR_ANY_SEND_BUF_SHIFT); + iocsr_write64(val, LOONGSON_IOCSR_ANY_SEND); +} +#endif + +#endif + From patchwork Sat Sep 7 10:17:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 826530 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 EB29815C149; Sat, 7 Sep 2024 10:17:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725704239; cv=none; b=jqRyAXUGQzV24ziSN87xpsGKAqNLcY1QZR+ow98dfrF3MXHolhlrzsnY05bK9O6jIQnZp7CfHfaFqOCYo8QsYGTULAWp7Xp+tC2nAt6Omx4NAZEQ4qahPRHTRUNAvBJUstm9xHrUhRHcPNWV/D9rn6DANQLsLfKAUM+ArLOrsjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725704239; c=relaxed/simple; bh=QR4DGLMUsuXkjf1A1LS7CFLwhFvqzfkt5ophtTS3Iko=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bU5G/dc5xckGGOWgXUBwo7y11hPbrfejqWPT1ZA6apxAUrb1uQJBAqAOyAoNHSR3iRoKMdFvEKF7yr/vGkCGsUe8PZM6m9iRqgqDTYELTLnHClErLnDqGt1UcrdDH/dNSWH+MnzmDBoDyW1cT68S4ipulAOpCoCCnK6DJ3bZolY= 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=Ve3W9ho3; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GMt3N4cH; arc=none smtp.client-ip=103.168.172.154 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="Ve3W9ho3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GMt3N4cH" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id 35FF81140285; Sat, 7 Sep 2024 06:17:17 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Sat, 07 Sep 2024 06:17:17 -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=1725704237; x=1725790637; bh=5yZhMf1etdNhnGTjDvT1Dwa0rJtLOxEPY0uZSbNmmL4=; b= Ve3W9ho35+837RTyIDPCJYoDM0/p1++4Syn+5G84CNLknNhAxgLzpCAQG8WJPb0h 0L0/5QD8oFpdJwPAHMjMGxFvQ+JJfipCPcCo0YDXDJKA4mWztwUqZU0MDPcEJqkU aCjtaSY1nBFW+7XuG94dB107F5fmLmE3KxLepYBTC/ZHL9x1/MMfp7M8+W93S1Vs FOhK9IXklyPJQhQZpEc7p1au8np2hp6H21sSpspLq/AIsp0O5GxYmguVgD+LxORP OqEtg+mQxp7gegTonmc4az1OpdI7E+hnKyV+AtHhCT4zzBjxrHnvmJ3fGURhwMUV /r24eV0ikWZCqCQhuJhMlg== 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=1725704237; x= 1725790637; bh=5yZhMf1etdNhnGTjDvT1Dwa0rJtLOxEPY0uZSbNmmL4=; b=G Mt3N4cHh8TVRV0Il53Hd1ZOMZYUScJvhbGWT/9FDvo90K8PKw68x0/wkq1lrwXGs Wvn69NVHd0ONBj+yNfEkSBVL7xpOPvR2/vsILBdsROiY3vlhH+p/Do6Xl1+rLM+d e5XPuOr5N95MCO72IakwHzwHZ+seCJBSf4qYKHXBspJqIYWkw9nAqj3KustiSUCa I4T9M5xibhdSYj98bEzYSVV90lKfPUQzm8Dlz9Q32ZtwW5NRChKfse9k8kMwD1f6 2e/kGXG03QzNhGo+KvNeiyuMS9p6ceGAIECcEQe816Ah2pRjCxJuEVajyHmk084C Jztqnd3PLxeagAXPIulZQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeifedgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdej necuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhi hgohgrthdrtghomheqnecuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffek gedugefhtdduudeghfeuveegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdr tghomhdpnhgspghrtghpthhtohepuddvpdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehkvhhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhglhigsehl ihhnuhhtrhhonhhigidruggvpdhrtghpthhtoheptghhvghnhhhurggtrghisehkvghrnh gvlhdrohhrghdprhgtphhtthhopehvihhrvghshhdrkhhumhgrrheslhhinhgrrhhordho rhhgpdhrtghpthhtoheplhhoohhnghgrrhgthheslhhishhtshdrlhhinhhugidruggvvh dprhgtphhtthhopehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmpdhrtghp thhtohepthhssghoghgvnhgusegrlhhphhgrrdhfrhgrnhhkvghnrdguvgdprhgtphhtth hopehkvghrnhgvlhesgigvnhdtnhdrnhgrmhgvpdhrtghpthhtoheplhhinhhugidqmhhi phhssehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Sep 2024 06:17:15 -0400 (EDT) From: Jiaxun Yang Date: Sat, 07 Sep 2024 11:17:07 +0100 Subject: [PATCH 5/5] MIPS: Loongson64: Use shared IOCSR header Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240907-iocsr-v1-5-0c99b3334444@flygoat.com> References: <20240907-iocsr-v1-0-0c99b3334444@flygoat.com> In-Reply-To: <20240907-iocsr-v1-0-0c99b3334444@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=10190; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=QR4DGLMUsuXkjf1A1LS7CFLwhFvqzfkt5ophtTS3Iko=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrQ7Gkq/Z0VEJb4KP/A7VOhE3O2/yhb8Z3en1MUFznos3 u9/+UlpRykLgxgXg6yYIkuIgFLfhsaLC64/yPoDM4eVCWQIAxenAExE+xkjw6tLW8xWeYVVOZ56 deLatPxNWxxMuCab/Fm01Ir5pPasE+sZ/jvIb/qp7nlNvfKlfD+bXXqTLZP6jmlV7xyTDY7PFvF /ywUA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 MIPS and LoongArch Loongson CPUs are sharing definition of IOCSR registers, so it makes sense to use the same header as well. Align function names in loongson_regs.h with it's loongarch equivalent and fix up macro names everywhere. Signed-off-by: Jiaxun Yang --- .../include/asm/mach-loongson64/loongson_regs.h | 58 ++++++---------------- arch/mips/kvm/vz.c | 2 +- arch/mips/loongson64/smp.c | 44 ++++++++-------- drivers/platform/mips/cpu_hwmon.c | 7 ++- include/linux/loongson/iocsr.h | 5 +- 5 files changed, 46 insertions(+), 70 deletions(-) diff --git a/arch/mips/include/asm/mach-loongson64/loongson_regs.h b/arch/mips/include/asm/mach-loongson64/loongson_regs.h index fec767507604..d8af16796dbe 100644 --- a/arch/mips/include/asm/mach-loongson64/loongson_regs.h +++ b/arch/mips/include/asm/mach-loongson64/loongson_regs.h @@ -5,12 +5,13 @@ #ifndef _LOONGSON_REGS_H_ #define _LOONGSON_REGS_H_ -#include #include +#include #include #include +#ifndef __ASSEMBLY__ static inline bool cpu_has_cfg(void) { return ((read_c0_prid() & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64G); @@ -33,6 +34,7 @@ static inline u32 read_cpucfg(u32 reg) ); return __res; } +#endif /* Bit Domains for CFG registers */ #define LOONGSON_CFG0 0x0 @@ -131,6 +133,7 @@ static inline u32 read_cpucfg(u32 reg) #define LOONGSON_CFG7_GCCAEQRP BIT(0) #define LOONGSON_CFG7_UCAWINP BIT(1) +#ifndef __ASSEMBLY__ static inline bool cpu_has_csr(void) { if (cpu_has_cfg()) @@ -139,7 +142,10 @@ static inline bool cpu_has_csr(void) return false; } -static inline u32 csr_readl(u32 reg) +#define cpu_has_iocsr() cpu_has_csr() + +/* For MIPS/Loongson IOCSR and Core CSR are accessed same way */ +static inline u32 csr_read32(u32 reg) { u32 __res; @@ -158,7 +164,7 @@ static inline u32 csr_readl(u32 reg) return __res; } -static inline u64 csr_readq(u32 reg) +static inline u64 csr_read64(u32 reg) { u64 __res; @@ -177,7 +183,7 @@ static inline u64 csr_readq(u32 reg) return __res; } -static inline void csr_writel(u32 val, u32 reg) +static inline void csr_write32(u32 val, u32 reg) { /* WRCSR reg, val */ __asm__ __volatile__( @@ -193,7 +199,7 @@ static inline void csr_writel(u32 val, u32 reg) ); } -static inline void csr_writeq(u64 val, u32 reg) +static inline void csr_write64(u64 val, u32 reg) { /* DWRCSR reg, val */ __asm__ __volatile__( @@ -209,43 +215,10 @@ static inline void csr_writeq(u64 val, u32 reg) ); } -/* Public CSR Register can also be accessed with regular addresses */ -#define CSR_PUBLIC_MMIO_BASE 0x1fe00000 - -#define MMIO_CSR(x) (void *)TO_UNCAC(CSR_PUBLIC_MMIO_BASE + x) - -#define LOONGSON_CSR_FEATURES 0x8 -#define LOONGSON_CSRF_TEMP BIT(0) -#define LOONGSON_CSRF_NODECNT BIT(1) -#define LOONGSON_CSRF_MSI BIT(2) -#define LOONGSON_CSRF_EXTIOI BIT(3) -#define LOONGSON_CSRF_IPI BIT(4) -#define LOONGSON_CSRF_FREQ BIT(5) - -#define LOONGSON_CSR_VENDOR 0x10 /* Vendor name string, should be "Loongson" */ -#define LOONGSON_CSR_CPUNAME 0x20 /* Processor name string */ -#define LOONGSON_CSR_NODECNT 0x408 -#define LOONGSON_CSR_CPUTEMP 0x428 - -/* PerCore CSR, only accessible by local cores */ -#define LOONGSON_CSR_IPI_STATUS 0x1000 -#define LOONGSON_CSR_IPI_EN 0x1004 -#define LOONGSON_CSR_IPI_SET 0x1008 -#define LOONGSON_CSR_IPI_CLEAR 0x100c -#define LOONGSON_CSR_IPI_SEND 0x1040 -#define CSR_IPI_SEND_IP_SHIFT 0 -#define CSR_IPI_SEND_CPU_SHIFT 16 -#define CSR_IPI_SEND_BLOCK BIT(31) - -#define LOONGSON_CSR_MAIL_BUF0 0x1020 -#define LOONGSON_CSR_MAIL_SEND 0x1048 -#define CSR_MAIL_SEND_BLOCK BIT_ULL(31) -#define CSR_MAIL_SEND_BOX_LOW(box) (box << 1) -#define CSR_MAIL_SEND_BOX_HIGH(box) ((box << 1) + 1) -#define CSR_MAIL_SEND_BOX_SHIFT 2 -#define CSR_MAIL_SEND_CPU_SHIFT 16 -#define CSR_MAIL_SEND_BUF_SHIFT 32 -#define CSR_MAIL_SEND_H32_MASK 0xFFFFFFFF00000000ULL +#define iocsr_read32(reg) csr_read32(reg) +#define iocsr_read64(reg) csr_read64(reg) +#define iocsr_write32(val, reg) csr_write32(val, reg) +#define iocsr_write64(val, reg) csr_write64(val, reg) static inline u64 drdtime(void) { @@ -264,5 +237,6 @@ static inline u64 drdtime(void) ); return val; } +#endif #endif diff --git a/arch/mips/kvm/vz.c b/arch/mips/kvm/vz.c index 99d5a71e4300..4964c1922b23 100644 --- a/arch/mips/kvm/vz.c +++ b/arch/mips/kvm/vz.c @@ -2977,7 +2977,7 @@ static int kvm_vz_hardware_enable(void) #ifdef CONFIG_CPU_LOONGSON64 /* Control guest CCA attribute */ if (cpu_has_csr()) - csr_writel(csr_readl(0xffffffec) | 0x1, 0xffffffec); + csr_write32(csr_read32(0xffffffec) | 0x1, 0xffffffec); #endif return 0; diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c index 147acd972a07..0cf03377edf0 100644 --- a/arch/mips/loongson64/smp.c +++ b/arch/mips/loongson64/smp.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -19,7 +20,6 @@ #include #include #include -#include #include #include "smp.h" @@ -45,19 +45,19 @@ static void csr_mail_send(uint64_t data, int cpu, int mailbox) { uint64_t val; - /* send high 32 bits */ - val = CSR_MAIL_SEND_BLOCK; - val |= (CSR_MAIL_SEND_BOX_HIGH(mailbox) << CSR_MAIL_SEND_BOX_SHIFT); - val |= (cpu << CSR_MAIL_SEND_CPU_SHIFT); - val |= (data & CSR_MAIL_SEND_H32_MASK); - csr_writeq(val, LOONGSON_CSR_MAIL_SEND); - - /* send low 32 bits */ - val = CSR_MAIL_SEND_BLOCK; - val |= (CSR_MAIL_SEND_BOX_LOW(mailbox) << CSR_MAIL_SEND_BOX_SHIFT); - val |= (cpu << CSR_MAIL_SEND_CPU_SHIFT); - val |= (data << CSR_MAIL_SEND_BUF_SHIFT); - csr_writeq(val, LOONGSON_CSR_MAIL_SEND); + /* Send high 32 bits */ + val = IOCSR_MBUF_SEND_BLOCKING; + val |= (IOCSR_MBUF_SEND_BOX_HI(mailbox) << IOCSR_MBUF_SEND_BOX_SHIFT); + val |= (cpu << IOCSR_MBUF_SEND_CPU_SHIFT); + val |= (data & IOCSR_MBUF_SEND_H32_MASK); + iocsr_write64(val, LOONGSON_IOCSR_MBUF_SEND); + + /* Send low 32 bits */ + val = IOCSR_MBUF_SEND_BLOCKING; + val |= (IOCSR_MBUF_SEND_BOX_LO(mailbox) << IOCSR_MBUF_SEND_BOX_SHIFT); + val |= (cpu << IOCSR_MBUF_SEND_CPU_SHIFT); + val |= (data << IOCSR_MBUF_SEND_BUF_SHIFT); + iocsr_write64(val, LOONGSON_IOCSR_MBUF_SEND); }; static u32 csr_ipi_read_clear(int cpu) @@ -65,9 +65,9 @@ static u32 csr_ipi_read_clear(int cpu) u32 action; /* Load the ipi register to figure out what we're supposed to do */ - action = csr_readl(LOONGSON_CSR_IPI_STATUS); + action = iocsr_read32(LOONGSON_IOCSR_IPI_STATUS); /* Clear the ipi register to clear the interrupt */ - csr_writel(action, LOONGSON_CSR_IPI_CLEAR); + iocsr_write32(action, LOONGSON_IOCSR_IPI_CLEAR); return action; } @@ -77,22 +77,22 @@ static void csr_ipi_write_action(int cpu, u32 action) unsigned int irq = 0; while ((irq = ffs(action))) { - uint32_t val = CSR_IPI_SEND_BLOCK; + uint32_t val = IOCSR_IPI_SEND_BLOCKING; val |= (irq - 1); - val |= (cpu << CSR_IPI_SEND_CPU_SHIFT); - csr_writel(val, LOONGSON_CSR_IPI_SEND); + val |= (cpu << IOCSR_IPI_SEND_CPU_SHIFT); + iocsr_write32(val, LOONGSON_IOCSR_IPI_SEND); action &= ~BIT(irq - 1); } } static void csr_ipi_write_enable(int cpu) { - csr_writel(0xffffffff, LOONGSON_CSR_IPI_EN); + iocsr_write32(0xffffffff, LOONGSON_IOCSR_IPI_EN); } static void csr_ipi_clear_buf(int cpu) { - csr_writeq(0, LOONGSON_CSR_MAIL_BUF0); + iocsr_write64(0, LOONGSON_IOCSR_MBUF0); } static void csr_ipi_write_buf(int cpu, struct task_struct *idle) @@ -169,7 +169,7 @@ static void legacy_ipi_write_buf(int cpu, struct task_struct *idle) static void csr_ipi_probe(void) { - if (cpu_has_csr() && csr_readl(LOONGSON_CSR_FEATURES) & LOONGSON_CSRF_IPI) { + if (cpu_has_iocsr() && iocsr_read32(LOONGSON_IOCSR_FEATURES) & IOCSRF_CSRIPI) { ipi_read_clear = csr_ipi_read_clear; ipi_write_action = csr_ipi_write_action; ipi_write_enable = csr_ipi_write_enable; diff --git a/drivers/platform/mips/cpu_hwmon.c b/drivers/platform/mips/cpu_hwmon.c index 2ac2f31090f9..9b0b39a39d13 100644 --- a/drivers/platform/mips/cpu_hwmon.c +++ b/drivers/platform/mips/cpu_hwmon.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only #include +#include #include #include #include @@ -9,7 +10,6 @@ #include #include #include -#include static int csr_temp_enable; @@ -24,7 +24,7 @@ int loongson3_cpu_temp(int cpu) u32 reg, prid_rev; if (csr_temp_enable) { - reg = (csr_readl(LOONGSON_CSR_CPUTEMP) & 0xff); + reg = (iocsr_read32(LOONGSON_IOCSR_CPUTEMP) & 0xff); goto out; } @@ -136,8 +136,7 @@ static int __init loongson_hwmon_init(void) pr_info("Loongson Hwmon Enter...\n"); if (cpu_has_csr()) - csr_temp_enable = csr_readl(LOONGSON_CSR_FEATURES) & - LOONGSON_CSRF_TEMP; + csr_temp_enable = iocsr_read32(LOONGSON_IOCSR_FEATURES) & IOCSRF_TEMP; if (!csr_temp_enable && !loongson_chiptemp[0]) return -ENODEV; diff --git a/include/linux/loongson/iocsr.h b/include/linux/loongson/iocsr.h index 6654a904bcbe..15e70e6e132e 100644 --- a/include/linux/loongson/iocsr.h +++ b/include/linux/loongson/iocsr.h @@ -10,9 +10,12 @@ #include #include -#ifdef CONFIG_LOONGARCH +#if defined(CONFIG_LOONGARCH) #include #endif +#if defined(CONFIG_MIPS) && defined(CONFIG_MACH_LOONGSON64) +#include +#endif #define LOONGSON_IOCSR_FEATURES 0x8 #define IOCSRF_TEMP BIT_ULL(0)