From patchwork Mon Dec 16 08:48:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13909398 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 D49F6E77183 for ; Mon, 16 Dec 2024 08:48: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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qsC6qX2OPDLqroKC0bA4ARS/wXtqcYZZuDua2aRNO0o=; b=Yl5uvio2CGYyVX yj9c6/E67PbwuEg4XuX3PPL+m2RqkCZJ/oZugkILwcvcpM7isPUrOHbtAirdIyNg+kV0hiGOF8p9N /Z6Wf9CHqEKenPxNWXLyEQMnSPG4aivSKO3I3cKbw/UBI/LuYdkcfQzxNz0p1ZyXXq5wygPFMKFXP dKViDD63/YuhgjFrBx++2c0rnnuQAKCTkJ5aXvaCUK0NsTBIm1aPY8r/GCBcRspacEK28RskvQiQD gtQXahphLzsrZ6Pn/tbd6RXA4vG80PlYof/As6fkUJpd54A/oP2jJx+/GKR3q4D42kW8UeP15CUDa fClWUeXNA7DvWJ53ZUNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mQ-00000009RG7-21yb; Mon, 16 Dec 2024 08:48:42 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mO-00000009RFC-48vO for linux-riscv@lists.infradead.org; Mon, 16 Dec 2024 08:48:42 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-216401de828so29581245ad.3 for ; Mon, 16 Dec 2024 00:48:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734338920; x=1734943720; 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=Eei5CeEAyNvf2PS4xwdFaq29ZOKnFWm89T3hqpCmQHw=; b=EiFeIgqc5kUAB7RPlA3ykItnNY/V3TGjE9mjx7vo7f4CQlEfWgDiAIg6huimlR+Mhr 5+0wYg4Wji+AZlw6EYI+exF7v1AWvkN7uH/tf0jfdYF3lh3WAnOAWUpJ5MxOsU56WWHL Yu3ZnHAB88naVWNSizWcUmSVkJ1SZOGCoJcwiFDJ99cpexwjNwoOiIyur2Wc/FIH8Pu1 DvGnoYn4/FvnqCpPKC8ft8zwm3H4iS4Xv99SPk+fVL6VsjYWY2h1C9Q0bteyTT609eqO JvYfIcXCxrJe2J8k/5NFUvptwF+sa+43PRh1VNIru5dY1ryoM/KHtQcsMRgqydjjJlKL OidQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734338920; x=1734943720; 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=Eei5CeEAyNvf2PS4xwdFaq29ZOKnFWm89T3hqpCmQHw=; b=VFIssCzp2+T5H/Wa2Zn73XHa0EvbR6jzzzyoIRWyjVkY/dNZeKWYm4GYNRioMPZ4G5 GJzOD+xGhT7RDeHDYf8pWYvs87hFEaJTcYj94/aF92MH7DaqcJcCr9Hozj5WBf6s/4F+ lu0k+uKyEplsCSlM5crDr+VPDgt02CcXWqgVDXBXJRAWqjrXt47M8eSHfFg5zf51yrFu rVPycuigxeLOHh3LEbWrAtP8KITPoJSQZ0iv5KRDhalPPS9KxF4x9MrIY3P3nmxvkXDp ZFj7CdFq6Bx0ZxfNrTrFPqt4zuaKPqE4e5l7fAyeucPpMAZe+KiSovna+IbCaiKpvSBn tq3Q== X-Forwarded-Encrypted: i=1; AJvYcCWHrP//xxtQTEKSc5dtn4zPxf7q9JVnbVHitA4l+zcsoMcQDmgiBXPtr9OIX4rMwfR7wzzcCrLqlL9xwg==@lists.infradead.org X-Gm-Message-State: AOJu0YyL1blLg/Yad5k9CfMpLj+wKSGUzl3pglIihOmKMeHEY+UTNmmg F2qBpv+jxnO7+KN5BY5qjzeOuPCLrzMduyFpJLHL47xyEgWAoZwon2qvlXuP6ZY= X-Gm-Gg: ASbGncteZ6lshAkPnkEoEYQ1l5ZGmhRNRCNd4vM/h+FEP6X2G9XamA5ybzaaohmhhHK ZBFJOyzo7DXtRFlegYFVDyWtJqT9BKg35nTXxhBaxR4R6aJ6+l9/Zyjn0KdNVsD0xO0yxV9kPBx A9yThOMX9LLFqa/zww6x7uTnvg3Ls7zmzrdYrDnscJcfCrhF6WKZ8Xl6HlKMdZ8P0wtXAClOhos o2H+Nq3Qe0K1rrtRrA6YgbMd4ngvy72hUs2v+sEx4rKcjtRfrEuFjfNdRoQ1SL1uDNKpS/IPze7 AEeQ9P/Ke2v0gFw= X-Google-Smtp-Source: AGHT+IH23xFB2kNx/gOskLUHtyyFSXX+WD7siqR8qRzGwZ+oJpSpIMc4NvB33gu7U5vEEvlRMs2S/A== X-Received: by 2002:a17:902:ce85:b0:216:7cbf:951f with SMTP id d9443c01a7336-218929c72b5mr138434115ad.21.1734338919985; Mon, 16 Dec 2024 00:48:39 -0800 (PST) Received: from localhost.localdomain ([223.185.130.105]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e501d0sm37711495ad.116.2024.12.16.00.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 00:48:39 -0800 (PST) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar Subject: [RFC PATCH 1/8] riscv: Add new error codes defined by SBI v3.0 Date: Mon, 16 Dec 2024 14:18:10 +0530 Message-ID: <20241216084817.373131-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241216084817.373131-1-apatel@ventanamicro.com> References: <20241216084817.373131-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241216_004841_028307_49099B43 X-CRM114-Status: UNSURE ( 9.61 ) X-CRM114-Notice: Please train this message. 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: , Cc: Anup Patel , devicetree@vger.kernel.org, Leyfoon Tan , Anup Patel , Paul Walmsley , linux-kernel@vger.kernel.org, Palmer Dabbelt , Atish Patra , linux-riscv@lists.infradead.org, Andrew Jones , linux-clk@vger.kernel.org, Rahul Pathak Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The SBI v3.0 defines new error codes so add these new error codes to the asm/sbi.h for use by newer SBI extensions. Signed-off-by: Anup Patel --- arch/riscv/include/asm/sbi.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 6c82318065cf..bc35ad750e28 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -418,6 +418,10 @@ enum sbi_ext_nacl_feature { #define SBI_ERR_ALREADY_STARTED -7 #define SBI_ERR_ALREADY_STOPPED -8 #define SBI_ERR_NO_SHMEM -9 +#define SBI_ERR_INVALID_STATE -10 +#define SBI_ERR_BAD_RANGE -11 +#define SBI_ERR_TIMEOUT -12 +#define SBI_ERR_IO -13 extern unsigned long sbi_spec_version; struct sbiret { @@ -504,9 +508,15 @@ static inline int sbi_err_map_linux_errno(int err) case SBI_ERR_DENIED: return -EPERM; case SBI_ERR_INVALID_PARAM: + case SBI_ERR_INVALID_STATE: + case SBI_ERR_BAD_RANGE: return -EINVAL; case SBI_ERR_INVALID_ADDRESS: return -EFAULT; + case SBI_ERR_TIMEOUT: + return -ETIMEDOUT; + case SBI_ERR_IO: + return -EIO; case SBI_ERR_NOT_SUPPORTED: case SBI_ERR_FAILURE: default: From patchwork Mon Dec 16 08:48:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13909399 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 7FD05E7717F for ; Mon, 16 Dec 2024 08:48:53 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UIKYIf6FhxA4muHgh3h12eOuAiClQrTPiUhFwpGrg+o=; b=ON1Q1uSFfeYcR6 eYIYEuKfZF0/F1ObUAbyQ8/R29Su/uRqMVl0nxd+/4VNtcxCE3zJaN/cwHGHkpNJFCiDst4JvdxzP 14xIxm4GgW4//z3ljiyNJXsg7MSCwfEgly3bAk3UA9gXESmlwpyOijmtu1h2WqkLbnK99Sfbk11g7 jNGiTCqaX3XjJJIOjOIzJHS0gtLSNKNPXmr80btHTHPQ/MgIvHVMn7JkdGHqbI2AWgvNykmtR6eXe FRXOOQIGyc19WBKVUNO+3vA5TNM9SvmAkENvodF0AVrUuMO7Uh4mnFltRPlEUKtVnO1djkh+tPJdP 8r+UHUtQVhRQj/5pJXUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mX-00000009RI8-0Ep8; Mon, 16 Dec 2024 08:48:49 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mU-00000009RGq-1zFd for linux-riscv@lists.infradead.org; Mon, 16 Dec 2024 08:48:47 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2166022c5caso28702705ad.2 for ; Mon, 16 Dec 2024 00:48:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734338925; x=1734943725; 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=cMO3jfuL5hmIGaCvebBRAsGTgzlAeW19tcp/lCnmhhM=; b=jmsYJxDuDTMqNGpZgvBrO1FNUVR5aHyWIIWrSYS2CdCyPy7OgP4ninnPsHFruAnWOY ki4GJ3EuXUv4XnDiJXu4M1P1fke6lfr/XHfBbndNo/Els+Yh9gRehg96hY2K/P9LcH2u Y8o+BStD+b4OR3JKwxJ/P+QIIzWv7I17mfK8JtDHdmFfz52aLKBBu0mYIZtDCrEGBGOh GeAMjYi9MWB6InXCBRLsximyMV2gVbCrsojI3iVLWsCwQ5imlUJ6lYh9SERdCHjibb9x wBGbqiocKNxvMQ3kBSreK1lighgaTJCOrFxWuobI7vMrExXVgGzrBX61tv/34/BQkSCj zB6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734338925; x=1734943725; 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=cMO3jfuL5hmIGaCvebBRAsGTgzlAeW19tcp/lCnmhhM=; b=dQfe3E+qMeSLNo9mA8t44q1KwztGc4jhO0WegbfzY9uN6XxOa/7XkEr0oiJsudIEtR rQbQiC3mXfkClGjjiIuCwomCQ/6OuL/heaQWCtWSm1byFWoNK2G/9hKLYYTUoHRpULeQ fMIgVVuvchoxn3rW1e3FfaOQhRbiHIBhWlTy2PqWyCXptS6lQWbDfJa1g37rXUcsRs+S CfcyiTLRWo08GhY7LKjmSw4koDlUmfaNbLZ37/4tOb+rymfJRqUl7R8zEgnT13SgEBqN qofGFdhVlPrr5xrTrz91pAmYdXfiomW3HcE4adgXBlw99pEHOhUaBDUXjCqaXWwRpi5E 3a4g== X-Forwarded-Encrypted: i=1; AJvYcCV/z17poxsP2nwPgr48QWnMBoOQsbnZU9GHz+qbuISYraedmoBCrli5r4Tyf3OJjgsY3QSMVSHfKbE8MQ==@lists.infradead.org X-Gm-Message-State: AOJu0YwqHT744c5JkqsoPay/4d3o8MSAMqLhi0naXb9jyDlFwFMKyE8S jBipmWGYW4M12MJtpKlm5pXnaHeMRmsHY/sUI8tfJSKTlMUdvj/ee983io5BbuU= X-Gm-Gg: ASbGncvUk4P6BvyHqgCbilgN9dYQvXLttctjTefScC9d7LAtCKX6XNC/I/MIVk9jpMc G/A9yZp6npWVrTTViZt6wuwGRkpDP/1kVuKCmsDEvhjV6Y+U+kpCndvWatrnbmmKHbkkSM/CFYp SOC5LMGWD3Wfy2yoD7NQuyq5mS46aluyGDhzQm/ywrCrnCWqFPk/4CC8wnUPt34yGCtlnfU7/GK +w/oimT1u8jNgYPCTceOA2iOKOUXn+f/WhoyhWyIx/tBHyewftteCCOO2Y1/LDEmczPVt/puvYc 0EagkWnX4oQiAuQ= X-Google-Smtp-Source: AGHT+IFP0telDvRf+8kDLe8zYK7tj9L0Ym2laW4HDpkbeQU6flKJQAmEPGbnSvej/CfGRJih0n5Yog== X-Received: by 2002:a17:902:d48b:b0:216:60a5:ebfd with SMTP id d9443c01a7336-21892a8483fmr144631265ad.55.1734338925436; Mon, 16 Dec 2024 00:48:45 -0800 (PST) Received: from localhost.localdomain ([223.185.130.105]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e501d0sm37711495ad.116.2024.12.16.00.48.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 00:48:44 -0800 (PST) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar Subject: [RFC PATCH 2/8] dt-bindings: mailbox: Add bindings for RPMI shared memory transport Date: Mon, 16 Dec 2024 14:18:11 +0530 Message-ID: <20241216084817.373131-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241216084817.373131-1-apatel@ventanamicro.com> References: <20241216084817.373131-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241216_004846_518153_96B0C581 X-CRM114-Status: GOOD ( 15.14 ) 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: , Cc: Anup Patel , devicetree@vger.kernel.org, Leyfoon Tan , Anup Patel , Paul Walmsley , linux-kernel@vger.kernel.org, Palmer Dabbelt , Atish Patra , linux-riscv@lists.infradead.org, Andrew Jones , linux-clk@vger.kernel.org, Rahul Pathak Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add device tree bindings for the common RISC-V Platform Management Interface (RPMI) shared memory transport as a mailbox controller. Signed-off-by: Anup Patel --- .../mailbox/riscv,rpmi-shmem-mbox.yaml | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml diff --git a/Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml b/Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file mode 100644 index 000000000000..8d713ba7ffc7 --- /dev/null +++ b/Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml @@ -0,0 +1,135 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mailbox/riscv,sbi-mpxy-mbox.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: RISC-V Platform Management Interface (RPMI) shared memory mailbox + +maintainers: + - Anup Patel + +description: | + The RISC-V Platform Management Interface (RPMI) [1] defines a common shared + memory based RPMI transport. This RPMI shared memory transport integrates as + mailbox controller in the SBI implementation or supervisor software whereas + each RPMI service group is mailbox client in the SBI implementation and + supervisor software. + + =========================================== + References + =========================================== + + [1] RISC-V Platform Management Interface (RPMI) + https://github.com/riscv-non-isa/riscv-rpmi/releases + +properties: + compatible: + const: riscv,rpmi-shmem-mbox + + reg: + oneOf: + - items: + - description: A2P request queue base address + - description: P2A acknowledgment queue base address + - description: P2A request queue base address + - description: A2P acknowledgment queue base address + - description: A2P doorbell address + - items: + - description: A2P request queue base address + - description: P2A acknowledgment queue base address + - description: A2P doorbell address + + reg-names: + oneOf: + - items: + - const: a2p-req + - const: p2a-ack + - const: p2a-req + - const: a2p-ack + - const: db-reg + - items: + - const: a2p-req + - const: p2a-ack + - const: db-reg + + interrupts: + minItems: 1 + maxItems: 1 + description: + The RPMI shared memory transport supports wired interrupt specified by + this property as the P2A doorbell. + + msi-parent: + description: + The RPMI shared memory transport supports MSI as P2A doorbell and this + property specifies the target MSI controller. + + riscv,slot-size: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 64 + description: + Power-of-2 RPMI slot size of the RPMI shared memory transport. + + riscv,db-mask: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Update only the register bits of doorbell defined by the mask (32 bit). + If this property is not present then mask is assumed to be 0xffffffff. + + riscv,db-value: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Value written to the doorbell register bits (32-bit access) specified + by the riscv,db-mask property. If this property is not present then + value is assumed to be 0x1. + + "#mbox-cells": + const: 1 + description: + The first cell specifies RPMI service group ID. + +required: + - compatible + - reg + - reg-names + - riscv,slot-size + - "#mbox-cells" + +anyOf: + - required: + - interrupts + - required: + - msi-parent + +additionalProperties: false + +examples: + - | + // Example 1 (RPMI shared memory with only 2 queues): + mailbox@10080000 { + compatible = "riscv,rpmi-shmem-mbox"; + reg = <0x00 0x10080000 0x00 0x10000>, + <0x00 0x10090000 0x00 0x10000>, + <0x00 0x100a0000 0x00 0x4>; + reg-names = "a2p-req", "p2a-ack", "db-reg"; + msi-parent = <&imsic_mlevel>; + riscv,slot-size = <64>; + #mbox-cells = <1>; + }; + - | + // Example 2 (RPMI shared memory with only 4 queues): + mailbox@10001000 { + compatible = "riscv,rpmi-shmem-mbox"; + reg = <0x00 0x10001000 0x00 0x800>, + <0x00 0x10001800 0x00 0x800>, + <0x00 0x10002000 0x00 0x800>, + <0x00 0x10002800 0x00 0x800>, + <0x00 0x10003000 0x00 0x4>; + reg-names = "a2p-req", "p2a-ack", "db-reg"; + msi-parent = <&imsic_mlevel>; + riscv,slot-size = <64>; + riscv,db-mask = <0x00008000>; + riscv,db-value = <0x00008000>; + #mbox-cells = <1>; + }; From patchwork Mon Dec 16 08:48:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13909400 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 832B9E77180 for ; Mon, 16 Dec 2024 08:48:58 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=cQ3s2YLlI1tcrBlcnenUY3rBKde2HZKFn9ZuP65dnGg=; b=416ARGxjlajMVH JGjBC3JVgqtvieBTt56csMtksgN6A3bgRu8OTGLEIQZXsuyR32ULdk9CyCuiDPHgYuuz/aXO1cqyH 7BoWQiqAhArS2msHIFKwEAa58gFQ1XQZrQfoALeGfDG3MW5MozrBDjdt5CaPr0eqZbBPBT7u5c4bR Z8crRyksId1pMa/YK5IyNQS06/A8nmHPU/TWMwCwCR/HyGe4GoA5BBG1HpqckSNMYxoRUVX3uyTUZ hSShoxyJYRq82C8WzuqSyFUwRUIEOppExbUYpjTa9xle9grk4imXTDSMZiDGXIDhTGLSsBzVJjICp /54DJ9cLbHMYmP4Ho5zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mb-00000009RKo-37OD; Mon, 16 Dec 2024 08:48:53 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mZ-00000009RJv-2gPO for linux-riscv@lists.infradead.org; Mon, 16 Dec 2024 08:48:53 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-2156e078563so28460035ad.2 for ; Mon, 16 Dec 2024 00:48:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734338931; x=1734943731; 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=ssg9a8o6gZjpZvchZzGUt0Qt044T+B0HdxLRYjAYuuA=; b=exD4L56Q0f/4sFy9/OaPVVoov3EiSmaIzD6lvVaT+4/fi22m8ZY4f45sGHsqJquFnq EEVFX8kOCfN8zvk5UFW1HK6sgDFPGTa2IQs2CcmTcskgCPh5afwvUSTc5ZSVpNzKrjJe DUrj/ZsUMXTBpU/e+j02762jLWIDAmECPkEkEFHhfBUqeaGBB+T1g1GrFl6qC/qpzUl6 Ky6lR88IdsGVjRTze6SXr/VoVsKRSgCrKlKMZhK9YDEO+W/FbgR0SSmg30feQw3pgvQq qJx2GrB2oDNtrgWcMPxkwgpRdp+YHg+b55LGH50tt0vpwQcXwS9q2Jrm0gBkG9TYRlmQ Mk2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734338931; x=1734943731; 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=ssg9a8o6gZjpZvchZzGUt0Qt044T+B0HdxLRYjAYuuA=; b=unNGCf62Ld9n7D6SUTEPNfFcKJvq3IZYQZZ9P1MTaiXbg2SSiHqWkSoodWYnI/i2bq SiizF79LCfW0XZ9+ok/kDwLmWVGfWpOD11irkQNy1Z5IMun8+ch6lturUhT4I3NkuneS 5aPtaJZFLr3a8bIPyUFufXmRRRrwliKpRems5eNs/X6RDOelfgGLUuZVGv/pbM7ZTZHE RwkrRiwqPQ/Uc0ngU0+Va6alipnunnWjQVqsru3kkkXVo9hNK2BwNpXX9AmXaapsUCjC W9mtTzbdVSKQLw2IX/Fl2SDnfRWA3fhX4YNKsQL9DfSxM18/txEGQtk4DM11SKHjdxLu 193A== X-Forwarded-Encrypted: i=1; AJvYcCVPtgdTDGuhj+JdvPu7MGfAAfGgoJeJzjIt0lO/IfaKbliH4+Xhvww1e4H+t2GiteMWbud9aUzYhhsFmQ==@lists.infradead.org X-Gm-Message-State: AOJu0Yw9fLn7XGNGmBQupp/lwsdS+ES4AoZ6koJSMiMt9Dj1tKV17iyv Yma1UtcP0tWztcIPB9M7v3cmSpby+Igx5vFNSOlQUGHA7950F5lsfJqgSfXalR4= X-Gm-Gg: ASbGncvd7e1Cweu0ZClyQ5SZ9tn+fp7JLq0jQY19MYcHAg3F7W8U4RM2nI5m4sdZy4F 1ccHSTMT/SUX5t+DyuTXEdctLKdx9LlU2cQWMyiTb1haFGw2vNNN+EsDx7+U8EnqLqmVepqlAKy L3enuy4Y9SmP6AssGFcVGMgCloLlp723Eq+m8RFNEDP1F+qedkutewf3n3L3/NTFNsxwjcq6Qoi 4XRr+ERFDomWyTAjFUj6ZGMGyd2jR6L5Cu/yel9bjR3PCz566E2mATiz787wkOskvN0xG7/AbyY eIQDPlT7wJxN8sc= X-Google-Smtp-Source: AGHT+IEjkG82UTaLNxVZ0a1jk6JfxX7g2yNmmqLUOhK1uOCG12kx8FsqZmcvvvLQulkpsVPnYWSQaw== X-Received: by 2002:a17:902:ec89:b0:216:770e:f46 with SMTP id d9443c01a7336-21892a74611mr174024415ad.54.1734338930854; Mon, 16 Dec 2024 00:48:50 -0800 (PST) Received: from localhost.localdomain ([223.185.130.105]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e501d0sm37711495ad.116.2024.12.16.00.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 00:48:50 -0800 (PST) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar Subject: [RFC PATCH 3/8] dt-bindings: mailbox: Add bindings for RISC-V SBI MPXY extension Date: Mon, 16 Dec 2024 14:18:12 +0530 Message-ID: <20241216084817.373131-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241216084817.373131-1-apatel@ventanamicro.com> References: <20241216084817.373131-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241216_004851_679093_7A5464C2 X-CRM114-Status: GOOD ( 13.13 ) 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: , Cc: Anup Patel , devicetree@vger.kernel.org, Leyfoon Tan , Anup Patel , Paul Walmsley , linux-kernel@vger.kernel.org, Palmer Dabbelt , Atish Patra , linux-riscv@lists.infradead.org, Andrew Jones , linux-clk@vger.kernel.org, Rahul Pathak Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add device tree bindings for the RISC-V SBI Message Proxy (MPXY) extension as a mailbox controller. Signed-off-by: Anup Patel --- .../bindings/mailbox/riscv,sbi-mpxy-mbox.yaml | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml diff --git a/Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml b/Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml new file mode 100644 index 000000000000..8a05e089b710 --- /dev/null +++ b/Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml @@ -0,0 +1,54 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mailbox/riscv,sbi-mpxy-mbox.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: RISC-V SBI Message Proxy (MPXY) extension based mailbox + +maintainers: + - Anup Patel + +description: | + The RISC-V SBI Message Proxy (MPXY) extension [1] allows supervisor + software to send messages through the SBI implementation (M-mode + firmware or HS-mode hypervisor). The underlying message protocol + and message format used by the supervisor software could be some + other standard protocol compatible with the SBI MPXY extension + (such as RISC-V Platform Management Interface (RPMI) [2]). + + =========================================== + References + =========================================== + + [1] RISC-V Supervisor Binary Interface (SBI) + https://github.com/riscv-non-isa/riscv-sbi-doc/releases + + [2] RISC-V Platform Management Interface (RPMI) + https://github.com/riscv-non-isa/riscv-rpmi/releases + +properties: + $nodename: + const: sbi-mpxy-mbox + + compatible: + const: riscv,sbi-mpxy-mbox + + "#mbox-cells": + const: 2 + description: + The first cell specifies channel_id of the SBI MPXY channel, + the second cell specifies MSG_PROT_ID of the SBI MPXY channel + +required: + - compatible + - "#mbox-cells" + +additionalProperties: false + +examples: + - | + sbi-mpxy-mbox { + compatible = "riscv,sbi-mpxy-mbox"; + #mbox-cells = <2>; + }; From patchwork Mon Dec 16 08:48:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13909401 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 51B3AE7717F for ; Mon, 16 Dec 2024 08:49:04 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qVHKZM2817OBnvHHY6m88D1XISWZMLMaf+neLAJVxFg=; b=sEcqokNsb5J182 CI7TXTYDmLbbGdqXMrwkJb89PSqeVwNGUnK+1m4RCxXfKSbp8PkTK2HIfeTm7bmX7p2HVBUHNi0TI 3uKU2r1ylwjZwF8RJRSkZLBjKkD3kNicP0ncCe6fqMmGbrVwKdv4zjW0LdXfJp1GGtIIrXWefJbz8 LAqsREuSQsyoSdcaluMuYSFPsUwnWXdfYId3jP89q610oIDaS5F1WfYgfFdDWCsmB4XmznNTtgY9S duhh8DKDPkLAL0nqxaXFuFkiJMgjAVmlc9L4/10R+QxFjGifiKu+kTJc3LdHRIcCqHTrGR8SwWM7v MVgiSZ5jFKCASVRAGW8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mi-00000009RNz-1SVI; Mon, 16 Dec 2024 08:49:00 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mf-00000009RMd-0elt for linux-riscv@lists.infradead.org; Mon, 16 Dec 2024 08:48:58 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-21644e6140cso35495275ad.1 for ; Mon, 16 Dec 2024 00:48:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734338936; x=1734943736; 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=tTubMU2kWF4VQtI7+afjrAi0Qg8VFM9pvYCuyyQx/90=; b=Vejj0Ni0C9UAupw4bqsdOmzDacBo8W8RSpFhMLbkvxW8n4WP8zLPgtToBfQMU1ntGe 3RIZeEm+UQTgQhtZ7rJOjl2CxwCFWTZwzNE3np01cJ5nXJjCsQ4YFMS1bhwvBHXscnan tXUrcP1U8zXt15acXUv4OGJyTNaFhXwYVdXb2au0u/ysnf77IOEuNk9Aw83Qhkty/B/P aVvlPzwZPRvIrCv8Gzu2Wjvw23a3MTQx/zOi2mS1nuFU3N1A4fymFSeh0o5/fKspbMAL DQO+fG4/WZrFla7ZP65Hp8E6Uec3zBaK8AaVsKZFSdZHjCmopL9nPKYgBE+ag07y8Vjm ZXIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734338936; x=1734943736; 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=tTubMU2kWF4VQtI7+afjrAi0Qg8VFM9pvYCuyyQx/90=; b=ORH2iA9553CkCb7e/7rqb4UG5szu1lEFvDhCaTczkHajvwDltBQHOSAoZYt5x+zVzA sWcQzpWjOyVYAoIVkdO/7zidVXVPaAfy+C8b0dMIZU8TrOSO2eo45vo4CTSN+9lqzzWm 0IEEs5rqJHaTb9ojkX9MZTrR/fYH8002sJojuvKlc8XwkwgV3pKP/pALOrBbrSnNyA7L kt4Svf3/cJuNQRbqXT5t54ekiNsqIBj0eFsWdOEm+Vcalb8bQgzQM1EEV2GlTLy7OqGf n4tgG72JMRlxyqW0JPhLAkgUu5EW2WsDeFLW9oI8aJJyr9iA+3Sqoq4ZikZj53jVTqEG nnTQ== X-Forwarded-Encrypted: i=1; AJvYcCUcYv3qekXYnfCGdISElKed/Zv90V+T7BIJ0Hu+p5z4hkNCCRyrK0ybbPDe2cdXjKylw7OxTuTk2ewN/A==@lists.infradead.org X-Gm-Message-State: AOJu0YzE9Cu+7kyjyTX7c1AC02r9yMBmPd6TX2MKJg2WOYhtA/x461SB pbtHBmzyF27jNrajVxvp9sRbb/gSYMsk0MtlUQmv4MDK/xztFcYPRSefXzqp5eM= X-Gm-Gg: ASbGncvgMwWAXEWXauNFxUdR9CYOPVsaUSZLx+o2FpBtERZe0RYL0s3CXp9Ypyw/xbk oH/9kdWAvJJRTG5vVTWXhOk/dYh+zcrZnSD3BTmIjOXLJDTXVo4a9lJpVOdVJOfVxr9ZFZN/jiM cQhvh3lcA+Fk4aSGPGhLvIwlYFMKB/50nX8IPgBQgSuSDpIKDlr4u8UGRDl660tJgrf+tNtESIF E41ETx2mgB3nYztwG/9JtR8dKaxL6gRwmHc+nNqQiWALRBmsChMAOraQ7sxjRYWNb6oxVt2qqFU k3qTI4zOgUbxqjY= X-Google-Smtp-Source: AGHT+IHpuJTFzeEhjSiGdehFNiKlPC/zQ57iedGa+8ilj9RzYBUBHeCW2l8Z59j6jtt7ugE/4lqbMg== X-Received: by 2002:a17:902:ec90:b0:215:75a5:f72b with SMTP id d9443c01a7336-21892aed1eemr161821665ad.53.1734338936193; Mon, 16 Dec 2024 00:48:56 -0800 (PST) Received: from localhost.localdomain ([223.185.130.105]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e501d0sm37711495ad.116.2024.12.16.00.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 00:48:55 -0800 (PST) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar Subject: [RFC PATCH 4/8] RISC-V: Add defines for the SBI message proxy extension Date: Mon, 16 Dec 2024 14:18:13 +0530 Message-ID: <20241216084817.373131-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241216084817.373131-1-apatel@ventanamicro.com> References: <20241216084817.373131-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241216_004857_195831_32123978 X-CRM114-Status: GOOD ( 10.21 ) 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: , Cc: Anup Patel , devicetree@vger.kernel.org, Leyfoon Tan , Anup Patel , Paul Walmsley , linux-kernel@vger.kernel.org, Palmer Dabbelt , Atish Patra , linux-riscv@lists.infradead.org, Andrew Jones , linux-clk@vger.kernel.org, Rahul Pathak Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add defines for the new SBI message proxy extension which is part of the SBI v3.0 specification. Co-developed-by: Rahul Pathak Signed-off-by: Rahul Pathak Signed-off-by: Anup Patel --- arch/riscv/include/asm/sbi.h | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index bc35ad750e28..18817efba430 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -35,6 +35,7 @@ enum sbi_ext_id { SBI_EXT_DBCN = 0x4442434E, SBI_EXT_STA = 0x535441, SBI_EXT_NACL = 0x4E41434C, + SBI_EXT_MPXY = 0x4D505859, /* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START = 0x08000000, @@ -401,6 +402,64 @@ enum sbi_ext_nacl_feature { #define SBI_NACL_SHMEM_SRET_X(__i) ((__riscv_xlen / 8) * (__i)) #define SBI_NACL_SHMEM_SRET_X_LAST 31 +enum sbi_ext_mpxy_fid { + SBI_EXT_MPXY_SET_SHMEM, + SBI_EXT_MPXY_GET_CHANNEL_IDS, + SBI_EXT_MPXY_READ_ATTRS, + SBI_EXT_MPXY_WRITE_ATTRS, + SBI_EXT_MPXY_SEND_MSG_WITH_RESP, + SBI_EXT_MPXY_SEND_MSG_NO_RESP, + SBI_EXT_MPXY_GET_NOTIFICATION_EVENTS, +}; + +enum sbi_mpxy_attribute_id { + /* Standard channel attributes managed by MPXY framework */ + SBI_MPXY_ATTR_MSG_PROT_ID = 0x00000000, + SBI_MPXY_ATTR_MSG_PROT_VER = 0x00000001, + SBI_MPXY_ATTR_MSG_MAX_LEN = 0x00000002, + SBI_MPXY_ATTR_MSG_SEND_TIMEOUT = 0x00000003, + SBI_MPXY_ATTR_MSG_COMPLETION_TIMEOUT = 0x00000004, + SBI_MPXY_ATTR_CHANNEL_CAPABILITY = 0x00000005, + SBI_MPXY_ATTR_SSE_EVENT_ID = 0x00000006, + SBI_MPXY_ATTR_MSI_CONTROL = 0x00000007, + SBI_MPXY_ATTR_MSI_ADDR_LO = 0x00000008, + SBI_MPXY_ATTR_MSI_ADDR_HI = 0x00000009, + SBI_MPXY_ATTR_MSI_DATA = 0x0000000A, + SBI_MPXY_ATTR_EVENTS_STATE_CONTROL = 0x0000000B, + SBI_MPXY_ATTR_STD_ATTR_MAX_IDX, + /* + * Message protocol specific attributes, managed by + * the message protocol specification. + */ + SBI_MPXY_ATTR_MSGPROTO_ATTR_START = 0x80000000, + SBI_MPXY_ATTR_MSGPROTO_ATTR_END = 0xffffffff +}; + +/* Possible values of MSG_PROT_ID attribute */ +enum sbi_mpxy_msgproto_id { + SBI_MPXY_MSGPROTO_RPMI_ID = 0x0, +}; + +/** RPMI message protocol specific MPXY attributes */ +enum sbi_mpxy_rpmi_attribute_id { + SBI_MPXY_RPMI_ATTR_SERVICEGROUP_ID = SBI_MPXY_ATTR_MSGPROTO_ATTR_START, + SBI_MPXY_RPMI_ATTR_SERVICEGROUP_VERSION, + SBI_MPXY_RPMI_ATTR_MAX_ID, +}; + +/* Encoding of MSG_PROT_VER attribute */ +#define SBI_MPXY_MSG_PROT_VER_MAJOR(__ver) (((__ver) >> 16) & 0xffff) +#define SBI_MPXY_MSG_PROT_VER_MINOR(__ver) ((__ver) & 0xffff) +#define SBI_MPXY_MSG_PROT_MKVER(__maj, __min) (((__maj) << 16) | (__min)) + +/* Capabilities available through CHANNEL_CAPABILITY attribute */ +#define SBI_MPXY_CHAN_CAP_MSI BIT(0) +#define SBI_MPXY_CHAN_CAP_SSE BIT(1) +#define SBI_MPXY_CHAN_CAP_EVENTS_STATE BIT(2) +#define SBI_MPXY_CHAN_CAP_SEND_WITH_RESP BIT(3) +#define SBI_MPXY_CHAN_CAP_SEND_WITHOUT_RESP BIT(4) +#define SBI_MPXY_CHAN_CAP_GET_NOTIFICATIONS BIT(5) + /* SBI spec version fields */ #define SBI_SPEC_VERSION_DEFAULT 0x1 #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 From patchwork Mon Dec 16 08:48:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13909402 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 49E81E7717F for ; Mon, 16 Dec 2024 08:49:10 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=O03Ox/ikMHUfughnRQyibxJAmPcJD8XXaT2vqZCoP8o=; b=sAuHxhFaUOycds PjxC5zLuXDoao38/MRbqh65hzKsvzOxvgYOiUYgIPBrdTVAxPptBi3EqPijZ3pduy3loRFj2qL/z7 rKcIR5Jw9j3wf6NTHZqP+bOA/Ej0o6vO9243idn2Dzjk1C3rz2gGFjTUn3lNrPZxIyJOLTGzotRM9 ES1PGl4ZmX7lYFuxhCVjuu0TLq+c23jJcp1nqAfdr/spSibLy/oCnVWJH51PFkWV5Z8W5petH3GtR EOw0PwHfLDLlQem8AIrcs/IM8nhJfgqkEWO/1QjKwiROVpyT+AMf9sX7Uu/sqAvDdTplRy7+3ika3 qsUbAqeGV7yz//J+oSzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mm-00000009RQK-3ryz; Mon, 16 Dec 2024 08:49:04 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mk-00000009ROr-1W5c for linux-riscv@lists.infradead.org; Mon, 16 Dec 2024 08:49:03 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-2161eb94cceso25014575ad.2 for ; Mon, 16 Dec 2024 00:49:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734338942; x=1734943742; 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=Vj0v6rXKvRsgy/Lo1T614knekVJOULW+di93SCW+j5g=; b=MsHZ/9o5nOvmpX419/uwcCMVOVtmYFwt2o2Ww2aSmdzl6dQBh2fZZDmNMSuYRgRQrW JEUlJShsS1MScHrokyYzQ7b02hF2U5W2K4rlzUZ3Pf4VKMhFPB0q4gyk5goZwyqUp07K gOlC9TzOtjgorBXq4QEQIztbUtm/28clq9t41ZXArnYbWpd9Y6EAa/l+9ScAdUAd1NE6 HOrKtOx3ShwVRX5hskIxkAwjI51jQ0WjF/Bg7ryebfGrr+XW9i3GNA+tpXw6T3hN54Fv xCozQqaL4ATUjRJ0ZzCl2v72r30/bjMBDBvOOQhqcrKz3LTJOFwiMrAMKC4jkdPSIx0L p4jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734338942; x=1734943742; 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=Vj0v6rXKvRsgy/Lo1T614knekVJOULW+di93SCW+j5g=; b=MYo0bci2nvQRb7SlWoDz63X/9BfmgY0w2MSzJg6Z2o5yyyBezH8X+uHKLwmj1eAkIX APdThsYqv8wYl4jBiltZHhN466REowi7i2zBj+YQsK7OhkOfvC979jCQjDW4TVu+qXYX QyK6xtbNZlIMo+TOt9DOVDrmvwwHsrPpdi0DHGafx1K7FPs11W83DlHe3mP43Zc0XL2G yy16y+Zv1AYMVyzi8kyvwg1GUNLJMw1LlUn/KbnR6rxt9etNaazca/inWXfHFeNPVQNI aP6vxHdYcHz2P6zLbzHhwWYuzirVCIKjHkAiibjHZc3HMB/ue60t3+MCa09/mXhXGQAv s0Tw== X-Forwarded-Encrypted: i=1; AJvYcCVdp9GsJquhg8vFQ1LcoEpwjQdHzVn5logGu6vo7Kjj93s+q8xrfqABcMk5vfB4irbBcLsm17PYfqDfvA==@lists.infradead.org X-Gm-Message-State: AOJu0Yy7arSW/d8M5TFgtFvPN+VNEfp6IOo/nfyvbIChSwjACdyjL6Zt VHr5kfaxnQnK08VnxlrK4IR8XnHei4PJtF5e/dXO0ZAaqWhiJfBDhCkGcQQJQKU= X-Gm-Gg: ASbGncvrGP4b0+EFh7TdO4hJObMVqOMLF5UmETks3ka4IPONeUrARRHCj11fkyzKXF2 6+D9YTLzt8+A5TK+SaxALWUkBY5SvVCqwFu/5M0WvlELwLbuIZuQ5HUtglLpe7f4cc9zLwkFGgW qob3zZMxgElnO8+5SiovY5KYT8fRzL719hD2lVSYAUTxiWFrMVL+b9rRr3TJyCXQR54Vjb0YpEW UeIL9iqciXrpOPwK9oJJdDUv1M+kyE69NITOyniKWQUQPHkVCJFk6UbgrIRxRh/oHfQEXKa9UWz MD2cQrd22M8ELvw= X-Google-Smtp-Source: AGHT+IGlobew52eERJtITGZ1gfIpDVC3U51H+/o8S+NMMG7tU1CeoxEfSB264j/n7py7mlp9j93BGg== X-Received: by 2002:a17:902:f644:b0:212:1ebf:9a03 with SMTP id d9443c01a7336-2189298250bmr173874985ad.2.1734338941574; Mon, 16 Dec 2024 00:49:01 -0800 (PST) Received: from localhost.localdomain ([223.185.130.105]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e501d0sm37711495ad.116.2024.12.16.00.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 00:49:01 -0800 (PST) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar Subject: [RFC PATCH 5/8] mailbox: Add common header for RPMI messages sent via mailbox Date: Mon, 16 Dec 2024 14:18:14 +0530 Message-ID: <20241216084817.373131-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241216084817.373131-1-apatel@ventanamicro.com> References: <20241216084817.373131-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241216_004902_404548_DB60B22B X-CRM114-Status: GOOD ( 16.27 ) 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: , Cc: Anup Patel , devicetree@vger.kernel.org, Leyfoon Tan , Anup Patel , Paul Walmsley , linux-kernel@vger.kernel.org, Palmer Dabbelt , Atish Patra , linux-riscv@lists.infradead.org, Andrew Jones , linux-clk@vger.kernel.org, Rahul Pathak Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The RPMI based mailbox controller drivers and mailbox cliens need to share defines related to RPMI messages over mailbox interface so add a common header for this purpose. Co-developed-by: Rahul Pathak Signed-off-by: Rahul Pathak Signed-off-by: Anup Patel --- include/linux/mailbox/riscv-rpmi-message.h | 202 +++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 include/linux/mailbox/riscv-rpmi-message.h diff --git a/include/linux/mailbox/riscv-rpmi-message.h b/include/linux/mailbox/riscv-rpmi-message.h new file mode 100644 index 000000000000..8f4b3a0edbce --- /dev/null +++ b/include/linux/mailbox/riscv-rpmi-message.h @@ -0,0 +1,202 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024 Ventana Micro Systems Inc. + */ + +#ifndef _LINUX_RISCV_RPMI_MESSAGE_H_ +#define _LINUX_RISCV_RPMI_MESSAGE_H_ + +#include + +/** RPMI version encode/decode macros */ +#define RPMI_VER_MAJOR(__ver) (((__ver) >> 16) & 0xffff) +#define RPMI_VER_MINOR(__ver) ((__ver) & 0xffff) +#define RPMI_MKVER(__maj, __min) (((__maj) << 16) | (__min)) + +/** RPMI message header */ +struct rpmi_message_header { + __le16 servicegroup_id; + u8 service_id; + u8 flags; + __le16 datalen; + __le16 token; +}; + +/** RPMI message */ +struct rpmi_message { + struct rpmi_message_header header; + u8 data[]; +}; + +/** RPMI notification event */ +struct rpmi_notification_event { + __le16 event_datalen; + u8 event_id; + u8 reserved; + u8 event_data[]; +}; + +/** RPMI error codes */ +enum rpmi_error_codes { + RPMI_SUCCESS = 0, + RPMI_ERR_FAILED = -1, + RPMI_ERR_NOTSUPP = -2, + RPMI_ERR_INVALID_PARAM = -3, + RPMI_ERR_DENIED = -4, + RPMI_ERR_INVALID_ADDR = -5, + RPMI_ERR_ALREADY = -6, + RPMI_ERR_EXTENSION = -7, + RPMI_ERR_HW_FAULT = -8, + RPMI_ERR_BUSY = -9, + RPMI_ERR_INVALID_STATE = -10, + RPMI_ERR_BAD_RANGE = -11, + RPMI_ERR_TIMEOUT = -12, + RPMI_ERR_IO = -13, + RPMI_ERR_NO_DATA = -14, + RPMI_ERR_RESERVED_START = -15, + RPMI_ERR_RESERVED_END = -127, + RPMI_ERR_VENDOR_START = -128, +}; + +static inline int rpmi_to_linux_error(int rpmi_error) +{ + switch (rpmi_error) { + case RPMI_SUCCESS: + return 0; + case RPMI_ERR_INVALID_PARAM: + case RPMI_ERR_BAD_RANGE: + case RPMI_ERR_INVALID_STATE: + return -EINVAL; + case RPMI_ERR_DENIED: + return -EPERM; + case RPMI_ERR_INVALID_ADDR: + case RPMI_ERR_HW_FAULT: + return -EFAULT; + case RPMI_ERR_ALREADY: + return -EALREADY; + case RPMI_ERR_BUSY: + return -EBUSY; + case RPMI_ERR_TIMEOUT: + return -ETIMEDOUT; + case RPMI_ERR_IO: + return -ECOMM; + case RPMI_ERR_FAILED: + case RPMI_ERR_NOTSUPP: + case RPMI_ERR_NO_DATA: + case RPMI_ERR_EXTENSION: + default: + return -EOPNOTSUPP; + } +} + +/** RPMI linux mailbox attribute IDs */ +enum rpmi_mbox_attribute_id { + RPMI_MBOX_ATTR_SPEC_VERSION = 0, + RPMI_MBOX_ATTR_MAX_MSG_DATA_SIZE, + RPMI_MBOX_ATTR_SERVICEGROUP_ID, + RPMI_MBOX_ATTR_SERVICEGROUP_VERSION, + RPMI_MBOX_ATTR_MAX_ID, +}; + +/** RPMI linux mailbox message types */ +enum rpmi_mbox_message_type { + RPMI_MBOX_MSG_TYPE_GET_ATTRIBUTE = 0, + RPMI_MBOX_MSG_TYPE_SET_ATTRIBUTE, + RPMI_MBOX_MSG_TYPE_SEND_WITH_RESPONSE, + RPMI_MBOX_MSG_TYPE_SEND_WITHOUT_RESPONSE, + RPMI_MBOX_MSG_TYPE_NOTIFICATION_EVENT, + RPMI_MBOX_MSG_MAX_TYPE, +}; + +/** RPMI linux mailbox message instance */ +struct rpmi_mbox_message { + enum rpmi_mbox_message_type type; + union { + struct { + enum rpmi_mbox_attribute_id id; + u32 value; + } attr; + + struct { + u32 service_id; + void *request; + unsigned long request_len; + void *response; + unsigned long max_response_len; + unsigned long out_response_len; + } data; + + struct rpmi_notification_event *notif_event; + }; + int error; +}; + +/** RPMI linux mailbox message helper routines */ +static inline void rpmi_mbox_init_get_attribute(struct rpmi_mbox_message *msg, + enum rpmi_mbox_attribute_id id) +{ + msg->type = RPMI_MBOX_MSG_TYPE_GET_ATTRIBUTE; + msg->attr.id = id; + msg->attr.value = 0; + msg->error = 0; +} + +static inline void rpmi_mbox_init_set_attribute(struct rpmi_mbox_message *msg, + enum rpmi_mbox_attribute_id id, + u32 value) +{ + msg->type = RPMI_MBOX_MSG_TYPE_SET_ATTRIBUTE; + msg->attr.id = id; + msg->attr.value = value; + msg->error = 0; +} + +static inline void rpmi_mbox_init_send_with_response(struct rpmi_mbox_message *msg, + u32 service_id, + void *request, + unsigned long request_len, + void *response, + unsigned long max_response_len) +{ + msg->type = RPMI_MBOX_MSG_TYPE_SEND_WITH_RESPONSE; + msg->data.service_id = service_id; + msg->data.request = request; + msg->data.request_len = request_len; + msg->data.response = response; + msg->data.max_response_len = max_response_len; + msg->data.out_response_len = 0; + msg->error = 0; +} + +static inline void rpmi_mbox_init_send_without_response(struct rpmi_mbox_message *msg, + u32 service_id, + void *request, + unsigned long request_len) +{ + msg->type = RPMI_MBOX_MSG_TYPE_SEND_WITHOUT_RESPONSE; + msg->data.service_id = service_id; + msg->data.request = request; + msg->data.request_len = request_len; + msg->data.response = NULL; + msg->data.max_response_len = 0; + msg->data.out_response_len = 0; + msg->error = 0; +} + +static inline int rpmi_mbox_send_message(struct mbox_chan *chan, + struct rpmi_mbox_message *msg) +{ + int ret; + + /* Send message for the underlying mailbox channel */ + ret = mbox_send_message(chan, msg); + if (ret < 0) + return ret; + + /* Explicitly signal txdone for mailbox channel */ + ret = msg->error; + mbox_client_txdone(chan, ret); + return ret; +} + +#endif /* _LINUX_RISCV_RPMI_MESSAGE_H_ */ From patchwork Mon Dec 16 08:48:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13909403 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 82B45E7717F for ; Mon, 16 Dec 2024 08:49:16 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JhL122+Ko6y3X7+nuOOqD9AU/miM9CkQKROGOM9Xt0s=; b=r/Frw5YCprG7tO 32E0H5qNHv8ebwvcBy0NbjkiyMAu6lamrUHrTfaoPiw+QX+LR+uJ7EGNgCpSOVkdg/EjGhHIbofsh SE3c2ljkxADzxH1/2dpk4VCk1NXJaxZ9BU144AvuNxPbnazPcx5gGmfGVXJWaAvvkQ5FNQ/9klOIO HVe3rtBgbNP5+M2Rv4tbHi4ZKg+PTQNvYqqTtPzPer4Dvi4pazyxLpdIDVowql4/hk7xiisBorm1q yKWlDvF9YwUGxvGlJypOnidv4ibZTDP5A37I6GCg0FIerFBshtNGAXNov8Wjt4tQqICfa+uTZbJ8x 5jCsq5QO/s3GmlgV6TWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mt-00000009RTt-27N1; Mon, 16 Dec 2024 08:49:11 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mq-00000009RRa-1yHP for linux-riscv@lists.infradead.org; Mon, 16 Dec 2024 08:49:10 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-7fbbe0fb0b8so2429245a12.0 for ; Mon, 16 Dec 2024 00:49:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734338947; x=1734943747; 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=AMjLeNO0RDJyAPYTZz7J9wbtSn5q5NFjOciwarzHcf0=; b=UQqvtkVUZyVTzTbcyJo1y3Efdt8GIDzJLZRP7Cz7XM1hVSvMmWXacfQmIcng83UsDI BHVjzz+aEnw8Yaw3flLGy6sB7ZIphIMtngdbVnroaZ5UAUtEfRWDdCvb4wUnRV8PbT+N i4MfNBStI42CwOGy+6nVIKsWXd5C3MqdTGYjzKh42218+yzzOAXA5H/9w21NoID2XtVt U2Uv6+xukgqHyu4BghwBWTwszETkB0czNxJV5nReHjt+3wdtDDsdBzms/RVhkZZO0vey bA3uPCdtfQeNvIX1ibkF8u6jr+VjNBUslGtdhh6BFjdKtExIgIUB3jSyZHxgoRazDBJE /T9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734338947; x=1734943747; 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=AMjLeNO0RDJyAPYTZz7J9wbtSn5q5NFjOciwarzHcf0=; b=qmBamafKJFLQENGs3AniyoME8fEvay5scTen/wOr/cfnKwV+4hyNGmPoqSWPNcrTYI 9qB+h90CIExFPTMdhtJ8ew+Bv+NAROUQ763exPcANfpPlI0Fzav1gQjVSwTmhpq3BT4Y 5pPcj07LeezR78kR/Ivnay3m457bVa/t1KCyMakbcbvmWTCx0BEiw5to0f7Ez7WFK3oz fdx7qRJYsAow3UKqjBJ8QGxdmGmfCltOBcFW9biOxyPSuRMUDnI7s3Gyo4WwDFptdYkc +QW24qCoFE/3C7BTyWhY7oCNiv1kO80bMO43QpKaGlv/PKFOc+n/SfvWAdPvpw5hjJRS PMkA== X-Forwarded-Encrypted: i=1; AJvYcCXz/xuz744LMS8WN1E24sxQ8kamDXnjoMHcphJwLMajUq3tOSQMA/LJec3uV0R0z5fZ3jn4TnX38v6eeQ==@lists.infradead.org X-Gm-Message-State: AOJu0YxoJtW6khGka0Y6qVtvNhMryebvw2p+zw922vrbXzA7dpyhsR2e eXAgNGbKEayv76fa2L1XXzkNjMgVw2RfXZrLOvVL/lQRmx8Xsmg/dxD1AA/hjUY= X-Gm-Gg: ASbGnct3fmS1wvzFTMaeJhFjgDdZUNwghpsz8O+MmeZvciZbdy7TGPscC5JJR65NZnV zzUqhFDWE3QiU1iyGT13z9z/6PEJnEAcDDxke9ylT6i/600HLocV0feNE28eypm8CHJgtnyLFQN 6q62s8+dY2fve/qCWQ+fO9Dp+PZuv173rx5BpUtbSRP50UyBSpPl4+iVSvF28YjUjG4J+LDBdNW AIOkUsEMMPt3+Nz1kGEJLL60MIbNukCQxdD1oDWQiabz6m0wBhav0/Jf+UjMVL/kpBdv6bLt1xj iAztLm8+SLiDoU4= X-Google-Smtp-Source: AGHT+IFy6g1+S8FkHM2m+YvWZE8/BsE6ueQB8YpU5o8TllbB7weEAL1KuZyxcnKvaIU6FydS/V1JdA== X-Received: by 2002:a17:90b:2652:b0:2ee:b666:d14a with SMTP id 98e67ed59e1d1-2f28fd6a6a8mr19773837a91.17.1734338947336; Mon, 16 Dec 2024 00:49:07 -0800 (PST) Received: from localhost.localdomain ([223.185.130.105]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e501d0sm37711495ad.116.2024.12.16.00.49.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 00:49:06 -0800 (PST) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar Subject: [RFC PATCH 6/8] mailbox: Add RISC-V SBI message proxy (MPXY) based mailbox driver Date: Mon, 16 Dec 2024 14:18:15 +0530 Message-ID: <20241216084817.373131-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241216084817.373131-1-apatel@ventanamicro.com> References: <20241216084817.373131-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241216_004909_140783_B42FC115 X-CRM114-Status: GOOD ( 25.33 ) 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: , Cc: Anup Patel , devicetree@vger.kernel.org, Leyfoon Tan , Anup Patel , Paul Walmsley , linux-kernel@vger.kernel.org, Palmer Dabbelt , Atish Patra , linux-riscv@lists.infradead.org, Andrew Jones , linux-clk@vger.kernel.org, Rahul Pathak Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add a mailbox controller driver for the new SBI message proxy extension which is part of the SBI v3.0 specification. Co-developed-by: Rahul Pathak Signed-off-by: Rahul Pathak Signed-off-by: Anup Patel --- drivers/mailbox/Kconfig | 11 + drivers/mailbox/Makefile | 2 + drivers/mailbox/riscv-sbi-mpxy-mbox.c | 979 ++++++++++++++++++++++++++ 3 files changed, 992 insertions(+) create mode 100644 drivers/mailbox/riscv-sbi-mpxy-mbox.c diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index 8ecba7fb999e..5e56d8d3b52b 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -306,4 +306,15 @@ config THEAD_TH1520_MBOX kernel is running, and E902 core used for power management among other things. +config RISCV_SBI_MPXY_MBOX + tristate "RISC-V SBI Message Proxy (MPXY) Mailbox" + depends on RISCV_SBI && OF + default RISCV + help + Mailbox driver implementation for RISC-V SBI Message Proxy (MPXY) + extension. This mailbox driver is used to send messages to the + remote processor through the SBI implementation (M-mode firmware + or HS-mode hypervisor). Say Y here if you want to have this support. + If unsure say N. + endif diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index 5f4f5b0ce2cc..c17c2c7a1de5 100644 --- a/drivers/mailbox/Makefile +++ b/drivers/mailbox/Makefile @@ -66,3 +66,5 @@ obj-$(CONFIG_QCOM_CPUCP_MBOX) += qcom-cpucp-mbox.o obj-$(CONFIG_QCOM_IPCC) += qcom-ipcc.o obj-$(CONFIG_THEAD_TH1520_MBOX) += mailbox-th1520.o + +obj-$(CONFIG_RISCV_SBI_MPXY_MBOX) += riscv-sbi-mpxy-mbox.o diff --git a/drivers/mailbox/riscv-sbi-mpxy-mbox.c b/drivers/mailbox/riscv-sbi-mpxy-mbox.c new file mode 100644 index 000000000000..0592df3028f9 --- /dev/null +++ b/drivers/mailbox/riscv-sbi-mpxy-mbox.c @@ -0,0 +1,979 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * RISC-V SBI Message Proxy (MPXY) mailbox controller driver + * + * Copyright (C) 2024 Ventana Micro Systems Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* ====== SBI MPXY extension data structures ====== */ + +/* SBI MPXY MSI related channel attributes */ +struct sbi_mpxy_msi_info { + /* Lower 32-bits of the MSI target address */ + u32 msi_addr_lo; + /* Upper 32-bits of the MSI target address */ + u32 msi_addr_hi; + /* MSI data value */ + u32 msi_data; +}; + +/* + * SBI MPXY standard channel attributes. + * + * NOTE: The sequence of attribute fields are as-per the + * defined sequence in the attribute table in spec (or + * as-per the enum sbi_mpxy_attribute_id). + */ +struct sbi_mpxy_channel_attrs { + /* Message protocol ID */ + u32 msg_proto_id; + /* Message protocol Version */ + u32 msg_proto_version; + /* Message protocol maximum message length */ + u32 msg_max_len; + /* Message protocol message send timeout in microseconds */ + u32 msg_send_timeout; + /* Message protocol message completion timeout in microseconds */ + u32 msg_completion_timeout; + /* Bit array for channel capabilities */ + u32 capability; + /* SSE Event Id */ + u32 sse_event_id; + /* MSI enable/disable control knob */ + u32 msi_control; + /* Channel MSI info */ + struct sbi_mpxy_msi_info msi_info; + /* Events State Control */ + u32 events_state_ctrl; +}; + +/* + * RPMI specific SBI MPXY channel attributes. + * + * NOTE: The sequence of attribute fields are as-per the + * defined sequence in the attribute table in spec (or + * as-per the enum sbi_mpxy_rpmi_attribute_id). + */ +struct sbi_mpxy_rpmi_channel_attrs { + /* RPMI service group ID */ + u32 servicegroup_id; + /* RPMI service group version */ + u32 servicegroup_version; +}; + +/* SBI MPXY channel IDs data in shared memory */ +struct sbi_mpxy_channel_ids_data { + /* Remaining number of channel ids */ + __le32 remaining; + /* Returned channel ids in current function call */ + __le32 returned; + /* Returned channel id array */ + __le32 channel_array[]; +}; + +/* SBI MPXY notification data in shared memory */ +struct sbi_mpxy_notification_data { + /* Remaining number of notification events */ + __le32 remaining; + /* Number of notification events returned */ + __le32 returned; + /* Number of notification events lost */ + __le32 lost; + /* Reserved for future use */ + __le32 reserved; + /* Returned channel id array */ + u8 events_data[]; +}; + +/* ====== MPXY data structures & helper routines ====== */ + +/* + * Size of per-CPU MPXY shared memory + * + * Note: This must be multiple of 4096 bytes (PAGE_SIZE) + */ +#define MPXY_SHMEM_SIZE PAGE_SIZE + +/* MPXY Per-CPU or local context */ +struct mpxy_local { + /* Shared memory base address */ + void *shmem; + /* Shared memory physical address */ + phys_addr_t shmem_phys_addr; + /* Flag representing whether shared memory is active or not */ + bool shmem_active; +}; + +static DEFINE_PER_CPU(struct mpxy_local, mpxy_local); +static bool mpxy_shmem_init_done; + +static int mpxy_get_channel_count(u32 *channel_count) +{ + struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local); + struct sbi_mpxy_channel_ids_data *sdata = mpxy->shmem; + u32 remaining, returned; + struct sbiret sret; + + if (!mpxy->shmem_active) + return -ENODEV; + if (!channel_count) + return -EINVAL; + + get_cpu(); + + /* Get the remaining and returned fields to calculate total */ + sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_CHANNEL_IDS, + 0, 0, 0, 0, 0, 0); + if (!sret.error) { + remaining = le32_to_cpu(sdata->remaining); + returned = le32_to_cpu(sdata->returned); + *channel_count = remaining + returned; + } + + put_cpu(); + return sbi_err_map_linux_errno(sret.error); +} + +static int mpxy_get_channel_ids(u32 channel_count, u32 *channel_ids) +{ + u32 remaining, returned, sidx, start_index = 0, cidx = 0; + struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local); + struct sbi_mpxy_channel_ids_data *sdata = mpxy->shmem; + struct sbiret sret; + + if (!mpxy->shmem_active) + return -ENODEV; + if (!channel_count || !channel_ids) + return -EINVAL; + + get_cpu(); + + do { + sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_CHANNEL_IDS, + start_index, 0, 0, 0, 0, 0); + if (sret.error) + goto done; + + remaining = le32_to_cpu(sdata->remaining); + returned = le32_to_cpu(sdata->returned); + + for (sidx = 0; sidx < returned && cidx < channel_count; sidx++) { + channel_ids[cidx] = le32_to_cpu(sdata->channel_array[sidx]); + cidx += 1; + } + + start_index = cidx; + + } while (remaining); + +done: + put_cpu(); + return sbi_err_map_linux_errno(sret.error); +} + +static int mpxy_read_attrs(u32 channel_id, u32 base_attrid, u32 attr_count, + u32 *attrs_buf) +{ + struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local); + struct sbiret sret; + u32 i; + + if (!mpxy->shmem_active) + return -ENODEV; + if (!attr_count || !attrs_buf) + return -EINVAL; + + get_cpu(); + + sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_READ_ATTRS, + channel_id, base_attrid, attr_count, 0, 0, 0); + if (!sret.error) { + for (i = 0; i < attr_count; i++) + attrs_buf[i] = le32_to_cpu(((__le32 *)mpxy->shmem)[i]); + } + + put_cpu(); + return sbi_err_map_linux_errno(sret.error); +} + +static int mpxy_write_attrs(u32 channel_id, u32 base_attrid, u32 attr_count, + u32 *attrs_buf) +{ + struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local); + struct sbiret sret; + u32 i; + + if (!mpxy->shmem_active) + return -ENODEV; + if (!attr_count || !attrs_buf) + return -EINVAL; + + get_cpu(); + + for (i = 0; i < attr_count; i++) + ((__le32 *)mpxy->shmem)[i] = cpu_to_le32(attrs_buf[i]); + sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_WRITE_ATTRS, + channel_id, base_attrid, attr_count, 0, 0, 0); + + put_cpu(); + return sbi_err_map_linux_errno(sret.error); +} + +static int mpxy_send_message_with_resp(u32 channel_id, u32 msg_id, + void *tx, unsigned long tx_len, + void *rx, unsigned long max_rx_len, + unsigned long *rx_len) +{ + struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local); + unsigned long rx_bytes; + struct sbiret sret; + + if (!mpxy->shmem_active) + return -ENODEV; + if (!tx && tx_len) + return -EINVAL; + + get_cpu(); + + /* Message protocols allowed to have no data in messages */ + if (tx_len) + memcpy(mpxy->shmem, tx, tx_len); + + sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SEND_MSG_WITH_RESP, + channel_id, msg_id, tx_len, 0, 0, 0); + if (rx && !sret.error) { + rx_bytes = sret.value; + rx_bytes = min(max_rx_len, rx_bytes); + memcpy(rx, mpxy->shmem, rx_bytes); + if (rx_len) + *rx_len = rx_bytes; + } + + put_cpu(); + return sbi_err_map_linux_errno(sret.error); +} + +static int mpxy_send_message_without_resp(u32 channel_id, u32 msg_id, + void *tx, unsigned long tx_len) +{ + struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local); + struct sbiret sret; + + if (!mpxy->shmem_active) + return -ENODEV; + if (!tx && tx_len) + return -EINVAL; + + get_cpu(); + + /* Message protocols allowed to have no data in messages */ + if (tx_len) + memcpy(mpxy->shmem, tx, tx_len); + + sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SEND_MSG_NO_RESP, + channel_id, msg_id, tx_len, 0, 0, 0); + + put_cpu(); + return sbi_err_map_linux_errno(sret.error); +} + +static int mpxy_get_notifications(u32 channel_id, + struct sbi_mpxy_notification_data *notif_data, + unsigned long *events_data_len) +{ + struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local); + struct sbiret sret; + + if (!mpxy->shmem_active) + return -ENODEV; + if (!notif_data || !events_data_len) + return -EINVAL; + + get_cpu(); + + sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_NOTIFICATION_EVENTS, + channel_id, 0, 0, 0, 0, 0); + if (!sret.error) { + memcpy(notif_data, mpxy->shmem, sret.value); + notif_data->remaining = le32_to_cpu(notif_data->remaining); + notif_data->returned = le32_to_cpu(notif_data->returned); + notif_data->lost = le32_to_cpu(notif_data->lost); + notif_data->reserved = le32_to_cpu(notif_data->reserved); + *events_data_len = sret.value - 16; + } + + put_cpu(); + return sbi_err_map_linux_errno(sret.error); +} + +static int mpxy_cleanup_shmem(unsigned int cpu) +{ + struct mpxy_local *mpxy; + struct sbiret sret; + + mpxy = per_cpu_ptr(&mpxy_local, cpu); + if (!mpxy->shmem_active) + return -EINVAL; + + sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SET_SHMEM, + 0, -1U, -1U, 0, 0, 0); + if (sret.error) + return sbi_err_map_linux_errno(sret.error); + + free_pages((unsigned long)mpxy->shmem, get_order(MPXY_SHMEM_SIZE)); + + mpxy->shmem = NULL; + mpxy->shmem_phys_addr = 0; + mpxy->shmem_active = false; + + return 0; +} + +static int mpxy_setup_shmem(unsigned int cpu) +{ + struct page *shmem_page; + struct mpxy_local *mpxy; + struct sbiret sret; + + mpxy = per_cpu_ptr(&mpxy_local, cpu); + if (mpxy->shmem_active) + return -EINVAL; + + shmem_page = alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(MPXY_SHMEM_SIZE)); + if (!shmem_page) + return -ENOMEM; + + /* + * Linux setup of shmem is done in mpxy OVERWRITE mode. + * flags[1:0] = 00b + */ + sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SET_SHMEM, + MPXY_SHMEM_SIZE, page_to_phys(shmem_page), 0, 0, 0, 0); + if (sret.error) { + free_pages((unsigned long)page_to_virt(shmem_page), + get_order(MPXY_SHMEM_SIZE)); + return sbi_err_map_linux_errno(sret.error); + } + + mpxy->shmem = page_to_virt(shmem_page); + mpxy->shmem_phys_addr = page_to_phys(shmem_page); + mpxy->shmem_active = true; + + return 0; +} + +/* ====== MPXY mailbox data structures ====== */ + +/* MPXY mailbox channel */ +struct mpxy_mbox_channel { + struct mpxy_mbox *mbox; + u32 channel_id; + struct sbi_mpxy_channel_attrs attrs; + struct sbi_mpxy_rpmi_channel_attrs rpmi_attrs; + struct sbi_mpxy_notification_data *notif; + u32 max_xfer_len; + bool have_events_state; + u32 msi_index; + u32 msi_irq; + bool started; +}; + +/* MPXY mailbox */ +struct mpxy_mbox { + struct device *dev; + u32 channel_count; + struct mpxy_mbox_channel *channels; + u32 msi_count; + struct mpxy_mbox_channel **msi_index_to_channel; + struct mbox_controller controller; +}; + +/* ====== MPXY RPMI processing ====== */ + +static int mpxy_mbox_send_rpmi_data(struct mpxy_mbox_channel *mchan, + struct rpmi_mbox_message *msg) +{ + int rc = 0; + + switch (msg->type) { + case RPMI_MBOX_MSG_TYPE_GET_ATTRIBUTE: + switch (msg->attr.id) { + case RPMI_MBOX_ATTR_SPEC_VERSION: + msg->attr.value = mchan->attrs.msg_proto_version; + break; + case RPMI_MBOX_ATTR_MAX_MSG_DATA_SIZE: + msg->attr.value = mchan->max_xfer_len; + break; + case RPMI_MBOX_ATTR_SERVICEGROUP_ID: + msg->attr.value = mchan->rpmi_attrs.servicegroup_id; + break; + case RPMI_MBOX_ATTR_SERVICEGROUP_VERSION: + msg->attr.value = mchan->rpmi_attrs.servicegroup_version; + break; + default: + rc = -EOPNOTSUPP; + break; + } + break; + case RPMI_MBOX_MSG_TYPE_SET_ATTRIBUTE: + /* None of the RPMI linux mailbox attributes are writeable */ + rc = -EOPNOTSUPP; + break; + case RPMI_MBOX_MSG_TYPE_SEND_WITH_RESPONSE: + if ((!msg->data.request && msg->data.request_len) || + (msg->data.request && + msg->data.request_len > mchan->max_xfer_len) || + (!msg->data.response && msg->data.max_response_len)) { + rc = -EINVAL; + break; + } + if (!(mchan->attrs.capability & SBI_MPXY_CHAN_CAP_SEND_WITH_RESP)) { + rc = -EIO; + break; + } + rc = mpxy_send_message_with_resp(mchan->channel_id, + msg->data.service_id, + msg->data.request, + msg->data.request_len, + msg->data.response, + msg->data.max_response_len, + &msg->data.out_response_len); + break; + case RPMI_MBOX_MSG_TYPE_SEND_WITHOUT_RESPONSE: + if ((!msg->data.request && msg->data.request_len) || + (msg->data.request && + msg->data.request_len > mchan->max_xfer_len)) { + rc = -EINVAL; + break; + } + if (!(mchan->attrs.capability & SBI_MPXY_CHAN_CAP_SEND_WITHOUT_RESP)) { + rc = -EIO; + break; + } + rc = mpxy_send_message_without_resp(mchan->channel_id, + msg->data.service_id, + msg->data.request, + msg->data.request_len); + break; + default: + rc = -EOPNOTSUPP; + break; + } + + msg->error = rc; + return 0; +} + +static void mpxy_mbox_peek_rpmi_data(struct mbox_chan *chan, + struct mpxy_mbox_channel *mchan, + struct sbi_mpxy_notification_data *notif, + unsigned long events_data_len) +{ + struct rpmi_notification_event *event; + unsigned long pos = 0, event_size; + struct rpmi_mbox_message msg; + + while ((pos < events_data_len) && !(pos & 0x3) && + ((events_data_len - pos) <= sizeof(*event))) { + event = (struct rpmi_notification_event *)(notif->events_data + pos); + event->event_datalen = le16_to_cpu(event->event_datalen); + + event_size = sizeof(*event) + event->event_datalen; + if (event_size > (events_data_len - pos)) { + event_size = events_data_len - pos; + goto skip_event; + } + if (event_size & 0x3) + goto skip_event; + + msg.type = RPMI_MBOX_MSG_TYPE_NOTIFICATION_EVENT; + msg.notif_event = event; + msg.error = 0; + mbox_chan_received_data(chan, &msg); + +skip_event: + pos += event_size; + } +} + +static int mpxy_mbox_read_rpmi_attrs(struct mpxy_mbox_channel *mchan) +{ + return mpxy_read_attrs(mchan->channel_id, + SBI_MPXY_ATTR_MSGPROTO_ATTR_START, + sizeof(mchan->rpmi_attrs) / sizeof(u32), + (u32 *)&mchan->rpmi_attrs); +} + +/* ====== MPXY mailbox callbacks ====== */ + +static int mpxy_mbox_send_data(struct mbox_chan *chan, void *data) +{ + struct mpxy_mbox_channel *mchan = chan->con_priv; + + if (mchan->attrs.msg_proto_id == SBI_MPXY_MSGPROTO_RPMI_ID) + return mpxy_mbox_send_rpmi_data(mchan, data); + + return -EOPNOTSUPP; +} + +static bool mpxy_mbox_peek_data(struct mbox_chan *chan) +{ + struct mpxy_mbox_channel *mchan = chan->con_priv; + struct sbi_mpxy_notification_data *notif = mchan->notif; + bool have_notifications = false; + unsigned long data_len; + int rc; + + while (1) { + rc = mpxy_get_notifications(mchan->channel_id, notif, &data_len); + if (rc || !notif->returned) + break; + + if (mchan->attrs.msg_proto_id == SBI_MPXY_MSGPROTO_RPMI_ID) + mpxy_mbox_peek_rpmi_data(chan, mchan, notif, data_len); + + have_notifications = true; + } + + return have_notifications; +} + +static irqreturn_t mpxy_mbox_irq_event(int irq, void *dev_id) +{ + /* We only have MSI for notification so just wakeup IRQ thread */ + return IRQ_WAKE_THREAD; +} + +static irqreturn_t mpxy_mbox_irq_thread(int irq, void *dev_id) +{ + mpxy_mbox_peek_data(dev_id); + return IRQ_HANDLED; +} + +static int mpxy_mbox_setup_msi(struct mbox_chan *chan, + struct mpxy_mbox_channel *mchan) +{ + struct device *dev = mchan->mbox->dev; + int rc; + + /* Do nothing if MSI not supported */ + if (mchan->msi_irq == U32_MAX) + return 0; + + /* Request channel MSI handler */ + rc = request_threaded_irq(mchan->msi_irq, + mpxy_mbox_irq_event, + mpxy_mbox_irq_thread, + 0, dev_name(dev), chan); + if (rc) { + dev_err(dev, "failed to request MPXY channel 0x%x IRQ\n", + mchan->channel_id); + return rc; + } + + /* Enable channel MSI control */ + mchan->attrs.msi_control = 1; + rc = mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSI_CONTROL, + 1, &mchan->attrs.msi_control); + if (rc) { + dev_err(dev, "enable MSI control failed for MPXY channel 0x%x\n", + mchan->channel_id); + free_irq(mchan->msi_irq, chan); + return rc; + } + + return 0; +} + +static void mpxy_mbox_cleanup_msi(struct mbox_chan *chan, + struct mpxy_mbox_channel *mchan) +{ + struct device *dev = mchan->mbox->dev; + int rc; + + /* Do nothing if MSI not supported */ + if (mchan->msi_irq == U32_MAX) + return; + + /* Disable channel MSI control */ + mchan->attrs.msi_control = 0; + rc = mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSI_CONTROL, + 1, &mchan->attrs.msi_control); + if (rc) { + dev_err(dev, "disable MSI control failed for MPXY channel 0x%x\n", + mchan->channel_id); + } + + /* Free channel MSI handler */ + free_irq(mchan->msi_irq, chan); +} + +static int mpxy_mbox_setup_events(struct mpxy_mbox_channel *mchan) +{ + struct device *dev = mchan->mbox->dev; + int rc; + + /* Do nothing if events state not supported */ + if (!mchan->have_events_state) + return 0; + + /* Enable channel events state */ + mchan->attrs.events_state_ctrl = 1; + rc = mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_EVENTS_STATE_CONTROL, + 1, &mchan->attrs.events_state_ctrl); + if (rc) { + dev_err(dev, "enable events state failed for MPXY channel 0x%x\n", + mchan->channel_id); + return rc; + } + + return 0; +} + +static void mpxy_mbox_cleanup_events(struct mpxy_mbox_channel *mchan) +{ + struct device *dev = mchan->mbox->dev; + int rc; + + /* Do nothing if events state not supported */ + if (!mchan->have_events_state) + return; + + /* Disable channel events state */ + mchan->attrs.events_state_ctrl = 0; + rc = mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_EVENTS_STATE_CONTROL, + 1, &mchan->attrs.events_state_ctrl); + if (rc) { + dev_err(dev, "disbable events state failed for MPXY channel 0x%x\n", + mchan->channel_id); + } +} + +static int mpxy_mbox_startup(struct mbox_chan *chan) +{ + struct mpxy_mbox_channel *mchan = chan->con_priv; + int rc; + + if (mchan->started) + return -EALREADY; + + /* Setup channel MSI */ + rc = mpxy_mbox_setup_msi(chan, mchan); + if (rc) + return rc; + + /* Setup channel notification events */ + rc = mpxy_mbox_setup_events(mchan); + if (rc) { + mpxy_mbox_cleanup_msi(chan, mchan); + return rc; + } + + /* Mark the channel as started */ + mchan->started = true; + + return 0; +} + +static void mpxy_mbox_shutdown(struct mbox_chan *chan) +{ + struct mpxy_mbox_channel *mchan = chan->con_priv; + + if (!mchan->started) + return; + + /* Mark the channel as stopped */ + mchan->started = false; + + /* Cleanup channel notification events */ + mpxy_mbox_cleanup_events(mchan); + + /* Cleanup channel MSI */ + mpxy_mbox_cleanup_msi(chan, mchan); +} + +static const struct mbox_chan_ops mpxy_mbox_ops = { + .send_data = mpxy_mbox_send_data, + .peek_data = mpxy_mbox_peek_data, + .startup = mpxy_mbox_startup, + .shutdown = mpxy_mbox_shutdown, +}; + +/* ====== MPXY platform driver ===== */ + +static void mpxy_mbox_msi_write(struct msi_desc *desc, struct msi_msg *msg) +{ + struct device *dev = msi_desc_to_dev(desc); + struct mpxy_mbox *mbox = dev_get_drvdata(dev); + struct mpxy_mbox_channel *mchan; + struct sbi_mpxy_msi_info *minfo; + int rc; + + mchan = mbox->msi_index_to_channel[desc->msi_index]; + if (!mchan) { + dev_warn(dev, "MPXY channel not available for MSI index %d\n", + desc->msi_index); + return; + } + + minfo = &mchan->attrs.msi_info; + minfo->msi_addr_lo = msg->address_lo; + minfo->msi_addr_hi = msg->address_hi; + minfo->msi_data = msg->data; + + rc = mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSI_ADDR_LO, + sizeof(*minfo) / sizeof(u32), (u32 *)minfo); + if (rc) { + dev_warn(dev, "failed to write MSI info for MPXY channel 0x%x\n", + mchan->channel_id); + } +} + +static struct mbox_chan *mpxy_mbox_of_xlate(struct mbox_controller *ctlr, + const struct of_phandle_args *pa) +{ + struct mpxy_mbox *mbox = container_of(ctlr, struct mpxy_mbox, controller); + struct mpxy_mbox_channel *mchan; + u32 i; + + if (pa->args_count != 2) + return ERR_PTR(-EINVAL); + + for (i = 0; i < mbox->channel_count; i++) { + mchan = &mbox->channels[i]; + if (mchan->channel_id == pa->args[0] && + mchan->attrs.msg_proto_id == pa->args[1]) + return &mbox->controller.chans[i]; + } + + return ERR_PTR(-ENOENT); +} + +static int mpxy_mbox_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct mpxy_mbox_channel *mchan; + struct mpxy_mbox *mbox; + int i, msi_idx, rc; + u32 *channel_ids; + + /* + * Initialize MPXY shared memory only once. This also ensures + * that SBI MPXY mailbox is probed only once. + */ + if (mpxy_shmem_init_done) { + dev_err(dev, "SBI MPXY mailbox already initialized\n"); + return -EALREADY; + } + + /* Probe for SBI MPXY extension */ + if (sbi_spec_version < sbi_mk_version(1, 0) || + sbi_probe_extension(SBI_EXT_MPXY) <= 0) { + dev_info(dev, "SBI MPXY extension not available\n"); + return -ENODEV; + } + + /* Setup cpuhp notifier for per-CPU MPXY shared memory */ + cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "riscv/sbi-mpxy-shmem", + mpxy_setup_shmem, mpxy_cleanup_shmem); + + /* Mark as MPXY shared memory initialization done */ + mpxy_shmem_init_done = true; + + /* Allocate mailbox instance */ + mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL); + if (!mbox) + return -ENOMEM; + mbox->dev = dev; + platform_set_drvdata(pdev, mbox); + + /* Find-out of number of channels */ + rc = mpxy_get_channel_count(&mbox->channel_count); + if (rc) { + dev_err(dev, "failed to get number of MPXY channels\n"); + return rc; + } + if (!mbox->channel_count) { + dev_err(dev, "no MPXY channels available\n"); + return -ENODEV; + } + + /* Allocate and fetch all channel IDs */ + channel_ids = devm_kcalloc(dev, mbox->channel_count, + sizeof(*channel_ids), GFP_KERNEL); + if (!channel_ids) + return -ENOMEM; + rc = mpxy_get_channel_ids(mbox->channel_count, channel_ids); + if (rc) { + dev_err(dev, "failed to get number of MPXY channels\n"); + return rc; + } + + /* Populate all channels */ + mbox->channels = devm_kcalloc(dev, mbox->channel_count, + sizeof(*mbox->channels), GFP_KERNEL); + if (!mbox->channels) + return -ENOMEM; + for (i = 0; i < mbox->channel_count; i++) { + mchan = &mbox->channels[i]; + mchan->mbox = mbox; + mchan->channel_id = channel_ids[i]; + + rc = mpxy_read_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSG_PROT_ID, + sizeof(mchan->attrs) / sizeof(u32), + (u32 *)&mchan->attrs); + if (rc) { + dev_err(dev, "read attributes failed for MPXY channel 0x%x\n", + mchan->channel_id); + return rc; + } + + if (mchan->attrs.msg_proto_id == SBI_MPXY_MSGPROTO_RPMI_ID) { + rc = mpxy_mbox_read_rpmi_attrs(mchan); + if (rc) { + dev_err(dev, + "read RPMI attributes failed for MPXY channel 0x%x\n", + mchan->channel_id); + return rc; + } + } + + mchan->notif = devm_kzalloc(dev, MPXY_SHMEM_SIZE, GFP_KERNEL); + if (!mchan->notif) + return -ENOMEM; + + mchan->max_xfer_len = min(MPXY_SHMEM_SIZE, mchan->attrs.msg_max_len); + + if ((mchan->attrs.capability & SBI_MPXY_CHAN_CAP_GET_NOTIFICATIONS) && + (mchan->attrs.capability & SBI_MPXY_CHAN_CAP_EVENTS_STATE)) + mchan->have_events_state = true; + + if (mchan->have_events_state && + (mchan->attrs.capability & SBI_MPXY_CHAN_CAP_MSI)) + mchan->msi_index = mbox->msi_count++; + else + mchan->msi_index = U32_MAX; + mchan->msi_irq = U32_MAX; + } + + /* Free-up channel IDs */ + devm_kfree(dev, channel_ids); + + /* Initialize mailbox controller */ + mbox->controller.txdone_irq = false; + mbox->controller.txdone_poll = false; + mbox->controller.ops = &mpxy_mbox_ops; + mbox->controller.dev = dev; + mbox->controller.num_chans = mbox->channel_count; + mbox->controller.of_xlate = mpxy_mbox_of_xlate; + mbox->controller.chans = devm_kcalloc(dev, mbox->channel_count, + sizeof(*mbox->controller.chans), + GFP_KERNEL); + if (!mbox->controller.chans) + return -ENOMEM; + for (i = 0; i < mbox->channel_count; i++) + mbox->controller.chans[i].con_priv = &mbox->channels[i]; + + /* Set the MSI domain if not available */ + if (!dev_get_msi_domain(dev)) { + /* + * The device MSI domain for OF devices is only set at the + * time of populating/creating OF device. If the device MSI + * domain is discovered later after the OF device is created + * then we need to set it explicitly before using any platform + * MSI functions. + */ + if (is_of_node(dev->fwnode)) + of_msi_configure(dev, to_of_node(dev->fwnode)); + } + + /* Setup MSIs for mailbox (if required) */ + if (mbox->msi_count) { + mbox->msi_index_to_channel = devm_kcalloc(dev, mbox->msi_count, + sizeof(*mbox->msi_index_to_channel), + GFP_KERNEL); + if (!mbox->msi_index_to_channel) + return -ENOMEM; + + for (msi_idx = 0; msi_idx < mbox->msi_count; msi_idx++) { + for (i = 0; i < mbox->channel_count; i++) { + mchan = &mbox->channels[i]; + if (mchan->msi_index == msi_idx) { + mbox->msi_index_to_channel[msi_idx] = mchan; + break; + } + } + } + + rc = platform_device_msi_init_and_alloc_irqs(dev, mbox->msi_count, + mpxy_mbox_msi_write); + if (rc) { + dev_err(dev, "Failed to allocate %d MSIs\n", mbox->msi_count); + return rc; + } + + for (i = 0; i < mbox->channel_count; i++) { + mchan = &mbox->channels[i]; + if (mchan->msi_index == U32_MAX) + continue; + mchan->msi_irq = msi_get_virq(dev, mchan->msi_index); + } + } + + /* Register mailbox controller */ + rc = devm_mbox_controller_register(dev, &mbox->controller); + if (rc) { + dev_err(dev, "Registering SBI MPXY mailbox failed\n"); + if (mbox->msi_count) + platform_device_msi_free_irqs_all(dev); + return rc; + } + + dev_info(dev, "mailbox registered with %d channels\n", + mbox->channel_count); + return 0; +} + +static void mpxy_mbox_remove(struct platform_device *pdev) +{ + struct mpxy_mbox *mbox = platform_get_drvdata(pdev); + + if (mbox->msi_count) + platform_device_msi_free_irqs_all(mbox->dev); +} + +static const struct of_device_id mpxy_mbox_of_match[] = { + {.compatible = "riscv,sbi-mpxy-mbox", }, + {}, +}; +MODULE_DEVICE_TABLE(of, mpxy_mbox_of_match); + +static struct platform_driver mpxy_mbox_driver = { + .driver = { + .name = "riscv-sbi-mpxy-mbox", + .of_match_table = mpxy_mbox_of_match, + }, + .probe = mpxy_mbox_probe, + .remove = mpxy_mbox_remove, +}; +module_platform_driver(mpxy_mbox_driver); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Anup Patel "); +MODULE_DESCRIPTION("RISC-V SBI MPXY mailbox controller driver"); From patchwork Mon Dec 16 08:48:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13909404 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 3A1E2E7717F for ; Mon, 16 Dec 2024 08:49:21 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5yNgN21VsZieywgx7cgOIjRmCRIYzZ8bonz6vWsO99k=; b=fZZifbSZXsPrqG 4lj4PoQSHKefOFS4as7bxFlAtdPfCMnQvunIIMFGWw4D+YlTREl8AOSvcnjsyX4Sga2C7Es9+ZNv3 OFzD3UGW1im4kkXdPdUZ+3bfLlzb9tEiOogVcbwyXsGUINWqaVOpz5YHD8vbpAZjr62tiShz4XEoF b806AxNQ5WaLz4yCh2qrfFSDpP93C2dZ8nnRJGMHWjsAgDnMspVqk6yBmu6U0Fttc2e4ScgtjwPDJ Lg9sirKzZEaUKrKAv9RcBYVn/8hMg8ymSXE7sqvhCKNSiJ9EFzpXx2J+NXZEtlg+ngqcfbdd1YQIk Dc/QszzKhWuNbftUeeCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tN6my-00000009RXx-0pbY; Mon, 16 Dec 2024 08:49:16 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mv-00000009RVh-2O8G for linux-riscv@lists.infradead.org; Mon, 16 Dec 2024 08:49:14 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-21680814d42so31058935ad.2 for ; Mon, 16 Dec 2024 00:49:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734338953; x=1734943753; 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=VTD9xjQhkwZ+fm306dP2P3Gi4nTgLSlKokzAF6+8eeg=; b=luHeMQVq2LKvOw9BnyASmTDm+hVTPHOL+3AUGTqrkp0NqO7Zj2ij+KBDXaUqBVV6u4 Wfx72GffNzdleaqDXtZsuRqZuCrYZsdOkxTnb840ziVs0AVyq4SskHZ67dRmJytVIoVF Us7Zger4vpb8ViAmyq+E/cxAZJUsztLNiF5P6gMIVSsHS4dran0e4O4ZJHehe/vHqfX7 OCRQHFNUouiUm5APMEnVqFme/lCerM340v1WxNt2CVAU+3j1y9MicoCBwgQCBPz4qDoU MPOk6iavJW+uD6KRinNBBDckTg30s6yp/lDbj6F22p3k4VOAmfOFblMsTEUKSLsgAA/F YcZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734338953; x=1734943753; 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=VTD9xjQhkwZ+fm306dP2P3Gi4nTgLSlKokzAF6+8eeg=; b=ZtIhZSYA/qwLWViyMBZiJE5x1GsQupchuMlDZMVOPv8NDXoGponANXOgc/qtKb07AO dli+pQiK4yquu+BiLNqvQEfnNbpz3VGsGIIQth7jeLn23aSChuunbhxFTHa6sOzlO523 CxAOQqfHNV/kJqzwW3+wY5OGE2QRyR0JjnG4hH9If0KP1n8VJ0hVysZIVTz6R+Ux0Xap mO1nJ1U8oIhnLWanNs1RojgwEk6JL7u7glavm4s6QyozS9xfCB/SqDII3kmKz2qc+vJ4 mDb1Wx69czHlUqIX3Kb2rMrf2krz9+7b+npgOgrXyR/6RrIK/HXZuzeE3zsne2KC1ZNF ooOA== X-Forwarded-Encrypted: i=1; AJvYcCW+tDSYP2AlwRUUoofblMlOj82jkILqtb8XKUzuCiHATrej/pCV9FCGYy+0nwHGkgxgsRLvaQJPfaLdyw==@lists.infradead.org X-Gm-Message-State: AOJu0Ywz75rckkBcyczAwHuzJIGYTrUMlO2BKhoBdkUA5vfrVKk8rAkD V81y/Zqj1P37GhIsY9ipYlXSsoTI9vGwksdIGCAZ323V1f0xfzZy//v8hhL4VZo= X-Gm-Gg: ASbGnctGvEPi/nCCalGsr6oSwtjNG9eh7+jA60S/ZCwWeFe2GlNa2kkSDmpndsWhk1L UvbEmtrmQ9JPMN+LvHhkys7KDd6ULNwbcSIEFH5EY0ifsCD/w5UEWPUteAi3n/O2+nDzelTu/2Y JzuAfbqtrNvqd3pTXDVxUiFDzLX13jfcA7T62hS4hvbL/bWL2kZbFJrJc4nYYTWfCNvhD5tnEtT VLTEugJuuKn2RDSxuHVi/jZQryggi1aGIxjEeGtK2Z6NSCIjtaRjNFtELqAynonjl7ailKW87Fu CRRntB+Kex18F7A= X-Google-Smtp-Source: AGHT+IFZAXk9i2QTSa1ARsAF//7P/a/eyeUKUtrq2KyDoH6hHl6V/6vbY1bhBC88LnxU0+wlfpf9Tg== X-Received: by 2002:a17:902:db0f:b0:212:fa3:f627 with SMTP id d9443c01a7336-218929b78admr165235345ad.16.1734338952799; Mon, 16 Dec 2024 00:49:12 -0800 (PST) Received: from localhost.localdomain ([223.185.130.105]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e501d0sm37711495ad.116.2024.12.16.00.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 00:49:12 -0800 (PST) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar Subject: [RFC PATCH 7/8] dt-bindings: clock: Add bindings for RISC-V RPMI clock service group Date: Mon, 16 Dec 2024 14:18:16 +0530 Message-ID: <20241216084817.373131-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241216084817.373131-1-apatel@ventanamicro.com> References: <20241216084817.373131-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241216_004913_608372_81712028 X-CRM114-Status: GOOD ( 13.75 ) 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: , Cc: Anup Patel , devicetree@vger.kernel.org, Leyfoon Tan , Anup Patel , Paul Walmsley , linux-kernel@vger.kernel.org, Palmer Dabbelt , Atish Patra , linux-riscv@lists.infradead.org, Andrew Jones , linux-clk@vger.kernel.org, Rahul Pathak Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add device tree bindings for the clock service group defined by the RISC-V platform management interface (RPMI) specification. Signed-off-by: Anup Patel --- .../bindings/clock/riscv,rpmi-clock.yaml | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml diff --git a/Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml b/Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file mode 100644 index 000000000000..9dd98e390708 --- /dev/null +++ b/Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml @@ -0,0 +1,78 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/riscv,rpmi-clock.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: RISC-V RPMI clock service group based clock controller + +maintainers: + - Anup Patel + +description: | + The RISC-V Platform Management Interface (RPMI) [1] defines a + messaging protocol which is modular and extensible. The supervisor + software can send/receive RPMI messages via SBI MPXY extension [2] + or some dedicated supervisor-mode RPMI transport. + + The RPMI specification [1] defines clock service group for accessing + system clocks managed by a platform microcontroller. + + =========================================== + References + =========================================== + + [1] RISC-V Platform Management Interface (RPMI) + https://github.com/riscv-non-isa/riscv-rpmi/releases + + [2] RISC-V Supervisor Binary Interface (SBI) + https://github.com/riscv-non-isa/riscv-sbi-doc/releases + +properties: + compatible: + oneOf: + - description: + Intended for use by the SBI implementation in machine mode or + software in supervisor mode. + const: riscv,rpmi-clock + + - description: + Intended for use by the SBI implementation in machine mode. + const: riscv,rpmi-mpxy-clock + + mboxes: + minItems: 1 + maxItems: 1 + description: | + Mailbox channel of the underlying RPMI transport or SBI message proxy. + + riscv,sbi-mpxy-channel-id: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The SBI MPXY channel id to be used for providing RPMI access to + the supervisor software. This property is mandatory when using + riscv,rpmi-mpxy-clock compatible string. + + "#clock-cells": + const: 1 + description: + This property is mandatory when using riscv,rpmi-clock compatible string. + +required: + - compatible + - mboxes + +additionalProperties: false + +examples: + - | + mpxy_mbox: sbi-mpxy-mbox { + compatible = "riscv,sbi-mpxy-mbox"; + #mbox-cells = <2>; + }; + rpmi-clk { + compatible = "riscv,rpmi-clock"; + mboxes = <&mpxy_mbox 0x1000 0x0>; + #clock-cells = <1>; + }; +... From patchwork Mon Dec 16 08:48:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13909405 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 83751E7717F for ; Mon, 16 Dec 2024 08:49:26 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=if+YMMRd4TqoMibyZ814blVazqWW5oPr6ddiAJJYJLk=; b=VII4VYnAwviP0b 5USy65HKjxxTZleUg8twpBJ9TuA+eBaqbFMPVltPL81DKVzsv1hTUsevkS6xBW7NYwKIUMtBcgnXM sqTVA1M/cOpFPTEQTg/K2GoB56RP/5ySB+R0L6iALLHfXChGJTKnY0Jk+/ingfvfrTgYOtIauA3wW jdf2R/zUwjOVrqySehXUOFkLSL30rMr5yMOkQ4/Fl9zF/gjtS0w+pMgr1C3TO7YSYYedszlf243D+ XHb/57cy0pVLjUG8vh342YIPeKMASjL7nCbwJYXaFNzW5DV1unJrxracpkFc5kyit4zGCpd2GQlNL FOf+iSomAtbjVTzyQgcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tN6n4-00000009RcZ-09UH; Mon, 16 Dec 2024 08:49:22 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tN6n1-00000009RaA-0or9 for linux-riscv@lists.infradead.org; Mon, 16 Dec 2024 08:49:20 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-21670dce0a7so41702415ad.1 for ; Mon, 16 Dec 2024 00:49:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734338958; x=1734943758; 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=Q8G2lzEGjyvQfBOtKRNxuvBVMdlmwHVHFBZ16sXaD00=; b=mq/urbXXNtka3wAhsbeJnAkhRXbHU58c8Q10BRtuPwCwnfYUn1TQGdMHIE2wWlDEAW QGkZiTDRaO6/91c9+aV7W4RppN7XfYLXPtHThSLfvY/JPdlnFPzZgX0a9GIZlCI4DXgw 2Kw+sbFMbdfkUOyRm4ViMqDRZeIzhu7lmvhOfKbbcoMM0vYDzaoMp9SoiaPrlJmZC9cQ n09X32hKyaV6M1LTwBchz3DeMCRG5/c2QkPSg9LlFtvllRLIotljzlfsPILK8Fftgg80 VCE3We2rcNDaxKaYmJfZDMW2g6HmUi3qBSEv89KdEl0y2JoATUxsqMuzo5kP8lB4jtWR iqZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734338958; x=1734943758; 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=Q8G2lzEGjyvQfBOtKRNxuvBVMdlmwHVHFBZ16sXaD00=; b=RclWcWpftRBpbaSL3ygafbOtLefPSM1obADAsyHw2XJkFoUWtDseLT4A44suOhnRtM vk1THk4gfeQ/nmiytqNJ4YVQ+qgaJyYugAFhPyi4HESlWr8YDgUXzJheCIa92B1pfYkU eWMqLfQ1zGanilSnVgqg8p8VrVvXlaHJup/9/UuHviaCkkMMZoUAP8ZoHZcGK7bdI7KZ JNex6NKwoBreaPsFUIB1Jr3M9rN9i8kUV6Z3DSfRLAxF2AQCXigiBDWh4ZSiYor8ibWM SmrKdO+VQaGFuzRRuSusCKQyaS8InkjqP7uVjlCJL0ou5x+j5iF7IADaFQjD4+0CkRp+ MLBg== X-Forwarded-Encrypted: i=1; AJvYcCUjXfp8kkcWPmbotGI0EA6chq+LQzp3Z6m4I2gw0NQrRNKtXXaUnZn5OJkwXX1PAem6QGqAmpOf/iuiTA==@lists.infradead.org X-Gm-Message-State: AOJu0YwaJTVXajL7efDlAFSopPbiHpp5ezB0otgkqujnBJ42Of5RsH4l xKj7VuZe9bx5g7f7k/XZ7BTdc0J4b+SIbgoW60ZCHoI0619AHYpCtZtK37MKiWg= X-Gm-Gg: ASbGncufEcLoNoe1MX6sESrEKXa1MeIs5RiqEqHleOLugfGrlqivzLVOSqlsQy9qzzE mOLg9USOz/EVvrI59fWKP3GOJziYwxCzW36gBPMx8aNOXY1keaIcjFceR6K32euOG9vSl48YVRW AqaUmwtTz8uKU9lXky1eiat1JloflTS8vrMi8t0QMZ8pPrCngjQxjM/6J342s05ARGpdsFh/bkP UMzevBdoFQFVao8It6/PO1CVAFjFix+nX00pKDvTOyFwP7s8mBhWY9jaQwhd7s78p0L19LxC5cN 1S6gAw+Dt4REDbY= X-Google-Smtp-Source: AGHT+IHqn9ZmkW3LZkTPkj+m1MCblgpPi2UZ8N8AVafYCTqx9Ty092XKkAQdDnczRdakBEOnQSMMbQ== X-Received: by 2002:a17:902:ea0e:b0:216:5e6e:68cb with SMTP id d9443c01a7336-218929a1ec5mr136515605ad.16.1734338958456; Mon, 16 Dec 2024 00:49:18 -0800 (PST) Received: from localhost.localdomain ([223.185.130.105]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e501d0sm37711495ad.116.2024.12.16.00.49.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 00:49:17 -0800 (PST) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar Subject: [RFC PATCH 8/8] clk: Add clock driver for the RISC-V RPMI clock service group Date: Mon, 16 Dec 2024 14:18:17 +0530 Message-ID: <20241216084817.373131-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241216084817.373131-1-apatel@ventanamicro.com> References: <20241216084817.373131-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241216_004919_254345_56E40EA5 X-CRM114-Status: GOOD ( 21.68 ) 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: , Cc: Anup Patel , devicetree@vger.kernel.org, Leyfoon Tan , Anup Patel , Paul Walmsley , linux-kernel@vger.kernel.org, Palmer Dabbelt , Atish Patra , linux-riscv@lists.infradead.org, Andrew Jones , linux-clk@vger.kernel.org, Rahul Pathak Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Rahul Pathak The RPMI specification defines a clock service group which can be accessed via SBI MPXY extension or dedicated S-mode RPMI transport. Add mailbox client based clock driver for the RISC-V RPMI clock service group. Co-developed-by: Anup Patel Signed-off-by: Anup Patel Signed-off-by: Rahul Pathak --- drivers/clk/Kconfig | 8 + drivers/clk/Makefile | 1 + drivers/clk/clk-rpmi.c | 588 +++++++++++++++++++++ include/linux/mailbox/riscv-rpmi-message.h | 16 + 4 files changed, 613 insertions(+) create mode 100644 drivers/clk/clk-rpmi.c diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index 713573b6c86c..874cea2ab21c 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -493,6 +493,14 @@ config COMMON_CLK_SP7021 Not all features of the PLL are currently supported by the driver. +config COMMON_CLK_RPMI + tristate "Clock driver based on RISC-V RPMI" + depends on MAILBOX || COMPILE_TEST + default RISCV + help + Support for clocks based on the clock service group defined by + the RISC-V platform management interface (RPMI) specification. + source "drivers/clk/actions/Kconfig" source "drivers/clk/analogbits/Kconfig" source "drivers/clk/baikal-t1/Kconfig" diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index bf4bd45adc3a..95ef59e439bf 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -107,6 +107,7 @@ obj-$(CONFIG_COMMON_CLK_VC5) += clk-versaclock5.o obj-$(CONFIG_COMMON_CLK_VC7) += clk-versaclock7.o obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o obj-$(CONFIG_COMMON_CLK_XGENE) += clk-xgene.o +obj-$(CONFIG_COMMON_CLK_RPMI) += clk-rpmi.o # please keep this section sorted lexicographically by directory path name obj-y += actions/ diff --git a/drivers/clk/clk-rpmi.c b/drivers/clk/clk-rpmi.c new file mode 100644 index 000000000000..ed8e32527d3d --- /dev/null +++ b/drivers/clk/clk-rpmi.c @@ -0,0 +1,588 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * RISC-V MPXY Based Clock Driver + * + * Copyright (C) 2024 Ventana Micro Systems Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RPMI_CLK_MAX_NUM_RATES 16 +#define RPMI_CLK_NAME_LEN 16 + +#define GET_RATE_LO_U32(rate_u64) ((u32)rate_u64) +#define GET_RATE_HI_U32(rate_u64) ((u32)((u64)(rate_u64) >> 32)) +#define GET_RATE_U64(hi_u32, lo_u32) ((u64)(hi_u32) << 32 | (lo_u32)) + +enum rpmi_clk_config { + RPMI_CLK_DISABLE = 0, + RPMI_CLK_ENABLE = 1, +}; + +enum rpmi_clk_type { + RPMI_CLK_DISCRETE = 0, + RPMI_CLK_LINEAR = 1, + RPMI_CLK_TYPE_MAX_IDX, +}; + +struct rpmi_clk_context { + struct device *dev; + struct mbox_chan *chan; + struct mbox_client client; +}; + +union rpmi_clk_rate { + struct { + u32 lo; + u32 hi; + } discrete[RPMI_CLK_MAX_NUM_RATES]; + struct { + u32 min_lo; + u32 min_hi; + u32 max_lo; + u32 max_hi; + u32 step_lo; + u32 step_hi; + } linear; +}; + +union rpmi_clk_rates { + u64 discrete[RPMI_CLK_MAX_NUM_RATES]; + struct { + u64 min; + u64 max; + u64 step; + } linear; +}; + +struct rpmi_clk { + struct rpmi_clk_context *context; + u32 id; + u32 num_rates; + u32 transition_latency; + enum rpmi_clk_type type; + union rpmi_clk_rates *rates; + char name[RPMI_CLK_NAME_LEN]; + struct clk_hw hw; +}; + +#define to_rpmi_clk(clk) container_of(clk, struct rpmi_clk, hw) + +struct rpmi_get_num_clocks_rx { + s32 status; + u32 num_clocks; +}; + +struct rpmi_get_attrs_tx { + u32 clkid; +}; + +struct rpmi_get_attrs_rx { + s32 status; + u32 flags; + u32 num_rates; + u32 transition_latency; + char name[RPMI_CLK_NAME_LEN]; +}; + +struct rpmi_get_supp_rates_tx { + u32 clkid; + u32 clk_rate_idx; +}; + +struct rpmi_get_supp_rates_rx { + u32 status; + u32 flags; + u32 remaining; + u32 returned; + union rpmi_clk_rate rates; +}; + +struct rpmi_get_rate_tx { + u32 clkid; +}; + +struct rpmi_get_rate_rx { + u32 status; + u32 lo; + u32 hi; +}; + +struct rpmi_set_rate_tx { + u32 clkid; + u32 flags; + u32 lo; + u32 hi; +}; + +struct rpmi_set_rate_rx { + u32 status; +}; + +struct rpmi_set_config_tx { + u32 clkid; + u32 config; +}; + +struct rpmi_set_config_rx { + u32 status; +}; + +static int rpmi_clk_get_num_clocks(struct rpmi_clk_context *context) +{ + struct rpmi_get_num_clocks_rx rx; + struct rpmi_mbox_message msg; + int ret; + + rpmi_mbox_init_send_with_response(&msg, RPMI_CLK_SRV_GET_NUM_CLOCKS, + NULL, 0, &rx, sizeof(rx)); + ret = rpmi_mbox_send_message(context->chan, &msg); + if (ret) + return ret; + if (rx.status) + return rpmi_to_linux_error(rx.status); + + return rx.num_clocks; +} + +/** + * Get the RPMI Clock Attributes. + * These attributes belong to a particular clock(clkid) + * which are different from the MPXY channel attributes. + */ +static int rpmi_clk_get_attrs(u32 clkid, struct rpmi_clk *rpmi_clk) +{ + struct rpmi_clk_context *context = rpmi_clk->context; + struct rpmi_mbox_message msg; + struct rpmi_get_attrs_tx tx; + struct rpmi_get_attrs_rx rx; + u8 format; + int ret; + + tx.clkid = cpu_to_le32(clkid); + rpmi_mbox_init_send_with_response(&msg, RPMI_CLK_SRV_GET_ATTRIBUTES, + &tx, sizeof(tx), &rx, sizeof(rx)); + ret = rpmi_mbox_send_message(context->chan, &msg); + if (ret) + return ret; + if (rx.status) + return rpmi_to_linux_error(rx.status); + + rpmi_clk->id = clkid; + rpmi_clk->num_rates = rx.num_rates; + rpmi_clk->transition_latency = rx.transition_latency; + strscpy(rpmi_clk->name, rx.name, RPMI_CLK_NAME_LEN); + + format = rx.flags & 1U; + if (format >= RPMI_CLK_TYPE_MAX_IDX) + return -EINVAL; + + rpmi_clk->type = format; + + return 0; +} + +static int rpmi_clk_get_supported_rates(u32 clkid, struct rpmi_clk *rpmi_clk) +{ + struct rpmi_clk_context *context = rpmi_clk->context; + struct rpmi_get_supp_rates_tx tx; + struct rpmi_get_supp_rates_rx rx; + struct rpmi_mbox_message msg; + size_t clk_rate_idx = 0; + int ret, rateidx, j; + + tx.clkid = cpu_to_le32(clkid); + tx.clk_rate_idx = 0; + + rpmi_mbox_init_send_with_response(&msg, RPMI_CLK_SRV_GET_SUPPORTED_RATES, + &tx, sizeof(tx), &rx, sizeof(rx)); + ret = rpmi_mbox_send_message(context->chan, &msg); + if (ret) + return ret; + if (rx.status) + return rpmi_to_linux_error(rx.status); + if (!rx.returned) + return -EINVAL; + + if (rpmi_clk->type == RPMI_CLK_DISCRETE) { + for (rateidx = 0; rateidx < rx.returned; rateidx++) { + rpmi_clk->rates->discrete[rateidx] = + GET_RATE_U64(rx.rates.discrete[rateidx].hi, + rx.rates.discrete[rateidx].lo); + } + + while (rx.remaining) { + clk_rate_idx += rx.returned; + tx.clk_rate_idx = clk_rate_idx; + + rpmi_mbox_init_send_with_response(&msg, + RPMI_CLK_SRV_GET_SUPPORTED_RATES, + &tx, sizeof(tx), &rx, sizeof(rx)); + ret = rpmi_mbox_send_message(context->chan, &msg); + if (ret) + return ret; + + for (j = 0; j < rx.returned; j++) { + if (rateidx >= (clk_rate_idx + rx.returned)) + break; + rpmi_clk->rates->discrete[rateidx++] = + GET_RATE_U64(rx.rates.discrete[j].hi, + rx.rates.discrete[j].lo); + } + } + } else if (rpmi_clk->type == RPMI_CLK_LINEAR) { + rpmi_clk->rates->linear.min = + GET_RATE_U64(rx.rates.linear.min_hi, + rx.rates.linear.min_lo); + rpmi_clk->rates->linear.max = + GET_RATE_U64(rx.rates.linear.max_hi, + rx.rates.linear.max_lo); + rpmi_clk->rates->linear.step = + GET_RATE_U64(rx.rates.linear.step_hi, + rx.rates.linear.step_lo); + } + + return 0; +} + +static unsigned long rpmi_clk_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct rpmi_clk *rpmi_clk = to_rpmi_clk(hw); + struct rpmi_clk_context *context = rpmi_clk->context; + struct rpmi_mbox_message msg; + struct rpmi_get_rate_tx tx; + struct rpmi_get_rate_rx rx; + int ret; + + tx.clkid = cpu_to_le32(rpmi_clk->id); + + rpmi_mbox_init_send_with_response(&msg, RPMI_CLK_SRV_GET_RATE, + &tx, sizeof(tx), &rx, sizeof(rx)); + ret = rpmi_mbox_send_message(context->chan, &msg); + if (ret) + return ret; + if (rx.status) + return rx.status; + + return GET_RATE_U64(rx.hi, rx.lo); +} + +static long rpmi_clk_round_rate(struct clk_hw *hw, + unsigned long rate, + unsigned long *parent_rate) +{ + struct rpmi_clk *rpmi_clk = to_rpmi_clk(hw); + u64 fmin, fmax, ftmp; + + if (rpmi_clk->type == RPMI_CLK_DISCRETE) + return rate; + + fmin = rpmi_clk->rates->linear.min; + fmax = rpmi_clk->rates->linear.max; + + if (rate <= fmin) + return fmin; + else if (rate >= fmax) + return fmax; + + ftmp = rate - fmin; + ftmp += rpmi_clk->rates->linear.step - 1; + do_div(ftmp, rpmi_clk->rates->linear.step); + + return ftmp * rpmi_clk->rates->linear.step + fmin; +} + +static int rpmi_clk_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct rpmi_clk *rpmi_clk = to_rpmi_clk(hw); + struct rpmi_clk_context *context = rpmi_clk->context; + struct rpmi_mbox_message msg; + struct rpmi_set_rate_tx tx; + struct rpmi_set_rate_rx rx; + int ret; + + tx.clkid = cpu_to_le32(rpmi_clk->id); + tx.lo = cpu_to_le32(GET_RATE_LO_U32(rate)); + tx.hi = cpu_to_le32(GET_RATE_HI_U32(rate)); + + rpmi_mbox_init_send_with_response(&msg, RPMI_CLK_SRV_SET_RATE, + &tx, sizeof(tx), &rx, sizeof(rx)); + ret = rpmi_mbox_send_message(context->chan, &msg); + if (ret) + return ret; + if (rx.status) + return rpmi_to_linux_error(rx.status); + + return 0; +} + +static int rpmi_clk_enable(struct clk_hw *hw) +{ + struct rpmi_clk *rpmi_clk = to_rpmi_clk(hw); + struct rpmi_clk_context *context = rpmi_clk->context; + struct rpmi_mbox_message msg; + struct rpmi_set_config_tx tx; + struct rpmi_set_config_rx rx; + int ret; + + tx.config = cpu_to_le32(RPMI_CLK_ENABLE); + tx.clkid = cpu_to_le32(rpmi_clk->id); + + rpmi_mbox_init_send_with_response(&msg, RPMI_CLK_SRV_SET_CONFIG, + &tx, sizeof(tx), &rx, sizeof(rx)); + ret = rpmi_mbox_send_message(context->chan, &msg); + if (ret) + return ret; + if (rx.status) + return rpmi_to_linux_error(rx.status); + + return 0; +} + +static void rpmi_clk_disable(struct clk_hw *hw) +{ + struct rpmi_clk *rpmi_clk = to_rpmi_clk(hw); + struct rpmi_clk_context *context = rpmi_clk->context; + struct rpmi_mbox_message msg; + struct rpmi_set_config_tx tx; + struct rpmi_set_config_rx rx; + int ret; + + tx.config = cpu_to_le32(RPMI_CLK_DISABLE); + tx.clkid = cpu_to_le32(rpmi_clk->id); + + rpmi_mbox_init_send_with_response(&msg, RPMI_CLK_SRV_SET_CONFIG, + &tx, sizeof(tx), &rx, sizeof(rx)); + ret = rpmi_mbox_send_message(context->chan, &msg); + if (ret || rx.status) + pr_err("Failed to disable clk-%u\n", rpmi_clk->id); +} + +static const struct clk_ops rpmi_clk_ops = { + .recalc_rate = rpmi_clk_recalc_rate, + .round_rate = rpmi_clk_round_rate, + .set_rate = rpmi_clk_set_rate, + .prepare = rpmi_clk_enable, + .unprepare = rpmi_clk_disable, +}; + +static struct clk_hw *rpmi_clk_enumerate(struct rpmi_clk_context *context, u32 clkid) +{ + struct device *dev = context->dev; + unsigned long min_rate, max_rate; + union rpmi_clk_rates *rates; + struct rpmi_clk *rpmi_clk; + struct clk_init_data init; + struct clk_hw *clk_hw; + int ret; + + rates = devm_kzalloc(dev, sizeof(union rpmi_clk_rates), GFP_KERNEL); + if (!rates) + return ERR_PTR(-ENOMEM); + + rpmi_clk = devm_kzalloc(dev, sizeof(struct rpmi_clk), GFP_KERNEL); + if (!rpmi_clk) + return ERR_PTR(-ENOMEM); + rpmi_clk->context = context; + rpmi_clk->rates = rates; + + ret = rpmi_clk_get_attrs(clkid, rpmi_clk); + if (ret) { + dev_err(dev, "Failed to get clk-%u attributes\n", clkid); + return ERR_PTR(ret); + } + + ret = rpmi_clk_get_supported_rates(clkid, rpmi_clk); + if (ret) { + dev_err(dev, "Get supported rates failed for clk-%u, %d\n", + clkid, ret); + return ERR_PTR(ret); + } + + init.flags = CLK_GET_RATE_NOCACHE; + init.num_parents = 0; + init.ops = &rpmi_clk_ops; + init.name = rpmi_clk->name; + clk_hw = &rpmi_clk->hw; + clk_hw->init = &init; + + ret = devm_clk_hw_register(dev, clk_hw); + if (ret) { + dev_err(dev, "Unable to register clk-%u\n", clkid); + return ERR_PTR(ret); + } + + if (rpmi_clk->type == RPMI_CLK_DISCRETE) { + min_rate = rpmi_clk->rates->discrete[0]; + max_rate = rpmi_clk->rates->discrete[rpmi_clk->num_rates - 1]; + } else { + min_rate = rpmi_clk->rates->linear.min; + max_rate = rpmi_clk->rates->linear.max; + } + + clk_hw_set_rate_range(clk_hw, min_rate, max_rate); + + return NULL; +} + +static void rpmi_clk_receive_message(struct mbox_client *cl, void *msg) +{ + /* Nothing to do here. */ +} + +static int rpmi_clk_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct clk_hw_onecell_data *clk_data; + struct rpmi_clk_context *context; + struct rpmi_mbox_message msg; + int ret, num_clocks, i; + struct clk_hw *hw_ptr; + + /* Allocate RPMI clock context */ + context = devm_kzalloc(dev, sizeof(*context), GFP_KERNEL); + if (!context) + return -ENOMEM; + context->dev = dev; + platform_set_drvdata(pdev, context); + + /* Setup mailbox client */ + context->client.dev = context->dev; + context->client.rx_callback = rpmi_clk_receive_message; + context->client.tx_block = false; + context->client.knows_txdone = true; + context->client.tx_tout = 0; + + /* Request mailbox channel */ + context->chan = mbox_request_channel(&context->client, 0); + if (IS_ERR(context->chan)) + return PTR_ERR(context->chan); + + /* Validate RPMI specification version */ + rpmi_mbox_init_get_attribute(&msg, RPMI_MBOX_ATTR_SPEC_VERSION); + ret = rpmi_mbox_send_message(context->chan, &msg); + if (ret) { + dev_err(dev, "Failed to get spec version\n"); + goto fail_free_channel; + } + if (msg.attr.value < RPMI_MKVER(1, 0)) { + dev_err(dev, + "msg protocol version mismatch, expected 0x%x, found 0x%x\n", + RPMI_MKVER(1, 0), msg.attr.value); + ret = -EINVAL; + goto fail_free_channel; + } + + /* Validate clock service group ID */ + rpmi_mbox_init_get_attribute(&msg, RPMI_MBOX_ATTR_SERVICEGROUP_ID); + ret = rpmi_mbox_send_message(context->chan, &msg); + if (ret) { + dev_err(dev, "Failed to get service group ID\n"); + goto fail_free_channel; + } + if (msg.attr.value != RPMI_SRVGRP_CLOCK) { + dev_err(dev, + "service group match failed, expected 0x%x, found 0x%x\n", + RPMI_SRVGRP_CLOCK, msg.attr.value); + ret = -EINVAL; + goto fail_free_channel; + } + + /* Validate clock service group version */ + rpmi_mbox_init_get_attribute(&msg, RPMI_MBOX_ATTR_SERVICEGROUP_VERSION); + ret = rpmi_mbox_send_message(context->chan, &msg); + if (ret) { + dev_err(dev, "Failed to get service group version\n"); + goto fail_free_channel; + } + if (msg.attr.value < RPMI_MKVER(1, 0)) { + dev_err(dev, + "service group version failed, expected 0x%x, found 0x%x\n", + RPMI_MKVER(1, 0), msg.attr.value); + ret = -EINVAL; + goto fail_free_channel; + } + + /* Find-out number of clocks */ + num_clocks = rpmi_clk_get_num_clocks(context); + if (!num_clocks) { + dev_err(dev, "No clocks found\n"); + ret = -ENODEV; + goto fail_free_channel; + } + + /* Allocate clock data */ + clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, num_clocks), + GFP_KERNEL); + if (!clk_data) { + ret = -ENOMEM; + goto fail_free_channel; + } + clk_data->num = num_clocks; + + /* Setup clock data */ + for (i = 0; i < clk_data->num; i++) { + hw_ptr = rpmi_clk_enumerate(context, i); + if (IS_ERR(hw_ptr)) { + dev_err(dev, "failed to register clk-%d\n", i); + ret = PTR_ERR(hw_ptr); + goto fail_free_channel; + } + clk_data->hws[i] = hw_ptr; + } + + /* Register clock HW provider */ + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_data); + if (ret) { + dev_err(dev, "failed to register clock HW provider\n"); + goto fail_free_channel; + } + + dev_info(dev, "clk HW provider registered with %d clocks\n", + num_clocks); + return 0; + +fail_free_channel: + mbox_free_channel(context->chan); + return ret; +} + +static void rpmi_clk_remove(struct platform_device *pdev) +{ + struct rpmi_clk_context *context = platform_get_drvdata(pdev); + + mbox_free_channel(context->chan); +} + +static const struct of_device_id rpmi_clk_of_match[] = { + { .compatible = "riscv,rpmi-clock" }, + { }, +}; + +MODULE_DEVICE_TABLE(of, rpmi_clk_of_match); + +static struct platform_driver rpmi_clk_driver = { + .driver = { + .name = "riscv-rpmi-clock", + .of_match_table = rpmi_clk_of_match, + }, + .probe = rpmi_clk_probe, + .remove = rpmi_clk_remove, +}; +module_platform_driver(rpmi_clk_driver); + +MODULE_AUTHOR("Rahul Pathak "); +MODULE_DESCRIPTION("Clock Driver based on RPMI message protocol"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mailbox/riscv-rpmi-message.h b/include/linux/mailbox/riscv-rpmi-message.h index 8f4b3a0edbce..4e9478c4c0a3 100644 --- a/include/linux/mailbox/riscv-rpmi-message.h +++ b/include/linux/mailbox/riscv-rpmi-message.h @@ -89,6 +89,22 @@ static inline int rpmi_to_linux_error(int rpmi_error) } } +/** RPMI service group IDs */ +#define RPMI_SRVGRP_CLOCK 0x00007 + +/** RPMI clock service IDs */ +enum rpmi_clock_service_id { + RPMI_CLK_SRV_ENABLE_NOTIFICATION = 0x01, + RPMI_CLK_SRV_GET_NUM_CLOCKS = 0x02, + RPMI_CLK_SRV_GET_ATTRIBUTES = 0x03, + RPMI_CLK_SRV_GET_SUPPORTED_RATES = 0x04, + RPMI_CLK_SRV_SET_CONFIG = 0x05, + RPMI_CLK_SRV_GET_CONFIG = 0x06, + RPMI_CLK_SRV_SET_RATE = 0x07, + RPMI_CLK_SRV_GET_RATE = 0x08, + RPMI_CLK_SRV_ID_MAX_COUNT, +}; + /** RPMI linux mailbox attribute IDs */ enum rpmi_mbox_attribute_id { RPMI_MBOX_ATTR_SPEC_VERSION = 0,