Skip to contentSkip to conversation

Linux SBI MPXY and RPMI drivers

RFC PATCH Superseded Anup Patel 6 participants 41 messages Feb 3, 2025 – May 4, 2025

Subsystems (10)

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

v2 cover Linux SBI MPXY and RPMI drivers

The SBI v3.0 MPXY extension [1] and RPMI v1.0 [2] specifications are in stable state and under ARC review at the RISC-V International so as part of the RVI process we would like to receive an early feedback on the device tree bindings and mailbox drivers hence this series.

Currently, most of the RPMI and MPXY drivers are in OpenSBI whereas for Linux only has SBI MPXY mailbox controller driver, RPMI clock driver.and RPMI system MSI driver This series also includes ACPI support for SBI MPXY mailbox controller and RPMI system MSI drivers.

These patches can be found in the riscv_sbi_mpxy_mailbox_v2 branch at:
https://github.com/avpatel/linux.git

To test these patches, boot Linux on "virt,rpmi=on,aia=aplic-imsic" machine with OpenSBI and QEMU from the dev-upstream QEMU branch at:
https://github.com/ventanamicro/opensbi.git
https://github.com/ventanamicro/qemu.git

[1] https://github.com/riscv-non-isa/riscv-sbi-doc/releases
[2] https://github.com/riscv-non-isa/riscv-rpmi/releases

Changes since v1:
- Addressed DT bindings related comments in PATCH2, PATCH3, and PATCH7 of v1 series
- Addressed comments in PATCH6 and PATCH8 of v1 series
- New PATCH6 in v2 series to allow fwnode based mailbox channel request
- New PATCH10 and PATCH11 to add RPMI system MSI based interrupt controller driver
- New PATCH12 to PATCH16 which adds ACPI support in SBI MPXY mailbox driver and RPMI system MSI driver
- New PATCH17 to enable required kconfig option to allow graceful shutdown on QEMU virt machine

Anup Patel (11):
riscv: Add new error codes defined by SBI v3.0
dt-bindings: mailbox: Add bindings for RPMI shared memory transport
dt-bindings: mailbox: Add bindings for RISC-V SBI MPXY extension
RISC-V: Add defines for the SBI message proxy extension
mailbox: Add common header for RPMI messages sent via mailbox
mailbox: Allow controller specific mapping using fwnode
mailbox: Add RISC-V SBI message proxy (MPXY) based mailbox driver
dt-bindings: clock: Add bindings for RISC-V RPMI clock service group
dt-bindings: interrupt-controller: Add bindings for RISC-V RPMI system
MSI
irqchip: Add driver for the RISC-V RPMI system MSI service group
RISC-V: Enable GPIO keyboard and event device in RV64 defconfig

Rahul Pathak (1):
clk: Add clock driver for the RISC-V RPMI clock service group

Sunil V L (5):
ACPI: property: Add support for nargs_prop in
acpi_fwnode_get_reference_args()
ACPI: scan: Update honor list for RPMI System MSI
ACPI: RISC-V: Add RPMI System MSI to GSI mapping mailbox/riscv-sbi-mpxy: Add ACPI support irqchip/riscv-rpmi-sysmsi: Add ACPI support

 .../bindings/clock/riscv,rpmi-clock.yaml      |   77 ++
 .../riscv,rpmi-system-msi.yaml                |   89 ++
 .../mailbox/riscv,rpmi-shmem-mbox.yaml        |  150 +++
 .../bindings/mailbox/riscv,sbi-mpxy-mbox.yaml |   54 +
 arch/riscv/configs/defconfig                  |    2 +
 arch/riscv/include/asm/irq.h                  |    1 +
 arch/riscv/include/asm/sbi.h                  |   70 ++
 drivers/acpi/property.c                       |   15 +-
 drivers/acpi/riscv/irq.c                      |   33 +
 drivers/acpi/scan.c                           |    2 +
 drivers/clk/Kconfig                           |    8 +
 drivers/clk/Makefile                          |    1 +
 drivers/clk/clk-rpmi.c                        |  601 ++++++++++
 drivers/gpio/gpiolib-acpi.c                   |    2 +-
 drivers/irqchip/Kconfig                       |    7 +
 drivers/irqchip/Makefile                      |    1 +
 drivers/irqchip/irq-riscv-rpmi-sysmsi.c       |  315 +++++
 drivers/mailbox/Kconfig                       |   11 +
 drivers/mailbox/Makefile                      |    2 +
 drivers/mailbox/mailbox.c                     |   44 +-
 drivers/mailbox/riscv-sbi-mpxy-mbox.c         | 1027 +++++++++++++++++
 drivers/pwm/core.c                            |    2 +-
 include/linux/acpi.h                          |   12 +-
 include/linux/mailbox/riscv-rpmi-message.h    |  235 ++++
 include/linux/mailbox_controller.h            |    3 +
 25 files changed, 2737 insertions(+), 27 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml
 create mode 100644 Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml
 create mode 100644 Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml
 create mode 100644 drivers/clk/clk-rpmi.c
 create mode 100644 drivers/irqchip/irq-riscv-rpmi-sysmsi.c
 create mode 100644 drivers/mailbox/riscv-sbi-mpxy-mbox.c
 create mode 100644 include/linux/mailbox/riscv-rpmi-message.h
Signature · 1 line
2.43.0
author
#1 lore raw

RFC PATCH v2 1/17 riscv: Add new error codes defined by SBI v3.0

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.

---
 arch/riscv/include/asm/sbi.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/riscv/include/asm/sbi.h +10 -0
index 3d250824178b..972eecccfb2a 100644
@@ -419,6 +419,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 {
@@ -505,9 +509,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:
Signature · 1 line
2.43.0
author
#2 lore raw

RFC PATCH v2 2/17 dt-bindings: mailbox: Add bindings for RPMI shared memory transport

In reply to Anup Patel

Add device tree bindings for the common RISC-V Platform Management Interface (RPMI) shared memory transport as a mailbox controller.

---
 .../mailbox/riscv,rpmi-shmem-mbox.yaml        | 150 ++++++++++++++++++
 1 file changed, 150 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +150 -0
new file mode 100644
index 000000000000..c339df5d9e24
@@ -0,0 +1,150 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mailbox/riscv,rpmi-shmem-mbox.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RISC-V Platform Management Interface (RPMI) shared memory mailbox
+
+maintainers:
+  - Anup Patel <[email protected]>
+
+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: P2A request queue base address
+          - description: A2P acknowledgment queue base address
+      - items:
+          - description: A2P request queue base address
+          - description: P2A acknowledgment queue base address
+          - description: A2P doorbell address
+      - items:
+          - description: A2P request queue base address
+          - description: P2A acknowledgment queue base address
+
+  reg-names:
+    oneOf:
+      - items:
+          - const: a2p-req
+          - const: p2a-ack
+          - const: p2a-req
+          - const: a2p-ack
+          - const: doorbell
+      - items:
+          - const: a2p-req
+          - const: p2a-ack
+          - const: p2a-req
+          - const: a2p-ack
+      - items:
+          - const: a2p-req
+          - const: p2a-ack
+          - const: doorbell
+      - items:
+          - const: a2p-req
+          - const: p2a-ack
+
+  interrupts:
+    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,doorbell-mask:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 0xffffffff
+    description:
+      Update only the register bits of doorbell defined by the mask (32 bit).
+
+  riscv,doorbell-value:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 0x1
+    description:
+      Value written to the doorbell register bits (32-bit access) specified
+      by the riscv,db-mask property.
+
+  "#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 = <0x10080000 0x10000>,
+              <0x10090000 0x10000>,
+              <0x100a0000 0x4>;
+        reg-names = "a2p-req", "p2a-ack", "doorbell";
+        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 = <0x10001000 0x800>,
+              <0x10001800 0x800>,
+              <0x10002000 0x800>,
+              <0x10002800 0x800>,
+              <0x10003000 0x4>;
+        reg-names = "a2p-req", "p2a-ack", "p2a-req", "a2p-ack", "doorbell";
+        msi-parent = <&imsic_mlevel>;
+        riscv,slot-size = <64>;
+        riscv,doorbell-mask = <0x00008000>;
+        riscv,doorbell-value = <0x00008000>;
+        #mbox-cells = <1>;
+    };
Signature · 1 line
2.43.0
author
#5 lore raw

RFC PATCH v2 3/17 dt-bindings: mailbox: Add bindings for RISC-V SBI MPXY extension

In reply to Anup Patel

Add device tree bindings for the RISC-V SBI Message Proxy (MPXY) extension as a mailbox controller.

---
 .../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
Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml new file +54 -0
new file mode 100644
index 000000000000..8a05e089b710
@@ -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 <[email protected]>
+
+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>;
+    };
Signature · 1 line
2.43.0
author
#8 lore raw

RFC PATCH v2 4/17 RISC-V: Add defines for the SBI message proxy extension

In reply to Anup Patel

Add defines for the new SBI message proxy extension which is part of the SBI v3.0 specification.

---
 arch/riscv/include/asm/sbi.h | 60 ++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
arch/riscv/include/asm/sbi.h +60 -0
index 972eecccfb2a..b730b5159b97 100644
@@ -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,
@@ -402,6 +403,65 @@ 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_GET_SHMEM_SIZE,
+	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_WITHOUT_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
Signature · 1 line
2.43.0
author
#9 lore raw

RFC PATCH v2 5/17 mailbox: Add common header for RPMI messages sent via mailbox

In reply to Anup Patel

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.

---
 include/linux/mailbox/riscv-rpmi-message.h | 206 +++++++++++++++++++++
 1 file changed, 206 insertions(+)
 create mode 100644 include/linux/mailbox/riscv-rpmi-message.h
include/linux/mailbox/riscv-rpmi-message.h new file +206 -0
new file mode 100644
index 000000000000..2747a1840937
@@ -0,0 +1,206 @@
+/* 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 <linux/mailbox_client.h>
+
+/** 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 {
+			u16 event_datalen;
+			u8 event_id;
+			u8 *event_data;
+		} notif;
+	};
+	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_ */
Signature · 1 line
2.43.0
author
#10 lore raw

RFC PATCH v2 6/17 mailbox: Allow controller specific mapping using fwnode

In reply to Anup Patel

Introduce optional fw_node() callback which allows a mailbox controller driver to provide controller specific mapping using fwnode.

The Linux OF framework already implements fwnode operations for the Linux DD framework so the fw_xlate() callback works fine with device tree as well.

---
 drivers/mailbox/mailbox.c          | 44 ++++++++++++++++++------------
 include/linux/mailbox_controller.h |  3 ++
 2 files changed, 29 insertions(+), 18 deletions(-)
