From patchwork Tue Jan 28 04:59:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13952020 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 69765C0218D for ; Tue, 28 Jan 2025 05:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oeVIzNSPZmA2fNgWgqUHeaXkn7W1jxmdbFnvOlWyRaU=; b=c2WoBWw3KpioEb fM2MkJGKs46Uoeu+EpiAny+oqougGhVIKAxdOdRmfhKK8z8apummM+CgWejuP5VziHEhRpJIp7g8j 8piQnPT6bDQj1htsoMVcDRO8ww6z4CgXRCysrMxIm8x1nEenS2/MFpWAnITjeSfRzoZ9SPj84jZCr TajRV3yQdesXoCwZlCTuXOqJt0r3oX6Mkv1gssl24mH9BXSLmgt9qxwMXukR42HHfG3HqJILRqVKn nOldDBWN8jBs2IBJOfMQjdUBBA2m3f85pfKzpg8xF3x3c8CkgnLOHytWZzmplP+P6HafsKA7CsPsg xivEx7m+mylIhu1GcFuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tcdo9-000000046ap-0vrs; Tue, 28 Jan 2025 05:06:41 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tcdhd-000000044P8-4Bcg for linux-riscv@lists.infradead.org; Tue, 28 Jan 2025 05:00:00 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2ee46851b5eso6894825a91.1 for ; Mon, 27 Jan 2025 20:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1738040397; x=1738645197; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vL7HY0dEKrWKEMn+BoWLtPifTt6hhf+Eo5KcPrG96mI=; b=MIPwWr7c3LsYDiZlez8A2xfJMqgzrW7ReQAHMoKb/4mB/yv42KC+N6kpruKDGtUMBc qluNllWDBHnEEcgz1eWlMq4GFamJXbJwUQqS17sCBT3TOaRq7V8zyalQJK0gEnnZhokO 2oPG5YKw6S7vVDJVENWr/ug/yqJTJSDeJ605xuXJLO5872C7w8qd9O8XFJSxhDZiVS/s Y9eICp+Ab/qRgERAHufx35TzJmS9XmhPqJb51jROzL8VLo9yTnA/o8akdPxJOdvDZZxs WG0WLKOH8Ekqc+dh13MR0zGFzIdYlEMjs379Fc2LTp2jX5qSd2UlK5rlV8gJl0mT+xo+ n5pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738040397; x=1738645197; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vL7HY0dEKrWKEMn+BoWLtPifTt6hhf+Eo5KcPrG96mI=; b=JD7aya7d/OTXSwaFn4XHARuz9c3jklibzbCOf1BiHT7IQ2Hqg31WKpxhp7Ulxx2uwz INYiuuAgKPPtsfPtGg/U0oAwd954XNUUtObeExcmEbD01e+x3JhrkPYVyIRY86dAfU5u 5Q6b7ylA2I0FMRUY6bLEX4uysCBj5DPmS/HVFZ9FP8wKqLgBpt4b4V4LE8F5PoBcebFk xmj77Fbf3B5vDqcQsJDtDLuTi3mKZLzAaEXn4S/to0bikn00XX7xICTVTGOLhnRMOEHq I2F14NmNVTe5H5S0B+oP4815KLE31/PkzTCDQgqwrRSPvfAtlzcNBqylkPns06+k9+6f JlAg== X-Gm-Message-State: AOJu0YwCFjosFqGxwwU4MLD8jBOusk0WCn9dSWRVTIDOQ52KU7ROGzp/ iz3V7jKOWwrLkdba47+inKXa/jGegd/tp7kpP1bCGRV/iazncXhzZxL7nrY2qkM= X-Gm-Gg: ASbGncv2EUqBZo3SSRXzv7BSL7MemG9qATFMpsHtwpfMTIzr5JCS0BnuBAXrqUvavCu u5bcDTugRACYbXytwel261rJDGR2FtmS5mHDtWtoRnfDoEgg60PVQqA2ZdGw9TMuWCn4bKTZkXh AyBScYRC3Palv3kBWvmzmYGvb9lxB01Ko7EKV6GCZ/aqF54tDBlEgm+xAlkDksENBnScESjBKhy 7W7qD9neqXkRsDKZ1zGaZWwtI3SZ3aFldVMmsfBsdVcK2PHKhLbFMXWAUs9a5v8tdNYCYB+Ljea iMZeHI/rmY+1JBcjQaijcz5hnaXP X-Google-Smtp-Source: AGHT+IEydkqGnMas9EixfltXBAZwEmzDNcAGB6aZaVaiRCrDSr5UAXUAKLQCmfBM6LnRIdbwcEstgw== X-Received: by 2002:a17:90a:da8e:b0:2ea:5e0c:2847 with SMTP id 98e67ed59e1d1-2f782d37703mr53064728a91.22.1738040397475; Mon, 27 Jan 2025 20:59:57 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7ffa5a7f7sm8212776a91.11.2025.01.27.20.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 20:59:57 -0800 (PST) From: Atish Patra Date: Mon, 27 Jan 2025 20:59:46 -0800 Subject: [PATCH v3 05/21] RISC-V: Define indirect CSR access helpers MIME-Version: 1.0 Message-Id: <20250127-counter_delegation-v3-5-64894d7e16d5@rivosinc.com> References: <20250127-counter_delegation-v3-0-64894d7e16d5@rivosinc.com> In-Reply-To: <20250127-counter_delegation-v3-0-64894d7e16d5@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Anup Patel , Atish Patra , Will Deacon , Mark Rutland , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , weilin.wang@intel.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Conor Dooley , devicetree@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, Atish Patra X-Mailer: b4 0.15-dev-13183 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250127_205958_059143_6DFB1FEA X-CRM114-Status: GOOD ( 11.53 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The indriect CSR requires multiple instructions to read/write CSR. Add a few helper functions for ease of usage. Signed-off-by: Atish Patra --- arch/riscv/include/asm/csr_ind.h | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/arch/riscv/include/asm/csr_ind.h b/arch/riscv/include/asm/csr_ind.h new file mode 100644 index 000000000000..d36e1e06ed2b --- /dev/null +++ b/arch/riscv/include/asm/csr_ind.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024 Rivos Inc. + */ + +#ifndef _ASM_RISCV_CSR_IND_H +#define _ASM_RISCV_CSR_IND_H + +#include + +#define csr_ind_read(iregcsr, iselbase, iseloff) ({ \ + unsigned long value = 0; \ + unsigned long flags; \ + local_irq_save(flags); \ + csr_write(CSR_ISELECT, iselbase + iseloff); \ + value = csr_read(iregcsr); \ + local_irq_restore(flags); \ + value; \ +}) + +#define csr_ind_write(iregcsr, iselbase, iseloff, value) ({ \ + unsigned long flags; \ + local_irq_save(flags); \ + csr_write(CSR_ISELECT, iselbase + iseloff); \ + csr_write(iregcsr, value); \ + local_irq_restore(flags); \ +}) + +#define csr_ind_warl(iregcsr, iselbase, iseloff, warl_val) ({ \ + unsigned long old_val = 0, value = 0; \ + unsigned long flags; \ + local_irq_save(flags); \ + csr_write(CSR_ISELECT, iselbase + iseloff); \ + old_val = csr_read(iregcsr); \ + csr_write(iregcsr, warl_val); \ + value = csr_read(iregcsr); \ + csr_write(iregcsr, old_val); \ + local_irq_restore(flags); \ + value; \ +}) + +#endif