From patchwork Wed Mar 27 10:11:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 1916661 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=dAxUq5ik; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=fpJKKtGG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V4MsY2VMTz1yXq for ; Wed, 27 Mar 2024 21:11:59 +1100 (AEDT) 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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hrq2lSha9F/lZ4/WsEB0WclLDFPckPEsAMy/be0j5Y4=; b=dAxUq5ikhPQV5a upi+5pcgQ0xLQaUzOV1ZUFx3UaeztrAis3Sz3e02Na6dGl27JNyXxy1ZTM53og0wybn7pHgNYdUGO /5ULxot7a5dUNq83q9lmL2mT1xtysCzT6VvgR4QNXs/pbbfbsTvuh6pqbeIoneEjghAZ4eYp0ZTWH wSzQ6RIbT1ZA3zCUb7Vgyy20WFrSXv7kBsNxiWyp49Euw+xWsaUqqi51ei1xNFxW9qE2AT4xi+kTt 2+SXmZYa9ibKSCT8bzse4u0zQHaV5jIS1tUagTUSoyBW5gNLlNwPdJiYXHtXmLGHgsSPfIpBWnZNm rGrMFxCavhfeXeCYUepw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpQG7-00000008MB5-3Tzj; Wed, 27 Mar 2024 10:11:51 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpQG2-00000008M8g-3rHr for opensbi@lists.infradead.org; Wed, 27 Mar 2024 10:11:49 +0000 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-56c147205b9so1294078a12.0 for ; Wed, 27 Mar 2024 03:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1711534304; x=1712139104; darn=lists.infradead.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=HXh4D9WbcqREhvV7IzjN/yaNphUlCFZDBPC/N6KbuIA=; b=fpJKKtGGVQINeiPskkD7/1+W7qlrQKIOsNUhd0Qsbd1+zCu5csfo9DdsyIvPzLcA+P 0VGHnOqEY9wOMRaunpqkWmCMhXVa5F+N8RBeY99pn4/X95R3x2XF10bwzVgWe8PduNt7 bEHZihoecuIWt0Rl8xovdGB/AtGDbYbgeiVAwuXMVpO8Cjt2CHadbd2KBkhjtlThG8BO IE13TXNZAsIL4EoDnxCT6REmyJHauegK7mr1V30QPBZ44X9JKBvc87VD2nkEXxbmHnCW sZYI9BapU10KhltknDZHfzXDqhTfGA0smnbWGLYq/z/+uLmCr7E2SFRfEIm4hg5wVBnn J2Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711534304; x=1712139104; 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=HXh4D9WbcqREhvV7IzjN/yaNphUlCFZDBPC/N6KbuIA=; b=KjWRzRuWBn2mNcPbaCFP5OulMZUOZn2buHM3ZAQO6LF984wSXJoNqqXTusId19++V1 hh75OF6okkD+8UaR5JNouCpIMgCnLL3kmrBY5Cm2vjkL5u7r/xe5pKfknodTe/h4v+Wb ooFnrMT8Jx2SL21oP5yyICLbMzUTa/cotnDg59wgIf/JVmS1mGVrHKXQCNnjZqATRVft UQEN9H46ntNGqFHOOMBgHyrkO4AVoer1bMg+kFyeRdP8oUmEMZGZhOXYW1a/TbO1vLxZ tDgcdhw2fhGZzlix+oF1jZHp+n318xQByn48T7Sjt9+0j67/ltCj4xC7koziBOLVkBSH rsHQ== X-Gm-Message-State: AOJu0YxhTIf6d7G6chrAf/smxfaq8EQeXnqzLza2n05rCANqA9rHxJk2 +HALw8AlEeD/Vwosk0k1tiz84AU3rNUYP4zFW3pZ6dAR3l+G9e8mcO7cGeF9tfxTzP65O1XdtnN pVIw= X-Google-Smtp-Source: AGHT+IGXN1gXlOyahkSKD0cEFdMve+kE0cQ7/tUdm5QF2mZe4NK2O6F4VO2CrSFzOpR+JP7+vOQu0g== X-Received: by 2002:a50:9ec3:0:b0:56b:aa17:813a with SMTP id a61-20020a509ec3000000b0056baa17813amr3254221edf.21.1711534303935; Wed, 27 Mar 2024 03:11:43 -0700 (PDT) Received: from antares.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id dh16-20020a0564021d3000b0056c1c4b870asm2451653edb.16.2024.03.27.03.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 03:11:43 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: opensbi@lists.infradead.org, Philipp Tomsich , Cooper Qu , Zhiwei Liu , Huang Tao , Alistair Francis Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH 1/9] sbi_platform: Add mechanism to handle CSR reads/writes in platform Date: Wed, 27 Mar 2024 11:11:29 +0100 Message-ID: <20240327101137.3644359-2-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327101137.3644359-1-christoph.muellner@vrull.eu> References: <20240327101137.3644359-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_031147_057144_A0FDAA23 X-CRM114-Status: GOOD ( 11.36 ) X-Spam-Score: -0.2 (/) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22bombadil=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__Platforms_may_want_to_provide_access_t?= =?unknown-8bit?q?o_custom_CSRs=2E_Let=27s?= =?unknown-8bit?q?_add_a_layer_that_allows_platforms_to_implement_CSR_read/wr?= =?unknown-8bit?q?ite_handlers=2C_where?= =?unknown-8bit?q?_custom_CSRs_can_be_accessed=2E_Signed-off-by=3A_Christoph_?= =?unknown-8bit?q?M=C3=BCllner_=3Cchristoph=2Emuellner=40vrull=2Eeu=3E?= =?unknown-8bit?q?_---_include/sbi/sbi=5Fplatform=2Eh_=7C_48_++++++++++++++++?= =?unknown-8bit?q?++++++++++++++++++++++?= =?unknown-8bit?q?_1_file_changed=2C_48_insertions=28+=29_?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=28-0=2E2_points=2C_5=2E0_re?= =?unknown-8bit?q?quired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID=5FAU__________Message_has_a_valid_DKIM?= =?unknown-8bit?q?_or_DK_signature_from_author=27s?= =?unknown-8bit?q?_domain?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID=5FEF__________Message_has_a_valid_DKIM?= =?unknown-8bit?q?_or_DK_signature_from?= =?unknown-8bit?q?_envelope-from_domain?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily_valid?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C_no?= =?unknown-8bit?q?_trust?= =?unknown-8bit?b?IFsyYTAwOjE0NTA6NDg2NDoyMDowOjA6MDo1MzUgbGlzdGVkIGluXQ==?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Platforms may want to provide access to custom CSRs. Let's add a layer that allows platforms to implement CSR read/write handlers, where custom CSRs can be accessed. Signed-off-by: Christoph Müllner --- include/sbi/sbi_platform.h | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 581935a..5dbbfea 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -148,6 +148,12 @@ struct sbi_platform_operations { /** platform specific handler to fixup store fault */ int (*emulate_store)(int wlen, unsigned long addr, union sbi_ldst_data in_val); + /** Platform-specific handler to read custom CSRs. */ + int (*read_csr)(int csr_num, struct sbi_trap_regs *regs, + ulong *csr_val); + /** Platform-specific handler to write custom CSRs. */ + int (*write_csr)(int csr_num, struct sbi_trap_regs *regs, + ulong csr_val); }; /** Platform default per-HART stack size for exception/interrupt handling */ @@ -728,6 +734,48 @@ static inline int sbi_platform_emulate_store(const struct sbi_platform *plat, return SBI_ENOTSUPP; } +/** + * Ask platform to read from CSR. + * + * @param plat pointer to struct sbi_platform + * @param csr_num CSR number + * @param regs Pointer to register state + * @param csr_val Pointer where the read value will be stored + * + * @return 0 on success and negative error code on failure + */ +static inline int sbi_platform_read_csr(const struct sbi_platform *plat, + int csr_num, + struct sbi_trap_regs *regs, + ulong *csr_val) +{ + if (plat && sbi_platform_ops(plat)->read_csr) + return sbi_platform_ops(plat)->read_csr(csr_num, regs, csr_val); + + return SBI_ENOTSUPP; +} + +/** + * Ask platform to write to CSR. + * + * @param plat pointer to struct sbi_platform + * @param csr_num CSR number + * @param regs Pointer to register state + * @param csr_val Value to write + * + * @return 0 on success and negative error code on failure + */ +static inline int sbi_platform_write_csr(const struct sbi_platform *plat, + int csr_num, + struct sbi_trap_regs *regs, + ulong csr_val) +{ + if (plat && sbi_platform_ops(plat)->write_csr) + return sbi_platform_ops(plat)->write_csr(csr_num, regs, csr_val); + + return SBI_ENOTSUPP; +} + #endif #endif