drivers/mailbox/mailbox.c +26 -18
index d3d26a2c9895..447edd212f0f 100644
@@ -402,20 +402,29 @@ EXPORT_SYMBOL_GPL(mbox_bind_client);
  */
 struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
 {
+	struct fwnode_reference_args fwspec;
 	struct device *dev = cl->dev;
 	struct mbox_controller *mbox;
 	struct of_phandle_args spec;
 	struct mbox_chan *chan;
 	int ret;
 
-	if (!dev || !dev->of_node) {
-		pr_debug("%s: No owner device node\n", __func__);
+	if (!dev) {
+		pr_debug("%s: No owner device\n", __func__);
 		return ERR_PTR(-ENODEV);
 	}
 
 	mutex_lock(&con_mutex);
 
-	if (of_parse_phandle_with_args(dev->of_node, "mboxes",
+	if (fwnode_property_get_reference_args(dev->fwnode, "mboxes",
+					       "#mbox-cells", 0, index, &fwspec)) {
+		dev_dbg(dev, "%s: can't parse \"mboxes\" property\n", __func__);
+		mutex_unlock(&con_mutex);
+		return ERR_PTR(-ENODEV);
+	}
+
+	if (dev->of_node &&
+	    of_parse_phandle_with_args(dev->of_node, "mboxes",
 				       "#mbox-cells", index, &spec)) {
 		dev_dbg(dev, "%s: can't parse \"mboxes\" property\n", __func__);
 		mutex_unlock(&con_mutex);
@@ -423,14 +432,20 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
 	}
 
 	chan = ERR_PTR(-EPROBE_DEFER);
-	list_for_each_entry(mbox, &mbox_cons, node)
-		if (mbox->dev->of_node == spec.np) {
+	list_for_each_entry(mbox, &mbox_cons, node) {
+		if (mbox->fw_xlate && mbox->dev->fwnode == fwspec.fwnode) {
+			chan = mbox->fw_xlate(mbox, &fwspec);
+			if (!IS_ERR(chan))
+				break;
+		} else if (mbox->of_xlate && mbox->dev->of_node == spec.np) {
 			chan = mbox->of_xlate(mbox, &spec);
 			if (!IS_ERR(chan))
 				break;
 		}
+	}
 
-	of_node_put(spec.np);
+	if (dev->of_node)
+		of_node_put(spec.np);
 
 	if (IS_ERR(chan)) {
 		mutex_unlock(&con_mutex);
@@ -449,15 +464,8 @@ EXPORT_SYMBOL_GPL(mbox_request_channel);
 struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl,
 					      const char *name)
 {
-	struct device_node *np = cl->dev->of_node;
-	int index;
-
-	if (!np) {
-		dev_err(cl->dev, "%s() currently only supports DT\n", __func__);
-		return ERR_PTR(-EINVAL);
-	}
+	int index = device_property_match_string(cl->dev, "mbox-names", name);
 
-	index = of_property_match_string(np, "mbox-names", name);
 	if (index < 0) {
 		dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n",
 			__func__, name);
@@ -495,8 +503,8 @@ void mbox_free_channel(struct mbox_chan *chan)
 EXPORT_SYMBOL_GPL(mbox_free_channel);
 
 static struct mbox_chan *
-of_mbox_index_xlate(struct mbox_controller *mbox,
-		    const struct of_phandle_args *sp)
+fw_mbox_index_xlate(struct mbox_controller *mbox,
+		    const struct fwnode_reference_args *sp)
 {
 	int ind = sp->args[0];
 
@@ -549,8 +557,8 @@ int mbox_controller_register(struct mbox_controller *mbox)
 		spin_lock_init(&chan->lock);
 	}
 
-	if (!mbox->of_xlate)
-		mbox->of_xlate = of_mbox_index_xlate;
+	if (!mbox->fw_xlate && !mbox->of_xlate)
+		mbox->fw_xlate = fw_mbox_index_xlate;
 
 	mutex_lock(&con_mutex);
 	list_add_tail(&mbox->node, &mbox_cons);
include/linux/mailbox_controller.h +3 -0
index 6fee33cb52f5..74352c244aba 100644
@@ -66,6 +66,7 @@ struct mbox_chan_ops {
  *			no interrupt rises. Ignored if 'txdone_irq' is set.
  * @txpoll_period:	If 'txdone_poll' is in effect, the API polls for
  *			last TX's status after these many millisecs
+ * @fw_xlate:		Controller driver specific mapping of channel via fwnode
  * @of_xlate:		Controller driver specific mapping of channel via DT
  * @poll_hrt:		API private. hrtimer used to poll for TXDONE on all
  *			channels.
@@ -79,6 +80,8 @@ struct mbox_controller {
 	bool txdone_irq;
 	bool txdone_poll;
 	unsigned txpoll_period;
+	struct mbox_chan *(*fw_xlate)(struct mbox_controller *mbox,
+				      const struct fwnode_reference_args *sp);
 	struct mbox_chan *(*of_xlate)(struct mbox_controller *mbox,
 				      const struct of_phandle_args *sp);
 	/* Internal to API */
Signature · 1 line
2.43.0
author
#11 lore raw

RFC PATCH v2 7/17 mailbox: Add RISC-V SBI message proxy (MPXY) based mailbox driver

In reply to Anup Patel

Add a mailbox controller driver for the new SBI message proxy extension which is part of the SBI v3.0 specification.

---
 drivers/mailbox/Kconfig               |   11 +
 drivers/mailbox/Makefile              |    2 +
 drivers/mailbox/riscv-sbi-mpxy-mbox.c | 1004 +++++++++++++++++++++++++
 3 files changed, 1017 insertions(+)
 create mode 100644 drivers/mailbox/riscv-sbi-mpxy-mbox.c
drivers/mailbox/Kconfig +11 -0
index ed52db272f4d..cc29a1a1974a 100644
@@ -330,4 +330,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
+	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
drivers/mailbox/Makefile +2 -0
index 9a1542b55539..833d72649790 100644
@@ -70,3 +70,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
drivers/mailbox/riscv-sbi-mpxy-mbox.c new file +1004 -0

1,004 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#12 lore raw

RFC PATCH v2 8/17 dt-bindings: clock: Add bindings for RISC-V RPMI clock service group

In reply to Anup Patel

Add device tree bindings for the clock service group defined by the RISC-V platform management interface (RPMI) specification.

---
 .../bindings/clock/riscv,rpmi-clock.yaml      | 77 +++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +77 -0
new file mode 100644
index 000000000000..c08491c04926
@@ -0,0 +1,77 @@
+# 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 <[email protected]>
+
+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:
+    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>;
+    };
+...
Signature · 1 line
2.43.0
author
#15 lore raw

RFC PATCH v2 9/17 clk: Add clock driver for the RISC-V RPMI clock service group

In reply to Anup Patel

From: Rahul Pathak <[email protected]>

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.

---
 drivers/clk/Kconfig                        |   8 +
 drivers/clk/Makefile                       |   1 +
 drivers/clk/clk-rpmi.c                     | 601 +++++++++++++++++++++
 include/linux/mailbox/riscv-rpmi-message.h |  16 +
 4 files changed, 626 insertions(+)
 create mode 100644 drivers/clk/clk-rpmi.c
drivers/clk/Kconfig +8 -0
index 713573b6c86c..d89308c7f75c 100644
@@ -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
+	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"
drivers/clk/Makefile +1 -0
index bf4bd45adc3a..b8588ab789c3 100644
@@ -84,6 +84,7 @@ obj-$(CONFIG_CLK_LS1028A_PLLDIG)	+= clk-plldig.o
 obj-$(CONFIG_COMMON_CLK_PWM)		+= clk-pwm.o
 obj-$(CONFIG_CLK_QORIQ)			+= clk-qoriq.o
 obj-$(CONFIG_COMMON_CLK_RK808)		+= clk-rk808.o
+obj-$(CONFIG_COMMON_CLK_RPMI)		+= clk-rpmi.o
 obj-$(CONFIG_COMMON_CLK_HI655X)		+= clk-hi655x.o
 obj-$(CONFIG_COMMON_CLK_S2MPS11)	+= clk-s2mps11.o
 obj-$(CONFIG_COMMON_CLK_SCMI)           += clk-scmi.o
drivers/clk/clk-rpmi.c new file +601 -0

601 lines not on this page · raw message

include/linux/mailbox/riscv-rpmi-message.h +16 -0
index 2747a1840937..f43d0874ad68 100644
@@ -89,6 +89,22 @@ static inline int rpmi_to_linux_error(int rpmi_error)
 	}
 }
 
+/** RPMI service group IDs */
+#define RPMI_SRVGRP_CLOCK		0x00008
+
+/** 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,
Signature · 1 line
2.43.0
author
#16 lore raw

RFC PATCH v2 10/17 dt-bindings: interrupt-controller: Add bindings for RISC-V RPMI system MSI

In reply to Anup Patel

Add device tree bindings for the system MSI service group based interrupt controller defined by the RISC-V platform management interface (RPMI) specification.

---
 .../riscv,rpmi-system-msi.yaml                | 89 +++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml new file +89 -0
new file mode 100644
index 000000000000..e6c297e66c99
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/riscv,rpmi-system-msi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RISC-V RPMI system MSI service group based interrupt controller
+
+maintainers:
+  - Anup Patel <[email protected]>
+
+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 system MSI service group which
+  allow application processors to receive MSIs upon system events
+  such as P2A doorbell, graceful shutdown/reboot request, CPU hotplug
+  event, memory hotplug event, etc from the 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
+
+allOf:
+  - $ref: /schemas/interrupt-controller.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - description:
+          Intended for use by the SBI implementation in machine mode or
+          software in supervisor mode.
+        const: riscv,rpmi-system-msi
+
+      - description:
+          Intended for use by the SBI implementation in machine mode.
+        const: riscv,rpmi-mpxy-system-msi
+
+  mboxes:
+    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-system-msi compatible string.
+
+  msi-parent: true
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 1
+
+required:
+  - compatible
+  - mboxes
+  - msi-parent
+  - interrupt-controller
+  - "#interrupt-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    mpxy_mbox: sbi-mpxy-mbox {
+          compatible = "riscv,sbi-mpxy-mbox";
+          #mbox-cells = <2>;
+    };
+    rpmi_sysmsi_intc: interrupt-controller {
+        compatible = "riscv,rpmi-system-msi";
+        mboxes = <&mpxy_mbox 0x2000 0x0>;
+        msi-parent = <&imsic_slevel>;
+        interrupt-controller;
+        #interrupt-cells = <1>;
+    };
+...
Signature · 1 line
2.43.0
author
#19 lore raw

RFC PATCH v2 11/17 irqchip: Add driver for the RISC-V RPMI system MSI service group

In reply to Anup Patel

The RPMI specification defines a system MSI service group which allows application processors to receive MSIs upon system events such as graceful shutdown/reboot request, CPU hotplug event, memory hotplug event, etc.

Add an irqchip driver for the RISC-V RPMI system MSI service group to directly receive system MSIs in Linux kernel.

---
 drivers/irqchip/Kconfig                    |   7 +
 drivers/irqchip/Makefile                   |   1 +
 drivers/irqchip/irq-riscv-rpmi-sysmsi.c    | 283 +++++++++++++++++++++
 include/linux/mailbox/riscv-rpmi-message.h |  13 +
 4 files changed, 304 insertions(+)
 create mode 100644 drivers/irqchip/irq-riscv-rpmi-sysmsi.c
drivers/irqchip/Kconfig +7 -0
index be063bfb50c4..2ae44354735b 100644
@@ -597,6 +597,13 @@ config RISCV_IMSIC_PCI
 	depends on PCI_MSI
 	default RISCV_IMSIC
 
+config RISCV_RPMI_SYSMSI
+	bool
+	depends on MAILBOX
+	select IRQ_DOMAIN_HIERARCHY
+	select GENERIC_MSI_IRQ
+	default RISCV
+
 config SIFIVE_PLIC
 	bool
 	depends on RISCV
drivers/irqchip/Makefile +1 -0
index 25e9ad29b8c4..7164aae58b47 100644
@@ -101,6 +101,7 @@ obj-$(CONFIG_RISCV_INTC)		+= irq-riscv-intc.o
 obj-$(CONFIG_RISCV_APLIC)		+= irq-riscv-aplic-main.o irq-riscv-aplic-direct.o
 obj-$(CONFIG_RISCV_APLIC_MSI)		+= irq-riscv-aplic-msi.o
 obj-$(CONFIG_RISCV_IMSIC)		+= irq-riscv-imsic-state.o irq-riscv-imsic-early.o irq-riscv-imsic-platform.o
+obj-$(CONFIG_RISCV_RPMI_SYSMSI)		+= irq-riscv-rpmi-sysmsi.o
 obj-$(CONFIG_SIFIVE_PLIC)		+= irq-sifive-plic.o
 obj-$(CONFIG_STARFIVE_JH8100_INTC)	+= irq-starfive-jh8100-intc.o
 obj-$(CONFIG_THEAD_C900_ACLINT_SSWI)	+= irq-thead-c900-aclint-sswi.o
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +283 -0

283 lines not on this page · raw message

include/linux/mailbox/riscv-rpmi-message.h +13 -0
index f43d0874ad68..9bf3f20c5e70 100644
@@ -90,6 +90,7 @@ static inline int rpmi_to_linux_error(int rpmi_error)
 }
 
 /** RPMI service group IDs */
+#define RPMI_SRVGRP_SYSTEM_MSI		0x00002
 #define RPMI_SRVGRP_CLOCK		0x00008
 
 /** RPMI clock service IDs */
@@ -105,6 +106,18 @@ enum rpmi_clock_service_id {
 	RPMI_CLK_SRV_ID_MAX_COUNT,
 };
 
+/** RPMI system MSI service IDs */
+enum rpmi_sysmsi_service_id {
+	RPMI_SYSMSI_SRV_ENABLE_NOTIFICATION = 0x01,
+	RPMI_SYSMSI_SRV_GET_ATTRIBUTES = 0x2,
+	RPMI_SYSMSI_SRV_GET_MSI_ATTRIBUTES = 0x3,
+	RPMI_SYSMSI_SRV_SET_MSI_STATE = 0x4,
+	RPMI_SYSMSI_SRV_GET_MSI_STATE = 0x5,
+	RPMI_SYSMSI_SRV_SET_MSI_TARGET = 0x6,
+	RPMI_SYSMSI_SRV_GET_MSI_TARGET = 0x7,
+	RPMI_SYSMSI_SRV_ID_MAX_COUNT,
+};
+
 /** RPMI linux mailbox attribute IDs */
 enum rpmi_mbox_attribute_id {
 	RPMI_MBOX_ATTR_SPEC_VERSION = 0,
Signature · 1 line
2.43.0
author
#22 lore raw

RFC PATCH v2 12/17 ACPI: property: Add support for nargs_prop in acpi_fwnode_get_reference_args()

In reply to Anup Patel

From: Sunil V L <[email protected]>

fwnode_get_reference_args() which is common for both DT and ACPI passes a property name like #mbox-cells which needs to be fetched from the reference node to determine the number of arguments needed for the property. However, the ACPI version of this function doesn't support this and simply ignores the parameter passed from the wrapper function. Add support for dynamically finding number of arguments by reading the nargs property value. Update the callers to pass extra parameter.

---
 drivers/acpi/property.c     | 15 +++++++++++++--
 drivers/gpio/gpiolib-acpi.c |  2 +-
 drivers/pwm/core.c          |  2 +-
 include/linux/acpi.h        | 12 +++++++-----
 4 files changed, 22 insertions(+), 9 deletions(-)
drivers/acpi/property.c +13 -2
index 98d93ed58315..ddea5dec70bd 100644
@@ -887,6 +887,9 @@ static struct fwnode_handle *acpi_parse_string_ref(const struct fwnode_handle *f
  * @fwnode: Firmware node to get the property from
  * @propname: Name of the property
  * @index: Index of the reference to return
+ * @nargs_prop:	The name of the property telling the number of arguments
+ *		in the referred node. NULL if @num_args is known, otherwise
+ *		@num_args is ignored.
  * @num_args: Maximum number of arguments after each reference
  * @args: Location to store the returned reference with optional arguments
  *	  (may be NULL)
@@ -919,13 +922,14 @@ static struct fwnode_handle *acpi_parse_string_ref(const struct fwnode_handle *f
  * Return: %0 on success, negative error code on failure.
  */
 int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
-	const char *propname, size_t index, size_t num_args,
+	const char *propname, size_t index, const char *nargs_prop, size_t num_args,
 	struct fwnode_reference_args *args)
 {
 	const union acpi_object *element, *end;
 	const union acpi_object *obj;
 	const struct acpi_device_data *data;
 	struct fwnode_handle *ref_fwnode;
+	struct acpi_device *ref_adev;
 	struct acpi_device *device;
 	int ret, idx = 0;
 
@@ -1012,6 +1016,13 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
 							   element->string.pointer);
 			if (!ref_fwnode)
 				return -EINVAL;
+			if (nargs_prop) {
+				ref_adev = to_acpi_device_node(ref_fwnode);
+				if (!acpi_dev_get_property(ref_adev, nargs_prop,
+							   ACPI_TYPE_INTEGER, &obj)) {
+					num_args = obj->integer.value;
+				}
+			}
 
 			element++;
 
@@ -1565,7 +1576,7 @@ acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
 			       struct fwnode_reference_args *args)
 {
 	return __acpi_node_get_property_reference(fwnode, prop, index,
-						  args_count, args);
+						  nargs_prop, args_count, args);
 }
 
 static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode)
drivers/gpio/gpiolib-acpi.c +1 -1
index 1f9fe50bba00..de8e4d081539 100644
@@ -839,7 +839,7 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode,
 	int ret;
 
 	memset(&args, 0, sizeof(args));
-	ret = __acpi_node_get_property_reference(fwnode, propname, index, 3,
+	ret = __acpi_node_get_property_reference(fwnode, propname, index, NULL, 3,
 						 &args);
 	if (ret) {
 		struct acpi_device *adev;
drivers/pwm/core.c +1 -1
index ccd54c089bab..7afd78061e6e 100644
@@ -1790,7 +1790,7 @@ static struct pwm_device *acpi_pwm_get(const struct fwnode_handle *fwnode)
 
 	memset(&args, 0, sizeof(args));
 
-	ret = __acpi_node_get_property_reference(fwnode, "pwms", 0, 3, &args);
+	ret = __acpi_node_get_property_reference(fwnode, "pwms", 0, NULL, 3, &args);
 	if (ret < 0)
 		return ERR_PTR(ret);
 
include/linux/acpi.h +7 -5
index 4e495b29c640..b9fd3c812e1f 100644
@@ -1296,8 +1296,9 @@ static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
 int acpi_dev_get_property(const struct acpi_device *adev, const char *name,
 			  acpi_object_type type, const union acpi_object **obj);
 int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
-				const char *name, size_t index, size_t num_args,
-				struct fwnode_reference_args *args);
+				       const char *name, size_t index,
+				       const char *nargs_prop, size_t num_args,
+				       struct fwnode_reference_args *args);
 
 static inline int acpi_node_get_property_reference(
 				const struct fwnode_handle *fwnode,
@@ -1305,7 +1306,7 @@ static inline int acpi_node_get_property_reference(
 				struct fwnode_reference_args *args)
 {
 	return __acpi_node_get_property_reference(fwnode, name, index,
-		NR_FWNODE_REFERENCE_ARGS, args);
+		NULL, NR_FWNODE_REFERENCE_ARGS, args);
 }
 
 static inline bool acpi_dev_has_props(const struct acpi_device *adev)
@@ -1400,8 +1401,9 @@ static inline int acpi_dev_get_property(struct acpi_device *adev,
 
 static inline int
 __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
-				const char *name, size_t index, size_t num_args,
-				struct fwnode_reference_args *args)
+				   const char *name, size_t index,
+				   const char *nargs_prop, size_t num_args,
+				   struct fwnode_reference_args *args)
 {
 	return -ENXIO;
 }
Signature · 1 line
2.43.0
author
#32 lore raw

RFC PATCH v2 13/17 ACPI: scan: Update honor list for RPMI System MSI

In reply to Anup Patel

From: Sunil V L <[email protected]>

The RPMI System MSI interrupt controller (just like PLIC and APLIC) needs to probed prior to devices like GED which use interrupts provided by it. Also, it has dependency on the SBI MPXY mailbox device.

Add HIDs of RPMI System MSI and SBI MPXY mailbox devices to the honor list so that those dependencies are handled.

---
 drivers/acpi/scan.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/scan.c +2 -0
index 9f4efa8f75a6..e490b4160612 100644
@@ -858,6 +858,8 @@ static const char * const acpi_honor_dep_ids[] = {
 	"INTC10CF", /* IVSC (MTL) driver must be loaded to allow i2c access to camera sensors */
 	"RSCV0001", /* RISC-V PLIC */
 	"RSCV0002", /* RISC-V APLIC */
+	"RSCV0005", /* RISC-V SBI MPXY MBOX */
+	"RSCV0006", /* RISC-V RPMI SYSMSI */
 	"PNP0C0F",  /* PCI Link Device */
 	NULL
 };
Signature · 1 line
2.43.0
author
#33 lore raw

RFC PATCH v2 14/17 ACPI: RISC-V: Add RPMI System MSI to GSI mapping

In reply to Anup Patel

From: Sunil V L <[email protected]>

The RPMI System MSI device will provide GSIs to downstream devices (such as GED) so add it to the RISC-V GSI to fwnode mapping.

---
 arch/riscv/include/asm/irq.h |  1 +
 drivers/acpi/riscv/irq.c     | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
arch/riscv/include/asm/irq.h +1 -0
index 7b038f3b7cb0..144f97189112 100644
@@ -30,6 +30,7 @@ enum riscv_irqchip_type {
 	ACPI_RISCV_IRQCHIP_IMSIC	= 0x01,
 	ACPI_RISCV_IRQCHIP_PLIC		= 0x02,
 	ACPI_RISCV_IRQCHIP_APLIC	= 0x03,
+	ACPI_RISCV_IRQCHIP_SMSI		= 0x04,
 };
 
 int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base,
drivers/acpi/riscv/irq.c +33 -0
index cced960c2aef..c141975c62b3 100644
@@ -129,6 +129,36 @@ static int __init riscv_acpi_register_ext_intc(u32 gsi_base, u32 nr_irqs, u32 nr
 	return 0;
 }
 
+static acpi_status __init riscv_acpi_create_gsi_map_smsi(acpi_handle handle, u32 level,
+							 void *context, void **return_value)
+{
+	acpi_status status;
+	u64 gbase;
+
+	if (!acpi_has_method(handle, "_GSB")) {
+		acpi_handle_err(handle, "_GSB method not found\n");
+		return AE_ERROR;
+	}
+
+	status = acpi_evaluate_integer(handle, "_GSB", NULL, &gbase);
+	if (ACPI_FAILURE(status)) {
+		acpi_handle_err(handle, "failed to evaluate _GSB method\n");
+		return status;
+	}
+
+	/*
+	 * TODO - find out number of interrupts from ACPI method
+	 */
+	riscv_acpi_register_ext_intc(gbase, 4, 0, 0, ACPI_RISCV_IRQCHIP_SMSI);
+	status = riscv_acpi_update_gsi_handle((u32)gbase, handle);
+	if (ACPI_FAILURE(status)) {
+		acpi_handle_err(handle, "failed to find the GSI mapping entry\n");
+		return status;
+	}
+
+	return AE_OK;
+}
+
 static acpi_status __init riscv_acpi_create_gsi_map(acpi_handle handle, u32 level,
 						    void *context, void **return_value)
 {
@@ -183,6 +213,9 @@ void __init riscv_acpi_init_gsi_mapping(void)
 
 	if (acpi_table_parse_madt(ACPI_MADT_TYPE_APLIC, riscv_acpi_aplic_parse_madt, 0) > 0)
 		acpi_get_devices("RSCV0002", riscv_acpi_create_gsi_map, NULL, NULL);
+
+	/* Unlike PLIC/APLIC, SYSMSI doesn't have MADT */
+	acpi_get_devices("RSCV0006", riscv_acpi_create_gsi_map_smsi, NULL, NULL);
 }
 
 static acpi_handle riscv_acpi_get_gsi_handle(u32 gsi)
Signature · 1 line
2.43.0
author
#34 lore raw

RFC PATCH v2 15/17 mailbox/riscv-sbi-mpxy: Add ACPI support

In reply to Anup Patel

From: Sunil V L <[email protected]>

Add ACPI support for the RISC-V SBI message proxy (MPXY) based mailbox driver.

---
 drivers/mailbox/riscv-sbi-mpxy-mbox.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/mailbox/riscv-sbi-mpxy-mbox.c +24 -1
index 4021f62ff487..0ce89970c5bd 100644
@@ -5,6 +5,7 @@
  * Copyright (C) 2024 Ventana Micro Systems Inc.
  */
 
+#include <linux/acpi.h>
 #include <asm/sbi.h>
 #include <linux/cpu.h>
 #include <linux/err.h>
@@ -12,6 +13,7 @@
 #include <linux/jump_label.h>
 #include <linux/kernel.h>
 #include <linux/mailbox_controller.h>
+#include <linux/irqchip/riscv-imsic.h>
 #include <linux/mailbox/riscv-rpmi-message.h>
 #include <linux/mm.h>
 #include <linux/module.h>
@@ -924,8 +926,16 @@ static int mpxy_mbox_probe(struct platform_device *pdev)
 		 * then we need to set it explicitly before using any platform
 		 * MSI functions.
 		 */
-		if (is_of_node(dev->fwnode))
+		if (is_of_node(dev->fwnode)) {
 			of_msi_configure(dev, to_of_node(dev->fwnode));
+		} else {
+			struct irq_domain *msi_domain;
+
+			msi_domain = irq_find_matching_fwnode(imsic_acpi_get_fwnode(dev),
+							      DOMAIN_BUS_PLATFORM_MSI);
+			if (msi_domain)
+				dev_set_msi_domain(dev, msi_domain);
+		}
 	}
 
 	/* Setup MSIs for mailbox (if required) */
@@ -970,6 +980,10 @@ static int mpxy_mbox_probe(struct platform_device *pdev)
 		return rc;
 	}
 
+#ifdef CONFIG_ACPI
+	if (!acpi_disabled)
+		acpi_dev_clear_dependencies(ACPI_COMPANION(dev));
+#endif
 	dev_info(dev, "mailbox registered with %d channels\n",
 		 mbox->channel_count);
 	return 0;
@@ -989,10 +1003,19 @@ static const struct of_device_id mpxy_mbox_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, mpxy_mbox_of_match);
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id mpxy_mbox_acpi_match[] = {
+	{ "RSCV0005", 0 },
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, mpxy_mbox_acpi_match);
+#endif
+
 static struct platform_driver mpxy_mbox_driver = {
 	.driver = {
 		.name = "riscv-sbi-mpxy-mbox",
 		.of_match_table = mpxy_mbox_of_match,
+		.acpi_match_table = ACPI_PTR(mpxy_mbox_acpi_match),
 	},
 	.probe = mpxy_mbox_probe,
 	.remove = mpxy_mbox_remove,
Signature · 1 line
2.43.0
author
#36 lore raw

RFC PATCH v2 16/17 irqchip/riscv-rpmi-sysmsi: Add ACPI support

In reply to Anup Patel

From: Sunil V L <[email protected]>

Add ACPI support for the RISC-V RPMI system MSI based irqchip driver.

---
 drivers/irqchip/Kconfig                 |  2 +-
 drivers/irqchip/irq-riscv-rpmi-sysmsi.c | 34 ++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)
drivers/irqchip/Kconfig +1 -1
index 2ae44354735b..cf96382113ce 100644
@@ -599,7 +599,7 @@ config RISCV_IMSIC_PCI
 
 config RISCV_RPMI_SYSMSI
 	bool
-	depends on MAILBOX
+	depends on RISCV && MAILBOX
 	select IRQ_DOMAIN_HIERARCHY
 	select GENERIC_MSI_IRQ
 	default RISCV
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +33 -1
index 3022f0924c94..1f03241920bb 100644
@@ -8,6 +8,7 @@
 #include <linux/cpu.h>
 #include <linux/interrupt.h>
 #include <linux/irqchip.h>
+#include <linux/irqchip/riscv-imsic.h>
 #include <linux/mailbox_client.h>
 #include <linux/mailbox/riscv-rpmi-message.h>
 #include <linux/module.h>
@@ -215,6 +216,7 @@ static int rpmi_sysmsi_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct rpmi_sysmsi_priv *priv;
+	u32 id;
 	int rc;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -223,6 +225,15 @@ static int rpmi_sysmsi_probe(struct platform_device *pdev)
 	priv->dev = dev;
 	platform_set_drvdata(pdev, priv);
 
+	if (!is_of_node(dev->fwnode)) {
+		rc = riscv_acpi_get_gsi_info(dev->fwnode, &priv->gsi_base, &id,
+					     &priv->nr_irqs, NULL);
+		if (rc) {
+			dev_err(dev, "failed to find GSI mapping\n");
+			return rc;
+		}
+	}
+
 	/* Setup mailbox client */
 	priv->client.dev		= priv->dev;
 	priv->client.rx_callback	= NULL;
@@ -252,8 +263,16 @@ static int rpmi_sysmsi_probe(struct platform_device *pdev)
 		 * then we need to set it explicitly before using any platform
 		 * MSI functions.
 		 */
-		if (is_of_node(dev->fwnode))
+		if (is_of_node(dev->fwnode)) {
 			of_msi_configure(dev, to_of_node(dev->fwnode));
+		} else {
+			struct irq_domain *msi_domain;
+
+			msi_domain = irq_find_matching_fwnode(imsic_acpi_get_fwnode(dev),
+							      DOMAIN_BUS_PLATFORM_MSI);
+			if (msi_domain)
+				dev_set_msi_domain(dev, msi_domain);
+		}
 
 		if (!dev_get_msi_domain(dev))
 			return -EPROBE_DEFER;
@@ -264,6 +283,10 @@ static int rpmi_sysmsi_probe(struct platform_device *pdev)
 					  priv->nr_irqs, priv, priv))
 		return dev_err_probe(dev, -ENOMEM, "failed to create MSI irq domain\n");
 
+#ifdef CONFIG_ACPI
+	if (!acpi_disabled)
+		acpi_dev_clear_dependencies(ACPI_COMPANION(dev));
+#endif
 	dev_info(dev, "%d system MSIs registered\n", priv->nr_irqs);
 	return 0;
 }
@@ -273,10 +296,19 @@ static const struct of_device_id rpmi_sysmsi_match[] = {
 	{}
 };
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id acpi_rpmi_sysmsi_match[] = {
+	{ "RSCV0006", 0 },
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, acpi_rpmi_sysmsi_match);
+#endif
+
 static struct platform_driver rpmi_sysmsi_driver = {
 	.driver = {
 		.name		= "rpmi-sysmsi",
 		.of_match_table	= rpmi_sysmsi_match,
+		.acpi_match_table	= ACPI_PTR(acpi_rpmi_sysmsi_match),
 	},
 	.probe = rpmi_sysmsi_probe,
 };
Signature · 1 line
2.43.0
author
#40 lore raw

RFC PATCH v2 17/17 RISC-V: Enable GPIO keyboard and event device in RV64 defconfig

In reply to Anup Patel

The GPIO keyboard and event device can be used to receive graceful shutdown or reboot input keys so let us enable it by default for RV64 (just like ARM64).

---
 arch/riscv/configs/defconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/riscv/configs/defconfig +2 -0
index 0f7dcbe3c45b..06265b6febba 100644
@@ -142,6 +142,8 @@ CONFIG_MICREL_PHY=y
 CONFIG_MICROSEMI_PHY=y
 CONFIG_MOTORCOMM_PHY=y
 CONFIG_INPUT_MOUSEDEV=y
+CONFIG_INPUT_EVDEV=y
+CONFIG_KEYBOARD_GPIO=y
 CONFIG_KEYBOARD_SUN4I_LRADC=m
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
Signature · 1 line
2.43.0
#37 lore raw

Re: [RFC PATCH v2 16/17] irqchip/riscv-rpmi-sysmsi: Add ACPI support

In reply to Anup Patel
Quoted 3 lines · Anup Patel

From: Sunil V L <[email protected]>

Add ACPI support for the RISC-V RPMI system MSI based irqchip driver.

...

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 228

Quoted 1 line
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +1 -0
+	if (!is_of_node(dev->fwnode)) {

Please, use dev_fwnode(),

But why do you need this? Can't the below simply become a no-op without this check?

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 229

Quoted 1 line
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +1 -0
+		rc = riscv_acpi_get_gsi_info(dev->fwnode, &priv->gsi_base, &id,

Ditto.

Quoted 6 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +6 -0
+					     &priv->nr_irqs, NULL);
+		if (rc) {
+			dev_err(dev, "failed to find GSI mapping\n");
+			return rc;
+		}
+	}

...

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev)

Quoted 13 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +7 -1
 		 * then we need to set it explicitly before using any platform
 		 * MSI functions.
 		 */
-		if (is_of_node(dev->fwnode))
+		if (is_of_node(dev->fwnode)) {
 			of_msi_configure(dev, to_of_node(dev->fwnode));
+		} else {
+			struct irq_domain *msi_domain;
+
+			msi_domain = irq_find_matching_fwnode(imsic_acpi_get_fwnode(dev),
+							      DOMAIN_BUS_PLATFORM_MSI);
 
+			if (msi_domain)

Hmm... The OF case above assumes this check is not needed. Why is it special otherwise?

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 277

Quoted 4 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +2 -0
+				dev_set_msi_domain(dev, msi_domain);
+		}
 
 		if (!dev_get_msi_domain(dev))

Even here you have a check for NULL, so I believe the conditional is simply redundant.

...

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 287

Quoted 3 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +2 -0
+#ifdef CONFIG_ACPI
 
+	if (!acpi_disabled)

Why?

Quoted 2 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +2 -0
+		acpi_dev_clear_dependencies(ACPI_COMPANION(dev));
+#endif

...

Quoted 1 line

+#ifdef CONFIG_ACPI

Drop this ugly ifdeffery along with ACPI_PTR(). They are more harmful than useful.

...

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static const struct of_device_id rpmi_sysmsi_match[] = { · line 301

Quoted 2 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +2 -0
+static const struct acpi_device_id acpi_rpmi_sysmsi_match[] = {
+	{ "RSCV0006", 0 },

Drop ', 0' part as it may be converted to a pointer in the future.

Quoted 4 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +4 -0
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, acpi_rpmi_sysmsi_match);
+#endif
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#23 lore raw

Re: [RFC PATCH v2 12/17] ACPI: property: Add support for nargs_prop in acpi_fwnode_get_reference_args()

In reply to Anup Patel
Quoted 9 lines · Anup Patel

From: Sunil V L <[email protected]>

fwnode_get_reference_args() which is common for both DT and ACPI passes a property name like #mbox-cells which needs to be fetched from the reference node to determine the number of arguments needed for the property. However, the ACPI version of this function doesn't support this and simply ignores the parameter passed from the wrapper function. Add support for dynamically finding number of arguments by reading the nargs property value. Update the callers to pass extra parameter.

I don't like this (implementation).

It seems that we basically have two parameters which values are duplicating each other. This is error prone API and confusing in the cases when both are defined. If you want property, add a new API that takes const char *nargs and relies on the property be present.

Your patch becomes much simpler, and solution is robust against potential confusion on how to treat the corner cases.

Note, Rafael might have different opinion and his has the last word. But here just my view on the implementation details.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#35 lore raw

Re: [RFC PATCH v2 15/17] mailbox/riscv-sbi-mpxy: Add ACPI support

In reply to Anup Patel
Quoted 4 lines · Anup Patel

From: Sunil V L <[email protected]>

Add ACPI support for the RISC-V SBI message proxy (MPXY) based mailbox driver.

Ah, here are the same comments are applicable as per patch 16. Haven't noticed there are two similarly looking changes.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#24 lore raw

Re: [RFC PATCH v2 12/17] ACPI: property: Add support for nargs_prop in acpi_fwnode_get_reference_args()

In reply to Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Anup Patel

From: Sunil V L <[email protected]>

fwnode_get_reference_args() which is common for both DT and ACPI passes a property name like #mbox-cells which needs to be fetched from the reference node to determine the number of arguments needed for the property. However, the ACPI version of this function doesn't support this and simply ignores the parameter passed from the wrapper function. Add support for dynamically finding number of arguments by reading the nargs property value. Update the callers to pass extra parameter.

Quoted 1 line

I don't like this (implementation).

Agree.

Quoted 4 lines

It seems that we basically have two parameters which values are duplicating each other. This is error prone API and confusing in the cases when both are defined. If you want property, add a new API that takes const char *nargs and relies on the property be present.

Also this is not really needed for ACPI case because it has types so it can distinguish references from integer. Having separate property for this just makes things more complex than they need to be IMHO.

maintainer
#25 lore raw

Re: [RFC PATCH v2 12/17] ACPI: property: Add support for nargs_prop in acpi_fwnode_get_reference_args()

Quoted 16 lines · Mika Westerberg
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Anup Patel

From: Sunil V L <[email protected]>

fwnode_get_reference_args() which is common for both DT and ACPI passes a property name like #mbox-cells which needs to be fetched from the reference node to determine the number of arguments needed for the property. However, the ACPI version of this function doesn't support this and simply ignores the parameter passed from the wrapper function. Add support for dynamically finding number of arguments by reading the nargs property value. Update the callers to pass extra parameter.

Quoted 1 line

I don't like this (implementation).

Agree.

Quoted 8 lines
Quoted 4 lines

It seems that we basically have two parameters which values are duplicating each other. This is error prone API and confusing in the cases when both are defined. If you want property, add a new API that takes const char *nargs and relies on the property be present.

Also this is not really needed for ACPI case because it has types so it can distinguish references from integer. Having separate property for this just makes things more complex than they need to be IMHO.

Thanks! Andy and Mika for your kind feedback. I agree that having both property name and nargs is confusing and also ACPI would not need nargs_prop. In fact, I think ACPI doesn't need even nargs integer value as well from the caller since all integers after the reference are counted as arguments. However, the issue is acpi_get_ref_args() assumes that caller passes valid num_args. But typically the common fwnode_property_get_reference_args() doesn't usually pass both valid values. So, should fwnode_property_get_reference_args() pass both nargs_prop (for DT) and nargs (for ACPI). Or do you mean it is better to remove the check for num_args in the loop inside acpi_get_ref_args() function?

Thanks,
Sunil

#26 lore raw

Re: [RFC PATCH v2 12/17] ACPI: property: Add support for nargs_prop in acpi_fwnode_get_reference_args()

Quoted 26 lines · Sunil V L
Quoted 16 lines · Mika Westerberg
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Anup Patel

From: Sunil V L <[email protected]>

fwnode_get_reference_args() which is common for both DT and ACPI passes a property name like #mbox-cells which needs to be fetched from the reference node to determine the number of arguments needed for the property. However, the ACPI version of this function doesn't support this and simply ignores the parameter passed from the wrapper function. Add support for dynamically finding number of arguments by reading the nargs property value. Update the callers to pass extra parameter.

Quoted 1 line

I don't like this (implementation).

Agree.

Quoted 8 lines
Quoted 4 lines

It seems that we basically have two parameters which values are duplicating each other. This is error prone API and confusing in the cases when both are defined. If you want property, add a new API that takes const char *nargs and relies on the property be present.

Also this is not really needed for ACPI case because it has types so it can distinguish references from integer. Having separate property for this just makes things more complex than they need to be IMHO.

Quoted 11 lines

Thanks! Andy and Mika for your kind feedback. I agree that having both property name and nargs is confusing and also ACPI would not need nargs_prop. In fact, I think ACPI doesn't need even nargs integer value as well from the caller since all integers after the reference are counted as arguments. However, the issue is acpi_get_ref_args() assumes that caller passes valid num_args. But typically the common fwnode_property_get_reference_args() doesn't usually pass both valid values. So, should fwnode_property_get_reference_args() pass both nargs_prop (for DT) and nargs (for ACPI). Or do you mean it is better to remove the check for num_args in the loop inside acpi_get_ref_args() function?

Can you show an example of a case you are trying to solve with this? So far we have been able to go with the current implementation so why this is needed now?

#20 lore raw

Re: [RFC PATCH v2 11/17] irqchip: Add driver for the RISC-V RPMI system MSI service group

In reply to Anup Patel

drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 59

Quoted 8 lines · Anup Patel
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +8 -0
+
+struct rpmi_sysmsi_priv {
+	struct device *dev;
+	struct mbox_client client;
+	struct mbox_chan *chan;
+	u32 nr_irqs;
+	u32 gsi_base;
+};

AS requested before please use tabular layout for structs:

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#struct-declarations-and-initializers

Quoted 15 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +15 -0
+static int rpmi_sysmsi_set_msi_state(struct rpmi_sysmsi_priv *priv,
+				     u32 sys_msi_index, u32 sys_msi_state)
+{
+	struct rpmi_sysmsi_set_msi_state_tx tx;
+	struct rpmi_sysmsi_set_msi_state_rx rx;
+	struct rpmi_mbox_message msg;
+	int ret;
+
+	tx.sys_msi_index = sys_msi_index;
+	tx.sys_msi_state = sys_msi_state;
+	rpmi_mbox_init_send_with_response(&msg, RPMI_SYSMSI_SRV_SET_MSI_STATE,
+					  &tx, sizeof(tx), &rx, sizeof(rx));
+	ret = rpmi_mbox_send_message(priv->chan, &msg);
+	if (ret)
+		return ret;

drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 102

Quoted 10 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +10 -0
+	if (rx.status)
+		return rpmi_to_linux_error(rx.status);
+
+	return 0;
+}
+
+#define rpmi_sysmsi_mask(__priv, __msi_index)		\
+	rpmi_sysmsi_set_msi_state(__priv, __msi_index, 0)
+#define rpmi_sysmsi_unmask(__priv, __msi_index)		\
+	rpmi_sysmsi_set_msi_state(__priv, __msi_index, RPMI_SYSMSI_MSI_STATE_ENABLE)

These macros are not really providing any value.

drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 135

Quoted 9 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +9 -0
+static void rpmi_sysmsi_irq_mask(struct irq_data *d)
+{
+	struct rpmi_sysmsi_priv *priv = irq_data_get_irq_chip_data(d);
+	int ret;
+
+	ret = rpmi_sysmsi_mask(priv, d->hwirq);
+	if (ret)
+		dev_warn(priv->dev, "Failed to mask hwirq %d (error %d)\n",
+			 (u32)d->hwirq, ret);
        if (ret) {
        	....
        }

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#bracket-rules

Review

Quoted 2 lines
(quoted diff) +2 -0
+	irq_chip_mask_parent(d);
+}

Other than those nits, this looks reasonable.

Thanks,

tglx

maintainer
#27 lore raw

Re: [RFC PATCH v2 12/17] ACPI: property: Add support for nargs_prop in acpi_fwnode_get_reference_args()

In reply to Mika Westerberg
Quoted 39 lines · Mika Westerberg
Quoted 26 lines · Sunil V L
Quoted 16 lines · Mika Westerberg
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Anup Patel

From: Sunil V L <[email protected]>

fwnode_get_reference_args() which is common for both DT and ACPI passes a property name like #mbox-cells which needs to be fetched from the reference node to determine the number of arguments needed for the property. However, the ACPI version of this function doesn't support this and simply ignores the parameter passed from the wrapper function. Add support for dynamically finding number of arguments by reading the nargs property value. Update the callers to pass extra parameter.

Quoted 1 line

I don't like this (implementation).

Agree.

Quoted 8 lines
Quoted 4 lines

It seems that we basically have two parameters which values are duplicating each other. This is error prone API and confusing in the cases when both are defined. If you want property, add a new API that takes const char *nargs and relies on the property be present.

Also this is not really needed for ACPI case because it has types so it can distinguish references from integer. Having separate property for this just makes things more complex than they need to be IMHO.

Quoted 11 lines

Thanks! Andy and Mika for your kind feedback. I agree that having both property name and nargs is confusing and also ACPI would not need nargs_prop. In fact, I think ACPI doesn't need even nargs integer value as well from the caller since all integers after the reference are counted as arguments. However, the issue is acpi_get_ref_args() assumes that caller passes valid num_args. But typically the common fwnode_property_get_reference_args() doesn't usually pass both valid values. So, should fwnode_property_get_reference_args() pass both nargs_prop (for DT) and nargs (for ACPI). Or do you mean it is better to remove the check for num_args in the loop inside acpi_get_ref_args() function?

Quoted 3 lines

Can you show an example of a case you are trying to solve with this? So far we have been able to go with the current implementation so why this is needed now?

Basically one can call fwnode_property_get_reference_args() irrespective of DT/ACPI. The case we are trying is like below.

if (fwnode_property_get_reference_args(dev->fwnode, "mboxes",

					       "#mbox-cells", 0, index, &fwspec)) {

...
}

As you can see this works for DT since OF interface handles "#mbox-cells". But since nargs is passed as 0, it won't work for ACPI due to the reason I mentioned earlier.

Mandating to pass both "#mbox-cell" and valid nargs count looks redundant to me.

Thanks,
Sunil

#39 lore raw

Re: [RFC PATCH v2 16/17] irqchip/riscv-rpmi-sysmsi: Add ACPI support

In reply to Anup Patel

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static const struct of_device_id rpmi_sysmsi_match[] = { · line 311

Quoted 6 lines · Anup Patel
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +2 -0
+
 static struct platform_driver rpmi_sysmsi_driver = {
 	.driver = {
 		.name		= "rpmi-sysmsi",
 		.of_match_table	= rpmi_sysmsi_match,
+		.acpi_match_table	= ACPI_PTR(acpi_rpmi_sysmsi_match),

Please indent .name and .of_match_table accordingly.

Thanks,

tglx

#28 lore raw

Re: [RFC PATCH v2 12/17] ACPI: property: Add support for nargs_prop in acpi_fwnode_get_reference_args()

In reply to Sunil V L
Quoted 52 lines · Sunil V L
Quoted 39 lines · Mika Westerberg
Quoted 26 lines · Sunil V L
Quoted 16 lines · Mika Westerberg
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Anup Patel

From: Sunil V L <[email protected]>

fwnode_get_reference_args() which is common for both DT and ACPI passes a property name like #mbox-cells which needs to be fetched from the reference node to determine the number of arguments needed for the property. However, the ACPI version of this function doesn't support this and simply ignores the parameter passed from the wrapper function. Add support for dynamically finding number of arguments by reading the nargs property value. Update the callers to pass extra parameter.

Quoted 1 line

I don't like this (implementation).

Agree.

Quoted 8 lines
Quoted 4 lines

It seems that we basically have two parameters which values are duplicating each other. This is error prone API and confusing in the cases when both are defined. If you want property, add a new API that takes const char *nargs and relies on the property be present.

Also this is not really needed for ACPI case because it has types so it can distinguish references from integer. Having separate property for this just makes things more complex than they need to be IMHO.

Quoted 11 lines

Thanks! Andy and Mika for your kind feedback. I agree that having both property name and nargs is confusing and also ACPI would not need nargs_prop. In fact, I think ACPI doesn't need even nargs integer value as well from the caller since all integers after the reference are counted as arguments. However, the issue is acpi_get_ref_args() assumes that caller passes valid num_args. But typically the common fwnode_property_get_reference_args() doesn't usually pass both valid values. So, should fwnode_property_get_reference_args() pass both nargs_prop (for DT) and nargs (for ACPI). Or do you mean it is better to remove the check for num_args in the loop inside acpi_get_ref_args() function?

Quoted 3 lines

Can you show an example of a case you are trying to solve with this? So far we have been able to go with the current implementation so why this is needed now?

Basically one can call fwnode_property_get_reference_args() irrespective of DT/ACPI. The case we are trying is like below.

if (fwnode_property_get_reference_args(dev->fwnode, "mboxes",

					       "#mbox-cells", 0, index, &fwspec)) {

...
}

Quoted 6 lines

As you can see this works for DT since OF interface handles "#mbox-cells". But since nargs is passed as 0, it won't work for ACPI due to the reason I mentioned earlier.

Mandating to pass both "#mbox-cell" and valid nargs count looks redundant to me.

Ah, interesting. The original change that introduces this 3e3119d3088f ("device
property: Introduce fwnode_property_get_reference_args") hadn't been reviewed by Mika or me, that's probably why we are not familiar with.

Since interface is already established, I would recommend to fix this as proposed, i.e. with a new API. This is the way to match how OF seems to be doing.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#29 lore raw

Re: [RFC PATCH v2 12/17] ACPI: property: Add support for nargs_prop in acpi_fwnode_get_reference_args()

Quoted 60 lines · Andy Shevchenko
Quoted 52 lines · Sunil V L
Quoted 39 lines · Mika Westerberg
Quoted 26 lines · Sunil V L
Quoted 16 lines · Mika Westerberg
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Anup Patel

From: Sunil V L <[email protected]>

fwnode_get_reference_args() which is common for both DT and ACPI passes a property name like #mbox-cells which needs to be fetched from the reference node to determine the number of arguments needed for the property. However, the ACPI version of this function doesn't support this and simply ignores the parameter passed from the wrapper function. Add support for dynamically finding number of arguments by reading the nargs property value. Update the callers to pass extra parameter.

Quoted 1 line

I don't like this (implementation).

Agree.

Quoted 8 lines
Quoted 4 lines

It seems that we basically have two parameters which values are duplicating each other. This is error prone API and confusing in the cases when both are defined. If you want property, add a new API that takes const char *nargs and relies on the property be present.

Also this is not really needed for ACPI case because it has types so it can distinguish references from integer. Having separate property for this just makes things more complex than they need to be IMHO.

Quoted 11 lines

Thanks! Andy and Mika for your kind feedback. I agree that having both property name and nargs is confusing and also ACPI would not need nargs_prop. In fact, I think ACPI doesn't need even nargs integer value as well from the caller since all integers after the reference are counted as arguments. However, the issue is acpi_get_ref_args() assumes that caller passes valid num_args. But typically the common fwnode_property_get_reference_args() doesn't usually pass both valid values. So, should fwnode_property_get_reference_args() pass both nargs_prop (for DT) and nargs (for ACPI). Or do you mean it is better to remove the check for num_args in the loop inside acpi_get_ref_args() function?

Quoted 3 lines

Can you show an example of a case you are trying to solve with this? So far we have been able to go with the current implementation so why this is needed now?

Basically one can call fwnode_property_get_reference_args() irrespective of DT/ACPI. The case we are trying is like below.

if (fwnode_property_get_reference_args(dev->fwnode, "mboxes",

					       "#mbox-cells", 0, index, &fwspec)) {

...
}

Quoted 6 lines

As you can see this works for DT since OF interface handles "#mbox-cells". But since nargs is passed as 0, it won't work for ACPI due to the reason I mentioned earlier.

Mandating to pass both "#mbox-cell" and valid nargs count looks redundant to me.

Quoted 7 lines

Ah, interesting. The original change that introduces this 3e3119d3088f ("device
property: Introduce fwnode_property_get_reference_args") hadn't been reviewed by Mika or me, that's probably why we are not familiar with.

Since interface is already established, I would recommend to fix this as proposed, i.e. with a new API. This is the way to match how OF seems to be doing.

For the reference see implementation of of_fwnode_get_reference_args()

	if (nargs_prop)
		ret = of_parse_phandle_with_args(to_of_node(fwnode), prop,
						 nargs_prop, index, &of_args);
	else
		ret = of_parse_phandle_with_fixed_args(to_of_node(fwnode), prop,
						       nargs, index, &of_args);
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw

Re: [RFC PATCH v2 02/17] dt-bindings: mailbox: Add bindings for RPMI shared memory transport

In reply to Anup Patel
Quoted 68 lines · Anup Patel

Add device tree bindings for the common RISC-V Platform Management Interface (RPMI) shared memory transport as a mailbox controller.

---
 .../mailbox/riscv,rpmi-shmem-mbox.yaml        | 150 ++++++++++++++++++
 1 file changed, 150 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +53 -0
new file mode 100644
index 000000000000..c339df5d9e24
@@ -0,0 +1,150 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mailbox/riscv,rpmi-shmem-mbox.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RISC-V Platform Management Interface (RPMI) shared memory mailbox
+
+maintainers:
+  - Anup Patel <[email protected]>
+
+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: P2A request queue base address
+          - description: A2P acknowledgment queue base address
+      - items:
+          - description: A2P request queue base address
+          - description: P2A acknowledgment queue base address
+          - description: A2P doorbell address
+      - items:
+          - description: A2P request queue base address
+          - description: P2A acknowledgment queue base address
+
+  reg-names:
+    oneOf:
+      - items:

Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +10 -0
+          - const: a2p-req
+          - const: p2a-ack
+          - const: p2a-req
+          - const: a2p-ack
+          - const: doorbell
+      - items:
+          - const: a2p-req
+          - const: p2a-ack
+          - const: p2a-req
+          - const: a2p-ack

These first 2 items lists can be combined with the addition of 'minItems: 4'

Quoted 27 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +27 -0
+      - items:
+          - const: a2p-req
+          - const: p2a-ack
+          - const: doorbell
+      - items:
+          - const: a2p-req
+          - const: p2a-ack
+
+  interrupts:
+    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,doorbell-mask:
+    $ref: /schemas/types.yaml#/definitions/uint32

Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml line 100

Quoted 10 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +10 -0
+    default: 0xffffffff
+    description:
+      Update only the register bits of doorbell defined by the mask (32 bit).
+
+  riscv,doorbell-value:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 0x1
+    description:
+      Value written to the doorbell register bits (32-bit access) specified
+      by the riscv,db-mask property.

You mean riscv,doorbell-mask?

I'm confused why you would need both? If the value to write is fixed here, then why do you need a mask? You could just mask the value here.

I assume there's some dependency between these 2 properties. That needs to be captured with 'dependencies'.

Quoted 53 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +50 -0
+
+  "#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 = <0x10080000 0x10000>,
+              <0x10090000 0x10000>,
+              <0x100a0000 0x4>;
+        reg-names = "a2p-req", "p2a-ack", "doorbell";
+        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 = <0x10001000 0x800>,
+              <0x10001800 0x800>,
+              <0x10002000 0x800>,
+              <0x10002800 0x800>,
+              <0x10003000 0x4>;
+        reg-names = "a2p-req", "p2a-ack", "p2a-req", "a2p-ack", "doorbell";
+        msi-parent = <&imsic_mlevel>;
+        riscv,slot-size = <64>;
+        riscv,doorbell-mask = <0x00008000>;
+        riscv,doorbell-value = <0x00008000>;
+        #mbox-cells = <1>;
+    };
Signature · 1 line
2.43.0
maintainer
#6 lore raw

Re: [RFC PATCH v2 03/17] dt-bindings: mailbox: Add bindings for RISC-V SBI MPXY extension

In reply to Anup Patel
Quoted 37 lines · Anup Patel

Add device tree bindings for the RISC-V SBI Message Proxy (MPXY) extension as a mailbox controller.

---
 .../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
Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml new file +22 -0
new file mode 100644
index 000000000000..8a05e089b710
@@ -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 <[email protected]>
+
+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
+  ===========================================

Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml line 32

Quoted 10 lines
Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml new file +10 -0
+
+  [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

'mailbox' is the defined name for mailbox providers.

Quoted 11 lines
Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml new file +11 -0
+
+  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:

Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml line 53

Quoted 10 lines
Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml new file +10 -0
+  - compatible
+  - "#mbox-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    sbi-mpxy-mbox {
+          compatible = "riscv,sbi-mpxy-mbox";
+          #mbox-cells = <2>;

Is there an SBI node? #mbox-cells could just be part of that along with anything else that SBI is a provider for. And we already have the PMU SBI binding. It's all one thing, so there should be one SBI node. Then we can debate about child nodes of it.

Rob

maintainer
#13 lore raw

Re: [RFC PATCH v2 08/17] dt-bindings: clock: Add bindings for RISC-V RPMI clock service group

In reply to Anup Patel
Quoted 58 lines · Anup Patel

Add device tree bindings for the clock service group defined by the RISC-V platform management interface (RPMI) specification.

---
 .../bindings/clock/riscv,rpmi-clock.yaml      | 77 +++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +43 -0
new file mode 100644
index 000000000000..c08491c04926
@@ -0,0 +1,77 @@
+# 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 <[email protected]>
+
+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:

Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml line 53

Quoted 10 lines
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +10 -0
+    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.

That constraint can be expressed as:

dependentSchemas:
riscv,sbi-mpxy-channel-id:
properties:
compatible:
const: riscv,rpmi-mpxy-clock

Please double check that works.

Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml line 58

Quoted 5 lines
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +5 -0
+
+  "#clock-cells":
+    const: 1
+    description:
+      This property is mandatory when using riscv,rpmi-clock compatible string.

Similar constraint here.

Though the only thing the 2 compatibles have in common is 'mboxes'. I think it would be better to just split this into 2 docs.

Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml line 68

Quoted 10 lines
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +10 -0
+
+required:
+  - compatible
+  - mboxes
+
+additionalProperties: false
+
+examples:
+  - |
+    mpxy_mbox: sbi-mpxy-mbox {

mailbox {

Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml line 72

Quoted 4 lines
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +4 -0
+          compatible = "riscv,sbi-mpxy-mbox";
+          #mbox-cells = <2>;
+    };
+    rpmi-clk {

clock-controller {

Quoted 8 lines
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +5 -0
+        compatible = "riscv,rpmi-clock";
+        mboxes = <&mpxy_mbox 0x1000 0x0>;
+        #clock-cells = <1>;
+    };
+...
Signature · 1 line
2.43.0
maintainer
#17 lore raw

Re: [RFC PATCH v2 10/17] dt-bindings: interrupt-controller: Add bindings for RISC-V RPMI system MSI

In reply to Anup Patel
Quoted 27 lines · Anup Patel

Add device tree bindings for the system MSI service group based interrupt controller defined by the RISC-V platform management interface (RPMI) specification.

---
 .../riscv,rpmi-system-msi.yaml                | 89 +++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml new file +11 -0
new file mode 100644
index 000000000000..e6c297e66c99
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/riscv,rpmi-system-msi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RISC-V RPMI system MSI service group based interrupt controller
+
+maintainers:
+  - Anup Patel <[email protected]>
+

Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml line 21

Quoted 10 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml new file +10 -0
+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 system MSI service group which
+  allow application processors to receive MSIs upon system events
+  such as P2A doorbell, graceful shutdown/reboot request, CPU hotplug
+  event, memory hotplug event, etc from the platform microcontroller.

I'm confused by this description and what the binding has. This "device" is receiving interrupts and generating MSIs based on those interrupts?

Quoted 47 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml new file +47 -0
+
+  ===========================================
+  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
+
+allOf:
+  - $ref: /schemas/interrupt-controller.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - description:
+          Intended for use by the SBI implementation in machine mode or
+          software in supervisor mode.
+        const: riscv,rpmi-system-msi
+
+      - description:
+          Intended for use by the SBI implementation in machine mode.
+        const: riscv,rpmi-mpxy-system-msi
+
+  mboxes:
+    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-system-msi compatible string.
+
+  msi-parent: true
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 1
+
+required:
+  - compatible

Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml line 78

Quoted 10 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml new file +10 -0
+  - mboxes
+  - msi-parent
+  - interrupt-controller
+  - "#interrupt-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    mpxy_mbox: sbi-mpxy-mbox {

mailbox {

Though generally we don't show providers for a consumer schema.

Quoted 14 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml new file +11 -0
+          compatible = "riscv,sbi-mpxy-mbox";
+          #mbox-cells = <2>;
+    };
+    rpmi_sysmsi_intc: interrupt-controller {
+        compatible = "riscv,rpmi-system-msi";
+        mboxes = <&mpxy_mbox 0x2000 0x0>;
+        msi-parent = <&imsic_slevel>;
+        interrupt-controller;
+        #interrupt-cells = <1>;
+    };
+...
Signature · 1 line
2.43.0
maintainer
#38 lore raw

Re: [RFC PATCH v2 16/17] irqchip/riscv-rpmi-sysmsi: Add ACPI support

In reply to Andy Shevchenko
Quoted 70 lines · Andy Shevchenko
Quoted 3 lines · Anup Patel

From: Sunil V L <[email protected]>

Add ACPI support for the RISC-V RPMI system MSI based irqchip driver.

...

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 228

Quoted 1 line
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +1 -0
+	if (!is_of_node(dev->fwnode)) {

Please, use dev_fwnode(),

But why do you need this? Can't the below simply become a no-op without this check?

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 229

Quoted 1 line
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +1 -0
+		rc = riscv_acpi_get_gsi_info(dev->fwnode, &priv->gsi_base, &id,

Ditto.

Quoted 6 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +6 -0
+					     &priv->nr_irqs, NULL);
+		if (rc) {
+			dev_err(dev, "failed to find GSI mapping\n");
+			return rc;
+		}
+	}

...

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev)

Quoted 13 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +7 -1
 		 * then we need to set it explicitly before using any platform
 		 * MSI functions.
 		 */
-		if (is_of_node(dev->fwnode))
+		if (is_of_node(dev->fwnode)) {
 			of_msi_configure(dev, to_of_node(dev->fwnode));
+		} else {
+			struct irq_domain *msi_domain;
+
+			msi_domain = irq_find_matching_fwnode(imsic_acpi_get_fwnode(dev),
+							      DOMAIN_BUS_PLATFORM_MSI);
 
+			if (msi_domain)

Hmm... The OF case above assumes this check is not needed. Why is it special otherwise?

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 277

Quoted 4 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +2 -0
+				dev_set_msi_domain(dev, msi_domain);
+		}
 
 		if (!dev_get_msi_domain(dev))

Even here you have a check for NULL, so I believe the conditional is simply redundant.

...

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 287

Quoted 3 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +2 -0
+#ifdef CONFIG_ACPI
 
+	if (!acpi_disabled)

Why?

Quoted 2 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +2 -0
+		acpi_dev_clear_dependencies(ACPI_COMPANION(dev));
+#endif

...

Quoted 1 line

+#ifdef CONFIG_ACPI

Drop this ugly ifdeffery along with ACPI_PTR(). They are more harmful than useful.

Quoted 7 lines

...

drivers/irqchip/irq-riscv-rpmi-sysmsi.c static const struct of_device_id rpmi_sysmsi_match[] = { · line 301

Quoted 2 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +2 -0
+static const struct acpi_device_id acpi_rpmi_sysmsi_match[] = {
+	{ "RSCV0006", 0 },

Drop ', 0' part as it may be converted to a pointer in the future.

Thanks!. Let me address your comments in next revision.

Thanks,
Sunil

maintainer
#30 lore raw

Re: [RFC PATCH v2 12/17] ACPI: property: Add support for nargs_prop in acpi_fwnode_get_reference_args()

In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines

Ah, interesting. The original change that introduces this 3e3119d3088f ("device
property: Introduce fwnode_property_get_reference_args") hadn't been reviewed by Mika or me, that's probably why we are not familiar with.

Since interface is already established, I would recommend to fix this as proposed, i.e. with a new API. This is the way to match how OF seems to be doing.

Quoted 10 lines

For the reference see implementation of of_fwnode_get_reference_args()

	if (nargs_prop)
		ret = of_parse_phandle_with_args(to_of_node(fwnode), prop,
						 nargs_prop, index, &of_args);
	else
		ret = of_parse_phandle_with_fixed_args(to_of_node(fwnode), prop,
						       nargs, index, &of_args);

Thanks!. I can do similar. But the change in __acpi_node_get_property_reference() will be still required since that is the place where the actual decoding of AML object is done. That would be similar to __of_parse_phandle_with_args() as well. Hope that is fine.

Thanks,
Sunil

#31 lore raw

Re: [RFC PATCH v2 12/17] ACPI: property: Add support for nargs_prop in acpi_fwnode_get_reference_args()

Quoted 19 lines · Sunil V L
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines

Ah, interesting. The original change that introduces this 3e3119d3088f ("device
property: Introduce fwnode_property_get_reference_args") hadn't been reviewed by Mika or me, that's probably why we are not familiar with.

Since interface is already established, I would recommend to fix this as proposed, i.e. with a new API. This is the way to match how OF seems to be doing.

Quoted 10 lines

For the reference see implementation of of_fwnode_get_reference_args()

	if (nargs_prop)
		ret = of_parse_phandle_with_args(to_of_node(fwnode), prop,
						 nargs_prop, index, &of_args);
	else
		ret = of_parse_phandle_with_fixed_args(to_of_node(fwnode), prop,
						       nargs, index, &of_args);
Quoted 4 lines

Thanks!. I can do similar. But the change in __acpi_node_get_property_reference() will be still required since that is the place where the actual decoding of AML object is done. That would be similar to __of_parse_phandle_with_args() as well. Hope that is fine.

You don't need that. Split the core part to local static helper that takes whatever it needs, but being not visible to anyone outside drivers/acpi/property.c. And build the current helper and new visible one on the basis of this split. For better reviewing and maintaining you can split this approach to two patches: 1) preparatory by splitting a new local helper; 2) the introduction of a new API.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#21 lore raw

Re: [RFC PATCH v2 11/17] irqchip: Add driver for the RISC-V RPMI system MSI service group

In reply to Thomas Gleixner

Hi Thomas,

Quoted 57 lines · Thomas Gleixner

drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 59

Quoted 8 lines · Anup Patel
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +8 -0
+
+struct rpmi_sysmsi_priv {
+     struct device *dev;
+     struct mbox_client client;
+     struct mbox_chan *chan;
+     u32 nr_irqs;
+     u32 gsi_base;
+};

AS requested before please use tabular layout for structs:

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#struct-declarations-and-initializers

Quoted 15 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +15 -0
+static int rpmi_sysmsi_set_msi_state(struct rpmi_sysmsi_priv *priv,
+                                  u32 sys_msi_index, u32 sys_msi_state)
+{
+     struct rpmi_sysmsi_set_msi_state_tx tx;
+     struct rpmi_sysmsi_set_msi_state_rx rx;
+     struct rpmi_mbox_message msg;
+     int ret;
+
+     tx.sys_msi_index = sys_msi_index;
+     tx.sys_msi_state = sys_msi_state;
+     rpmi_mbox_init_send_with_response(&msg, RPMI_SYSMSI_SRV_SET_MSI_STATE,
+                                       &tx, sizeof(tx), &rx, sizeof(rx));
+     ret = rpmi_mbox_send_message(priv->chan, &msg);
+     if (ret)
+             return ret;

drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 102

Quoted 10 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +10 -0
+     if (rx.status)
+             return rpmi_to_linux_error(rx.status);
+
+     return 0;
+}
+
+#define rpmi_sysmsi_mask(__priv, __msi_index)                \
+     rpmi_sysmsi_set_msi_state(__priv, __msi_index, 0)
+#define rpmi_sysmsi_unmask(__priv, __msi_index)              \
+     rpmi_sysmsi_set_msi_state(__priv, __msi_index, RPMI_SYSMSI_MSI_STATE_ENABLE)

These macros are not really providing any value.

drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 135

Quoted 9 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +9 -0
+static void rpmi_sysmsi_irq_mask(struct irq_data *d)
+{
+     struct rpmi_sysmsi_priv *priv = irq_data_get_irq_chip_data(d);
+     int ret;
+
+     ret = rpmi_sysmsi_mask(priv, d->hwirq);
+     if (ret)
+             dev_warn(priv->dev, "Failed to mask hwirq %d (error %d)\n",
+                      (u32)d->hwirq, ret);
        if (ret) {
                ....
        }
Quoted 6 lines

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#bracket-rules

Review

Quoted 2 lines
(quoted diff) +2 -0
+     irq_chip_mask_parent(d);
+}

Other than those nits, this looks reasonable.

I will address all above comments in the next revision.

Thanks,
Anup

author
#7 lore raw

Re: [RFC PATCH v2 03/17] dt-bindings: mailbox: Add bindings for RISC-V SBI MPXY extension

In reply to Rob Herring
Quoted 43 lines · Rob Herring
Quoted 41 lines · Anup Patel

Add device tree bindings for the RISC-V SBI Message Proxy (MPXY) extension as a mailbox controller.

---
 .../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
Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml new file +26 -0
new file mode 100644
index 000000000000..8a05e089b710
@@ -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 <[email protected]>
+
+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
+
Quoted 8 lines

Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml line 32

Quoted 6 lines
Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml new file +6 -0
+  [2] RISC-V Platform Management Interface (RPMI)
+      https://github.com/riscv-non-isa/riscv-rpmi/releases
+
+properties:
+  $nodename:
+    const: sbi-mpxy-mbox

'mailbox' is the defined name for mailbox providers.

Okay, I will update.

Quoted 19 lines
Quoted 19 lines
Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml new file +18 -0
+
+  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:
+  - |
Quoted 8 lines

Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml line 53

Quoted 3 lines
Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml new file +3 -0
+    sbi-mpxy-mbox {
+          compatible = "riscv,sbi-mpxy-mbox";
+          #mbox-cells = <2>;

Is there an SBI node? #mbox-cells could just be part of that along with anything else that SBI is a provider for. And we already have the PMU SBI binding. It's all one thing, so there should be one SBI node. Then we can debate about child nodes of it.

There is no SBI node for any other SBI extension.

The PMU bindings for "riscv,pmu" compatible string is for the firmware driver (M-mode) which implements the SBI PMU extension not the Linux driver.

The "title" and "description" of <linux_source>/Documentation/devicetree/bindings/perf/riscv,pmu.yaml needs some clarification.

Regards,
Anup

author
#4 lore raw

Re: [RFC PATCH v2 02/17] dt-bindings: mailbox: Add bindings for RPMI shared memory transport

In reply to Rob Herring
Quoted 75 lines · Rob Herring
Quoted 73 lines · Anup Patel

Add device tree bindings for the common RISC-V Platform Management Interface (RPMI) shared memory transport as a mailbox controller.

---
 .../mailbox/riscv,rpmi-shmem-mbox.yaml        | 150 ++++++++++++++++++
 1 file changed, 150 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +58 -0
new file mode 100644
index 000000000000..c339df5d9e24
@@ -0,0 +1,150 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mailbox/riscv,rpmi-shmem-mbox.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RISC-V Platform Management Interface (RPMI) shared memory mailbox
+
+maintainers:
+  - Anup Patel <[email protected]>
+
+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: P2A request queue base address
+          - description: A2P acknowledgment queue base address
+      - items:
+          - description: A2P request queue base address
+          - description: P2A acknowledgment queue base address
+          - description: A2P doorbell address
+      - items:
+          - description: A2P request queue base address
+          - description: P2A acknowledgment queue base address
+
+  reg-names:
+    oneOf:
+      - items:
+          - const: a2p-req
+          - const: p2a-ack
+          - const: p2a-req
+          - const: a2p-ack
+          - const: doorbell
Quoted 8 lines

Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml line 57

Quoted 5 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +5 -0
+      - items:
+          - const: a2p-req
+          - const: p2a-ack
+          - const: p2a-req
+          - const: a2p-ack

These first 2 items lists can be combined with the addition of 'minItems: 4'

It seems "minItems" is not allowed under "items".

If we put "minItems: 4" under "reg-names" then below combinations become invalid.

Quoted 41 lines
Quoted 28 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +27 -0
+      - items:
+          - const: a2p-req
+          - const: p2a-ack
+          - const: doorbell
+      - items:
+          - const: a2p-req
+          - const: p2a-ack
+
+  interrupts:
+    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,doorbell-mask:
+    $ref: /schemas/types.yaml#/definitions/uint32

Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml line 100

Quoted 10 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +10 -0
+    default: 0xffffffff
+    description:
+      Update only the register bits of doorbell defined by the mask (32 bit).
+
+  riscv,doorbell-value:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 0x1
+    description:
+      Value written to the doorbell register bits (32-bit access) specified
+      by the riscv,db-mask property.

You mean riscv,doorbell-mask?

Quoted 5 lines

I'm confused why you would need both? If the value to write is fixed here, then why do you need a mask? You could just mask the value here.

I assume there's some dependency between these 2 properties. That needs to be captured with 'dependencies'.

We don't need the "riscv,doorbell-mask" property because the latest frozen RPMI specification only defines a write-only 32-bit doorbell register. I will remove this property in the next revision.

Quoted 46 lines
Quoted 46 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +45 -0
+
+  "#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 = <0x10080000 0x10000>,
+              <0x10090000 0x10000>,
+              <0x100a0000 0x4>;
+        reg-names = "a2p-req", "p2a-ack", "doorbell";
+        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 = <0x10001000 0x800>,
+              <0x10001800 0x800>,
+              <0x10002000 0x800>,
+              <0x10002800 0x800>,
+              <0x10003000 0x4>;
+        reg-names = "a2p-req", "p2a-ack", "p2a-req", "a2p-ack", "doorbell";
+        msi-parent = <&imsic_mlevel>;
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +5 -1
+        riscv,slot-size = <64>;
+        riscv,doorbell-mask = <0x00008000>;
+        riscv,doorbell-value = <0x00008000>;
+        #mbox-cells = <1>;
+    };
--

2.43.0

Regards,
Anup

author
#14 lore raw

Re: [RFC PATCH v2 08/17] dt-bindings: clock: Add bindings for RISC-V RPMI clock service group

In reply to Rob Herring
Quoted 87 lines · Rob Herring
Quoted 58 lines · Anup Patel

Add device tree bindings for the clock service group defined by the RISC-V platform management interface (RPMI) specification.

---
 .../bindings/clock/riscv,rpmi-clock.yaml      | 77 +++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +43 -0
new file mode 100644
index 000000000000..c08491c04926
@@ -0,0 +1,77 @@
+# 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 <[email protected]>
+
+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:

Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml line 53

Quoted 10 lines
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +10 -0
+    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.

That constraint can be expressed as:

dependentSchemas:
riscv,sbi-mpxy-channel-id:
properties:
compatible:
const: riscv,rpmi-mpxy-clock

Please double check that works.

Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml line 58

Quoted 5 lines
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +5 -0
+
+  "#clock-cells":
+    const: 1
+    description:
+      This property is mandatory when using riscv,rpmi-clock compatible string.
Quoted 4 lines

Similar constraint here.

Though the only thing the 2 compatibles have in common is 'mboxes'. I think it would be better to just split this into 2 docs.

Yes, it is much simpler to have 2 separate docs. I will update in the next revision.

Regards,
Anup

Quoted 29 lines

Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml line 68

Quoted 11 lines
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +10 -0
+
+required:
+  - compatible
+  - mboxes
+
+additionalProperties: false
+
+examples:
+  - |
+    mpxy_mbox: sbi-mpxy-mbox {

mailbox {

Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml line 72

Quoted 4 lines
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +4 -0
+          compatible = "riscv,sbi-mpxy-mbox";
+          #mbox-cells = <2>;
+    };
+    rpmi-clk {

clock-controller {

Quoted 8 lines
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +5 -1
+        compatible = "riscv,rpmi-clock";
+        mboxes = <&mpxy_mbox 0x1000 0x0>;
+        #clock-cells = <1>;
+    };
+...
--

2.43.0

author
#18 lore raw

Re: [RFC PATCH v2 10/17] dt-bindings: interrupt-controller: Add bindings for RISC-V RPMI system MSI

In reply to Rob Herring
Quoted 34 lines · Rob Herring
Quoted 32 lines · Anup Patel

Add device tree bindings for the system MSI service group based interrupt controller defined by the RISC-V platform management interface (RPMI) specification.

---
 .../riscv,rpmi-system-msi.yaml                | 89 +++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml new file +16 -0
new file mode 100644
index 000000000000..e6c297e66c99
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/riscv,rpmi-system-msi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RISC-V RPMI system MSI service group based interrupt controller
+
+maintainers:
+  - Anup Patel <[email protected]>
+
+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.
Quoted 8 lines

Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml line 21

Quoted 5 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml new file +5 -0
+
+  The RPMI specification [1] defines system MSI service group which
+  allow application processors to receive MSIs upon system events
+  such as P2A doorbell, graceful shutdown/reboot request, CPU hotplug
+  event, memory hotplug event, etc from the platform microcontroller.

I'm confused by this description and what the binding has. This "device" is receiving interrupts and generating MSIs based on those interrupts?

The platform microcontroller receives/monitors system events and sends MSI to application processors (RISC-V CPUs).

Quoted 61 lines
Quoted 48 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml new file +47 -0
+
+  ===========================================
+  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
+
+allOf:
+  - $ref: /schemas/interrupt-controller.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - description:
+          Intended for use by the SBI implementation in machine mode or
+          software in supervisor mode.
+        const: riscv,rpmi-system-msi
+
+      - description:
+          Intended for use by the SBI implementation in machine mode.
+        const: riscv,rpmi-mpxy-system-msi
+
+  mboxes:
+    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-system-msi compatible string.
+
+  msi-parent: true
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 1
+
+required:
+  - compatible

Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml line 78

Quoted 10 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml new file +10 -0
+  - mboxes
+  - msi-parent
+  - interrupt-controller
+  - "#interrupt-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    mpxy_mbox: sbi-mpxy-mbox {

mailbox {

Quoted 1 line

Though generally we don't show providers for a consumer schema.

Okay, I will drop the producer schema.

Quoted 15 lines
Quoted 13 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml new file +11 -1
+          compatible = "riscv,sbi-mpxy-mbox";
+          #mbox-cells = <2>;
+    };
+    rpmi_sysmsi_intc: interrupt-controller {
+        compatible = "riscv,rpmi-system-msi";
+        mboxes = <&mpxy_mbox 0x2000 0x0>;
+        msi-parent = <&imsic_slevel>;
+        interrupt-controller;
+        #interrupt-cells = <1>;
+    };
+...
--
Quoted 2 lines

2.43.0

Regards,
Anup