Linux SBI MPXY and RPMI drivers
Subsystems (10)
v3 cover Linux SBI MPXY and RPMI drivers
The SBI v3.0 (MPXY extension) [1] and RPMI v1.0 [2] specifications are frozen and in public review at the RISC-V International.
Currently, most of the RPMI and MPXY drivers are in OpenSBI whereas 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_v3 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 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 v2:
- Dropped the "RFC" tag from series since the SBI v3.0 and RPMI v1.0 specifications are now frozen
- Rebased the series on Linux-6.15-rc5
- Split PATCH8 of v2 into two patches adding separate DT bindings for "riscv,rpmi-mpxy-clock" and "riscv,rpmi-clock"
- Split PATCH10 of v2 into two patches adding separate DT bindings for "riscv,rpmi-mpxy-system-msi" and "riscv,rpmi-system-msi"
- Addressed comments from TGLX on PATCH11 of v2 adding irqchip driver for RPMI system MSI
- Addressed ACPI related comments in PATCH15 and PATCH16 of v2
- New PATCH17 and PATCH18 in this series
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 (14):
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 RPMI clock service message proxy bindings
dt-bindings: clock: Add RPMI clock service controller bindings
dt-bindings: Add RPMI system MSI message proxy bindings
dt-bindings: Add RPMI system MSI interrupt controller bindings
irqchip: Add driver for the RPMI system MSI service group
RISC-V: Enable GPIO keyboard and event device in RV64 defconfig
MAINTAINERS: Add entry for RISC-V RPMI and MPXY drivers
Rahul Pathak (1):
clk: Add clock driver for the RISC-V RPMI clock service group
Sunil V L (8):
ACPI: property: Refactor acpi_fwnode_get_reference_args()
ACPI: property: Add support for cells property
ACPI: scan: Update honor list for RPMI System MSI
ACPI: RISC-V: Create interrupt controller list in sorted order
ACPI: RISC-V: Add support to update gsi range
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 | 61 + .../bindings/clock/riscv,rpmi-mpxy-clock.yaml | 64 ++ .../riscv,rpmi-mpxy-system-msi.yaml | 67 ++ .../riscv,rpmi-system-msi.yaml | 74 ++ .../mailbox/riscv,rpmi-shmem-mbox.yaml | 148 +++ .../bindings/mailbox/riscv,sbi-mpxy-mbox.yaml | 51 + MAINTAINERS | 15 + arch/riscv/configs/defconfig | 2 + arch/riscv/include/asm/irq.h | 6 + arch/riscv/include/asm/sbi.h | 72 ++ drivers/acpi/property.c | 118 +- drivers/acpi/riscv/irq.c | 80 +- drivers/acpi/scan.c | 2 + drivers/base/property.c | 2 +- drivers/clk/Kconfig | 8 + drivers/clk/Makefile | 1 + drivers/clk/clk-rpmi.c | 601 ++++++++++ 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 | 48 +- drivers/mailbox/riscv-sbi-mpxy-mbox.c | 1007 +++++++++++++++++ include/linux/mailbox/riscv-rpmi-message.h | 235 ++++ include/linux/mailbox_controller.h | 3 + 26 files changed, 2925 insertions(+), 76 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml create mode 100644 Documentation/devicetree/bindings/clock/riscv,rpmi-mpxy-clock.yaml create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-mpxy-system-msi.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
PATCH v3 1/23 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/riscv/include/asm/sbi.h +12 -0
@@ -419,6 +419,11 @@ 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 +#define SBI_ERR_DENIED_LOCKED -14extern unsigned long sbi_spec_version;struct sbiret {
@@ -503,11 +508,18 @@ static inline int sbi_err_map_linux_errno(int err)case SBI_SUCCESS :return 0 ;case SBI_ERR_DENIED : +case SBI_ERR_DENIED_LOCKED :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
PATCH v3 2/23 dt-bindings: mailbox: Add bindings for RPMI shared memory transport
In reply to Anup PatelAdd 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 | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +148 -0
@@ -0,0 +1,148 @@ +# 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: a2p-doorbell + - items: + - const: a2p-req + - const: p2a-ack + - const: p2a-req + - const: a2p-ack + - items: + - const: a2p-req + - const: p2a-ack + - const: a2p-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 P2A doorbell as a system MSI + 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,a2p-doorbell-value: + $ref: /schemas/types.yaml#/definitions/uint32 + default: 0x1 + description: + Value written to the 32-bit A2P doorbell register. + + riscv,p2a-doorbell-sysmsi-index: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The RPMI shared memory transport supports P2A doorbell as a system MSI + and this property specifies system MSI index to be used for configuring + the P2A doorbell MSI. + + "#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>; + reg-names = "a2p-req", "p2a-ack"; + 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", "a2p-doorbell"; + msi-parent = <&imsic_mlevel>; + riscv,slot-size = <64>; + riscv,a2p-doorbell-value = <0x00008000>; + #mbox-cells = <1>; + };
Signature · 1 line
2.43.0
Rob Herring
maintainerRe: [PATCH v3 02/23] dt-bindings: mailbox: Add bindings for RPMI shared memory transport
Quoted 75 lines · Anup Patel
Add device tree bindings for the common RISC-V Platform Management Interface (RPMI) shared memory transport as a mailbox controller.
Signed-off-by Anup Patel <[email protected]>--- .../mailbox/riscv,rpmi-shmem-mbox.yaml | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yamlDocumentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +60
-0@@ -0,0 +1,148 @@ +# 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: a2p-doorbell + - items: + - const: a2p-req
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml line 70
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +10
-0+ - const: p2a-ack + - const: p2a-req + - const: a2p-ack + - items: + - const: a2p-req + - const: p2a-ack + - const: a2p-doorbell + - items: + - const: a2p-req + - const: p2a-ack
This can all be just:
minItems: 2
items:
- const: a2p-req
- const: p2a-ack
- enum: [ p2a-req, a2p-doorbell ]
- const: a2p-ack
- const: a2p-doorbell
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml line 76
Quoted 6 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +6
-0+ + interrupts: + maxItems: 1 + description: + The RPMI shared memory transport supports wired interrupt specified by + this property as the P2A doorbell.
"The RPMI shared memory transport P2A doorbell"
Quoted 75 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +72
-0+ + msi-parent: + description: + The RPMI shared memory transport supports P2A doorbell as a system MSI + 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,a2p-doorbell-value: + $ref: /schemas/types.yaml#/definitions/uint32 + default: 0x1 + description: + Value written to the 32-bit A2P doorbell register. + + riscv,p2a-doorbell-sysmsi-index: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The RPMI shared memory transport supports P2A doorbell as a system MSI + and this property specifies system MSI index to be used for configuring + the P2A doorbell MSI. + + "#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>; + reg-names = "a2p-req", "p2a-ack"; + 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", "a2p-doorbell"; + msi-parent = <&imsic_mlevel>; + riscv,slot-size = <64>; + riscv,a2p-doorbell-value = <0x00008000>; + #mbox-cells = <1>; + };Signature · 1 line
2.43.0
Re: [PATCH v3 02/23] dt-bindings: mailbox: Add bindings for RPMI shared memory transport
Quoted 90 lines · Rob Herring
Quoted 75 lines · Anup Patel
Add device tree bindings for the common RISC-V Platform Management Interface (RPMI) shared memory transport as a mailbox controller.
Signed-off-by Anup Patel <[email protected]>--- .../mailbox/riscv,rpmi-shmem-mbox.yaml | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yamlDocumentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +60
-0@@ -0,0 +1,148 @@ +# 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: a2p-doorbell + - items: + - const: a2p-reqDocumentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml line 70
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +10
-0+ - const: p2a-ack + - const: p2a-req + - const: a2p-ack + - items: + - const: a2p-req + - const: p2a-ack + - const: a2p-doorbell + - items: + - const: a2p-req + - const: p2a-ackThis can all be just:
Quoted 7 lines
minItems: 2
items:
- const: a2p-req
- const: p2a-ack
- enum: [ p2a-req, a2p-doorbell ]
- const: a2p-ack
- const: a2p-doorbell
Okay, I will update.
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml line 76
Quoted 8 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +6
-0+ + interrupts: + maxItems: 1 + description: + The RPMI shared memory transport supports wired interrupt specified by + this property as the P2A doorbell."The RPMI shared memory transport P2A doorbell"
Okay, I will update.
Quoted 69 lines
Quoted 69 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +67
-0+ + msi-parent: + description: + The RPMI shared memory transport supports P2A doorbell as a system MSI + 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,a2p-doorbell-value: + $ref: /schemas/types.yaml#/definitions/uint32 + default: 0x1 + description: + Value written to the 32-bit A2P doorbell register. + + riscv,p2a-doorbell-sysmsi-index: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The RPMI shared memory transport supports P2A doorbell as a system MSI + and this property specifies system MSI index to be used for configuring + the P2A doorbell MSI. + + "#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>; + reg-names = "a2p-req", "p2a-ack"; + 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", "a2p-doorbell";
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml new file +5
-1+ msi-parent = <&imsic_mlevel>; + riscv,slot-size = <64>; + riscv,a2p-doorbell-value = <0x00008000>; + #mbox-cells = <1>; + }; --2.43.0
Thanks,
Anup
PATCH v3 3/23 dt-bindings: mailbox: Add bindings for RISC-V SBI MPXY extension
In reply to Anup PatelAdd device tree bindings for the RISC-V SBI Message Proxy (MPXY) extension as a mailbox controller.
--- .../bindings/mailbox/riscv,sbi-mpxy-mbox.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml
Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml new file +51 -0
@@ -0,0 +1,51 @@ +# 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: + 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: + - | + mailbox { + compatible = "riscv,sbi-mpxy-mbox"; + #mbox-cells = <2>; + };
Signature · 1 line
2.43.0
PATCH v3 4/23 RISC-V: Add defines for the SBI message proxy extension
In reply to Anup PatelAdd 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
@@ -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
PATCH v3 5/23 mailbox: Add common header for RPMI messages sent via mailbox
In reply to Anup PatelThe RPMI based mailbox controller drivers and mailbox clients 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
@@ -0,0 +1,206 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2025 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
PATCH v3 6/23 mailbox: Allow controller specific mapping using fwnode
In reply to Anup PatelIntroduce 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 | 48 +++++++++++++++++------------- include/linux/mailbox_controller.h | 3 ++ 2 files changed, 31 insertions(+), 20 deletions(-)
drivers/mailbox/mailbox.c +28 -20
@@ -399,35 +399,50 @@ 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; +int i, ret; -if (!dev || !dev->of_node) { -pr_debug ("%s: No owner device node\n" , __func__); +if (!dev || !dev->fwnode) { +pr_debug ("%s: No owner device\n" , __func__); +pr_debug ("%s: No owner fwnode\n" , __func__);return ERR_PTR (-ENODEV ); } - ret =of_parse_phandle_with_args (dev->of_node,"mboxes" ,"#mbox-cells" , - index, &spec); + ret =fwnode_property_get_reference_args (dev->fwnode,"mboxes" , +"#mbox-cells" ,0 , index, &fwspec);if (ret) {dev_dbg (dev,"%s: can't parse \"mboxes\" property\n" , __func__);return ERR_PTR (ret); } +memset (&spec,0 ,sizeof (spec)); +if (dev->of_node) { + spec.np =to_of_node (fwspec.fwnode); + spec.args_count = fwspec.nargs; +for (i =0 ; i < spec.args_count; i++) + spec.args[i] = fwspec.args[i]; + } +mutex_lock (&con_mutex); 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); +fwnode_handle_put (fwspec.fwnode);if (IS_ERR (chan)) {mutex_unlock (&con_mutex);
@@ -446,15 +461,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);
@@ -492,8 +500,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 ];
@@ -544,8 +552,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
@@ -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
PATCH v3 7/23 mailbox: Add RISC-V SBI message proxy (MPXY) based mailbox driver
In reply to Anup PatelAdd 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 | 987 ++++++++++++++++++++++++++ 3 files changed, 1000 insertions(+) create mode 100644 drivers/mailbox/riscv-sbi-mpxy-mbox.c
drivers/mailbox/Kconfig +11 -0
@@ -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
@@ -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 +987 -0
987 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v3 07/23] mailbox: Add RISC-V SBI message proxy (MPXY) based mailbox driver
drivers/mailbox/riscv-sbi-mpxy-mbox.c line 548
Quoted 5 lines · Anup Patel
drivers/mailbox/riscv-sbi-mpxy-mbox.c new file +5
-0+ +static irqreturn_t mpxy_mbox_irq_event (int irq,void *dev_id) +{ +/* We only have MSI for notification so just wakeup IRQ thread */ +return IRQ_WAKE_THREAD ;
I was idly reading through this because I looked at the irq chip.
This function is competely pointless.
Quoted 17 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c new file +17
-0+} + +static irqreturn_t mpxy_mbox_irq_thread (int irq,void *dev_id) +{ +mpxy_mbox_peek_data (dev_id); +return IRQ_HANDLED ; +} + +static int mpxy_mbox_setup_msi (struct mbox_chan *chan, +struct mpxy_mbox_channel *mchan) +{ +struct device *dev = mchan->mbox->dev; +int rc; + +/* Do nothing if MSI not supported */ +if (mchan->msi_irq ==U32_MAX ) +return 0 ;
drivers/mailbox/riscv-sbi-mpxy-mbox.c line 575
Quoted 10 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c new file +10
-0+ +/* Fail if MSI already enabled */ +if (mchan->attrs.msi_control) +return -EALREADY ; + +/* Request channel MSI handler */ + rc =request_threaded_irq (mchan->msi_irq, + mpxy_mbox_irq_event, + mpxy_mbox_irq_thread, +0 ,dev_name (dev), chan);
Just do:
rc = request_threaded_irq(mchan->msi_irq, NULL, mpxy_mbox_irq_thread, 0, dev_name(dev), chan);
and be done with it. The core code will happily wake up your thread.
Re: [PATCH v3 07/23] mailbox: Add RISC-V SBI message proxy (MPXY) based mailbox driver
Quoted 42 lines · Thomas Gleixner
drivers/mailbox/riscv-sbi-mpxy-mbox.c line 548
Quoted 5 lines · Anup Patel
drivers/mailbox/riscv-sbi-mpxy-mbox.c new file +5
-0+ +static irqreturn_t mpxy_mbox_irq_event (int irq,void *dev_id) +{ +/* We only have MSI for notification so just wakeup IRQ thread */ +return IRQ_WAKE_THREAD ;I was idly reading through this because I looked at the irq chip.
This function is competely pointless.
Quoted 17 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c new file +17
-0+} + +static irqreturn_t mpxy_mbox_irq_thread (int irq,void *dev_id) +{ +mpxy_mbox_peek_data (dev_id); +return IRQ_HANDLED ; +} + +static int mpxy_mbox_setup_msi (struct mbox_chan *chan, +struct mpxy_mbox_channel *mchan) +{ +struct device *dev = mchan->mbox->dev; +int rc; + +/* Do nothing if MSI not supported */ +if (mchan->msi_irq ==U32_MAX ) +return 0 ;drivers/mailbox/riscv-sbi-mpxy-mbox.c line 575
Quoted 10 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c new file +10
-0+ +/* Fail if MSI already enabled */ +if (mchan->attrs.msi_control) +return -EALREADY ; + +/* Request channel MSI handler */ + rc =request_threaded_irq (mchan->msi_irq, + mpxy_mbox_irq_event, + mpxy_mbox_irq_thread, +0 ,dev_name (dev), chan);Just do:
Quoted 4 lines
rc = request_threaded_irq(mchan->msi_irq, NULL, mpxy_mbox_irq_thread, 0, dev_name(dev), chan);and be done with it. The core code will happily wake up your thread.
I did not see the irq_default_primary_handler() set by irq core. Thanks for catching it, I will update in the next revision.
Regards,
Anup
PATCH v3 8/23 dt-bindings: clock: Add RPMI clock service message proxy bindings
In reply to Anup PatelAdd device tree bindings for the RPMI clock service group based message proxy implemented by the SBI implementation (machine mode firmware or hypervisor).
The RPMI clock service group is defined by the RISC-V platform management interface (RPMI) specification.
--- .../bindings/clock/riscv,rpmi-mpxy-clock.yaml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/riscv,rpmi-mpxy-clock.yaml
Documentation/devicetree/bindings/clock/riscv,rpmi-mpxy-clock.yaml new file +64 -0
@@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/riscv,rpmi-mpxy-clock.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: RISC-V RPMI clock service group based message proxy + +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. The SBI implementation + (machine mode firmware or hypervisor) can implement an SBI MPXY channel + to allow RPMI clock service group access to the supervisor software. + + =========================================== + 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: + description: + Intended for use by the SBI implementation. + const: riscv,rpmi-mpxy-clock + + mboxes: + maxItems: 1 + description: + Mailbox channel of the underlying RPMI transport. + + 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. + +required: + - compatible + - mboxes + - riscv,sbi-mpxy-channel-id + +additionalProperties: false + +examples: + - | + clock-controller { + compatible = "riscv,rpmi-mpxy-clock"; + mboxes = <&rpmi_shmem_mbox 0x8>; + riscv,sbi-mpxy-channel-id = <0x1000>; + }; +...
Signature · 1 line
2.43.0
PATCH v3 9/23 dt-bindings: clock: Add RPMI clock service controller bindings
In reply to Anup PatelAdd device tree bindings for the RPMI clock service group based controller for the supervisor software.
The RPMI clock service group is defined by the RISC-V platform management interface (RPMI) specification.
--- .../bindings/clock/riscv,rpmi-clock.yaml | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml
Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml new file +61 -0
@@ -0,0 +1,61 @@ +# 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. The supervisor + software can access RPMI clock service group via SBI MPXY channel or + some dedicated supervisor-mode RPMI transport. + + =========================================== + 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: + description: + Intended for use by the supervisor software. + const: riscv,rpmi-clock + + mboxes: + maxItems: 1 + description: + Mailbox channel of the underlying RPMI transport or SBI message proxy channel. + + "#clock-cells": + const: 1 + +required: + - compatible + - mboxes + - "#clock-cells" + +additionalProperties: false + +examples: + - | + clock-controller { + compatible = "riscv,rpmi-clock"; + mboxes = <&mpxy_mbox 0x1000 0x0>; + #clock-cells = <1>; + }; +...
Signature · 1 line
2.43.0
PATCH v3 10/23 clk: Add clock driver for the RISC-V RPMI clock service group
In reply to Anup PatelFrom: 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
@@ -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
@@ -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
@@ -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
Andy Shevchenko
reviewerRe: [PATCH v3 10/23] clk: Add clock driver for the RISC-V RPMI clock service group
Quoted 7 lines · 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/clk-rpmi.c line 13
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+#include <linux/clk-provider.h> +#include <linux/err.h> +#include <linux/mailbox_client.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/mailbox/riscv-rpmi-message.h>
Just to point out again that the above misses a lot of headers definitions and/or APIs this driver uses. Follow IWYU principle.
...
Quoted 1 line
+#define
GET_RATE_U64(hi_u32, lo_u32)((u64)(hi_u32) << 32 | (lo_u32))
Hmm... Perhaps add this kind of macro to wordpart.h ? IIRC not only this driver uses something like this.
...
drivers/clk/clk-rpmi.c line 28
Quoted 5 lines
drivers/clk/clk-rpmi.c new file +4
-0+enum rpmi_clk_type { +RPMI_CLK_DISCRETE =0 , +RPMI_CLK_LINEAR =1 , +RPMI_CLK_TYPE_MAX_IDX ,
No comma for the terminator. Please, clean all these cases.
Quoted 1 line
+};
...
drivers/clk/clk-rpmi.c line 44
Quoted 7 lines
drivers/clk/clk-rpmi.c new file +7
-0+union rpmi_clk_rates { +u64 discrete[RPMI_CLK_DISCRETE_MAX_NUM_RATES ]; +struct { +u64 min; +u64 max; +u64 step; + } linear;
Have you looked at the linear ranges library we have in the kernel? Can you utilise it here?
Quoted 1 line
+};
...
drivers/clk/clk-rpmi.c line 55
Quoted 9 lines
drivers/clk/clk-rpmi.c new file +9
-0+struct rpmi_clk { +struct rpmi_clk_context *context; +u32 id; +u32 num_rates; +u32 transition_latency; +enum rpmi_clk_type type; +union rpmi_clk_rates *rates; +char name[RPMI_CLK_NAME_LEN ]; +struct clk_hw hw;
Just a reminder to use pahole to check that your data layout is optimised for memory consumption.
Quoted 1 line
+};
...
drivers/clk/clk-rpmi.c line 102
Quoted 7 lines
drivers/clk/clk-rpmi.c new file +7
-0+struct rpmi_get_supp_rates_rx { +u32 status; +u32 flags; +u32 remaining; +u32 returned; +u32 rates[]; +};
Is it ABI? (I mean if this is interface with some kind of FW) If so, Use proper endianess aware types. Same Q for all data types defined in this driver.
...
drivers/clk/clk-rpmi.c line 245
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+for (j =0 ; j < rx->returned; j++) { +if (rateidx >= (clk_rate_idx + rx->returned))
Too many parentheses.
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+break ; + rpmi_clk->rates->discrete[rateidx++] = +GET_RATE_U64 (rate_discrete[j].hi, + rate_discrete[j].lo); + } + }
...
drivers/clk/clk-rpmi.c line 266
Quoted 1 line
drivers/clk/clk-rpmi.c new file +1
-0+devm_kfree (context->dev, rx);
Why?! This is a red flag to point that here is misunderstanding or abuse of managed resources approach. Either use __Free() from cleanup.h or don't call devm_kfree(). The latter must have a very good justification to explain why.
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;
(this is even not an error path, where it might have a little argument for)
...
drivers/clk/clk-rpmi.c line 302
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+/* Keep the requested rate if the clock format +* is of discrete type. Let the platform which +* is actually controlling the clock handle that. +*/
/*
* Use proper style for the multi-line comments. You can
* refer to this comment as an example.
*/
...
Quoted 1 line
+out:
Redundant label. Note, the labels are recommended to be named after the flow they will run if goto. This one can be named as out_literally_with_return_0, which makes it obvious how useless it is.
Quoted 1 line
(quoted diff) +1
-0+ return 0;
...
drivers/clk/clk-rpmi.c line 411
Quoted 1 line
drivers/clk/clk-rpmi.c new file +1
-0+ rates =devm_kzalloc (dev,sizeof (union rpmi_clk_rates ),GFP_KERNEL );
sizeof(*...)
drivers/clk/clk-rpmi.c line 415
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+if (!rates) +return ERR_PTR (-ENOMEM ); + + rpmi_clk =devm_kzalloc (dev,sizeof (struct rpmi_clk ),GFP_KERNEL );
Ditto.
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+if (!rpmi_clk) +return ERR_PTR (-ENOMEM );
...
drivers/clk/clk-rpmi.c line 430
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+ ret =rpmi_clk_get_supported_rates (clkid, rpmi_clk); +if (ret) +return dev_err_ptr_probe (dev, ret, +"Get supported rates failed for clk-%u, %d\n" , clkid, ret);
Indentation issues. Repetitive ret in the message. Please, get familiar with the format dev_err_probe() uses.
...
drivers/clk/clk-rpmi.c line 462
Quoted 1 line
drivers/clk/clk-rpmi.c new file +1
-0+int ret, num_clocks, i;
Why is 'i' signed?
...
drivers/clk/clk-rpmi.c line 466
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+/* Allocate RPMI clock context */ + context =devm_kzalloc (dev,sizeof (*context),GFP_KERNEL );
Ha-ha, you have even inconsistent style in the same file! So, go through the whole series and make sure that the style used in each file is consistent.
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+if (!context) +return -ENOMEM ;
...
drivers/clk/clk-rpmi.c line 489
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+/* Validate RPMI specification version */ +rpmi_mbox_init_get_attribute (&msg,RPMI_MBOX_ATTR_SPEC_VERSION ); + ret =rpmi_mbox_send_message (context->chan, &msg); +if (ret) { +dev_err_probe (dev, ret,"Failed to get spec version\n" ); + goto fail_free_channel;
This is simply wrong. You should not do goto before any devm_*() calls. The error path and ->remove(), if present) is broken. Fix it accordingly.
Here should be
return dev_err_probe(...);
it's your homework to understand how to achieve that. Plenty of the examples in the kernel.
Quoted 1 line
(quoted diff) +1
-0+ }
...
include/linux/mailbox/riscv-rpmi-message.h static inline int rpmi_to_linux_error(int rpmi_error) · line 105
Quoted 11 lines
include/linux/mailbox/riscv-rpmi-message.h +10
-0+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 ,
No comma in the terminator line.
Quoted 1 line
+};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 10/23] clk: Add clock driver for the RISC-V RPMI clock service group
Quoted 12 lines · Andy Shevchenko
Quoted 7 lines · 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.
...
Quoted 9 lines
drivers/clk/clk-rpmi.c line 13
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+#include <linux/clk-provider.h> +#include <linux/err.h> +#include <linux/mailbox_client.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/mailbox/riscv-rpmi-message.h> Just to point out again that the above misses a lot of headers definitions and/or APIs this driver uses. Follow IWYU principle.
Sure
Quoted 8 lines
...
Quoted 1 line
+#define
GET_RATE_U64(hi_u32, lo_u32)((u64)(hi_u32) << 32 | (lo_u32))Hmm... Perhaps add this kind of macro to
wordpart.h? IIRC not only this driver uses something like this.
Sure, it makes sense.
Quoted 9 lines
...
drivers/clk/clk-rpmi.c line 28
Quoted 5 lines
drivers/clk/clk-rpmi.c new file +4
-0+enum rpmi_clk_type { +RPMI_CLK_DISCRETE =0 , +RPMI_CLK_LINEAR =1 , +RPMI_CLK_TYPE_MAX_IDX ,No comma for the terminator. Please, clean all these cases.
Sure
Quoted 13 lines
Quoted 2 lines
+};
...
drivers/clk/clk-rpmi.c line 44
Quoted 7 lines
drivers/clk/clk-rpmi.c new file +7
-0+union rpmi_clk_rates { +u64 discrete[RPMI_CLK_DISCRETE_MAX_NUM_RATES ]; +struct { +u64 min; +u64 max; +u64 step; + } linear;
Quoted 2 lines
Have you looked at the linear ranges library we have in the kernel? Can you utilise it here?
Ok, i will check
Quoted 15 lines
Quoted 2 lines
+};
...
drivers/clk/clk-rpmi.c line 55
Quoted 9 lines
drivers/clk/clk-rpmi.c new file +9
-0+struct rpmi_clk { +struct rpmi_clk_context *context; +u32 id; +u32 num_rates; +u32 transition_latency; +enum rpmi_clk_type type; +union rpmi_clk_rates *rates; +char name[RPMI_CLK_NAME_LEN ]; +struct clk_hw hw;
Quoted 2 lines
Just a reminder to use
paholeto check that your data layout is optimised for memory consumption.
Ok, i will check
Quoted 5 lines
Quoted 2 lines
+};
...
Quoted 11 lines
drivers/clk/clk-rpmi.c line 102
Quoted 7 lines
drivers/clk/clk-rpmi.c new file +7
-0+struct rpmi_get_supp_rates_rx { +u32 status; +u32 flags; +u32 remaining; +u32 returned; +u32 rates[]; +};Is it ABI? (I mean if this is interface with some kind of FW) If so, Use proper endianess aware types. Same Q for all data types defined in this driver.
Sure.
It's the message format defined by the RISC-V RPMI spec.
Quoted 7 lines
...
drivers/clk/clk-rpmi.c line 245
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+for (j =0 ; j < rx->returned; j++) { +if (rateidx >= (clk_rate_idx + rx->returned))Too many parentheses.
Ok, will remove
Quoted 8 lines
drivers/clk/clk-rpmi.c line 251
Quoted 7 lines
drivers/clk/clk-rpmi.c new file +6
-0+break ; + rpmi_clk->rates->discrete[rateidx++] = +GET_RATE_U64 (rate_discrete[j].hi, + rate_discrete[j].lo); + } + }
Quoted 7 lines
...
Quoted 1 line
+
devm_kfree(context->dev, rx);Why?! This is a red flag to point that here is misunderstanding or abuse of managed resources approach. Either use
__Free()fromcleanup.hor don't calldevm_kfree(). The latter must have a very good justification to explain why.
Yeah, I think it's better to use kzalloc for this case and then free it.
Quoted 7 lines
Quoted 2 lines
+ return 0;
(this is even not an error path, where it might have a little argument for)
...
Quoted 8 lines
drivers/clk/clk-rpmi.c line 302
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+/* Keep the requested rate if the clock format +* is of discrete type. Let the platform which +* is actually controlling the clock handle that. +*/ /*
* Use proper style for the multi-line comments. You can
* refer to this comment as an example.
Yes, I will correct it.
Quoted 9 lines
*/
...
Quoted 1 line
+out:
Redundant label. Note, the labels are recommended to be named after the flow they will run if goto. This one can be named as
out_literally_with_return_0, which makes it obvious how useless it is.
I will improve the flow.
Quoted 21 lines
Quoted 2 lines
+ return 0;
...
Quoted 1 line
+ rates =
devm_kzalloc(dev, sizeof(union rpmi_clk_rates), GFP_KERNEL);
sizeof(*...)drivers/clk/clk-rpmi.c line 415
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+if (!rates) +return ERR_PTR (-ENOMEM ); + + rpmi_clk =devm_kzalloc (dev,sizeof (struct rpmi_clk ),GFP_KERNEL );Ditto.
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+if (!rpmi_clk) +return ERR_PTR (-ENOMEM );...
Quoted 7 lines
drivers/clk/clk-rpmi.c line 430
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+ ret =rpmi_clk_get_supported_rates (clkid, rpmi_clk); +if (ret) +return dev_err_ptr_probe (dev, ret, +"Get supported rates failed for clk-%u, %d\n" , clkid, ret);Indentation issues. Repetitive ret in the message. Please, get familiar with the format
dev_err_probe()uses.
Ok, I will correct.
Quoted 6 lines
...
Quoted 1 line
+ int ret,
num_clocks, i;Why is 'i' signed?
This and num_clocks can be unsigned, will change.
Quoted 8 lines
...
drivers/clk/clk-rpmi.c line 466
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+/* Allocate RPMI clock context */ + context =devm_kzalloc (dev,sizeof (*context),GFP_KERNEL );Ha-ha, you have even inconsistent style in the same file! So, go through the whole series and make sure that the style used in each file is consistent.
Yeah, that's because there are multiple devs in this series. I will improve that.
Quoted 16 lines
Quoted 3 lines
drivers/clk/clk-rpmi.c new file +2
-0+if (!context) +return -ENOMEM ;...
drivers/clk/clk-rpmi.c line 489
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+/* Validate RPMI specification version */ +rpmi_mbox_init_get_attribute (&msg,RPMI_MBOX_ATTR_SPEC_VERSION ); + ret =rpmi_mbox_send_message (context->chan, &msg); +if (ret) { +dev_err_probe (dev, ret,"Failed to get spec version\n" ); + goto fail_free_channel;This is simply wrong. You should not do goto before any devm_*() calls. The error path and ->remove(), if present) is broken. Fix it accordingly.
Quoted 7 lines
Here should be
return dev_err_probe(...);it's your homework to understand how to achieve that. Plenty of the examples in the kernel.
Sure
Quoted 14 lines
Quoted 1 line
+ }
...
Quoted 9 lines
include/linux/mailbox/riscv-rpmi-message.h +9
-0+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 ,
Quoted 3 lines
Quoted 1 line
+
RPMI_CLK_SRV_ID_MAX_COUNT,No comma in the terminator line.
Ok
Quoted 8 lines
Quoted 2 lines
+};
--
With Best Regards,
Andy Shevchenko
Thanks
Rahul Pathak
Andy Shevchenko
reviewerRe: [PATCH v3 10/23] clk: Add clock driver for the RISC-V RPMI clock service group
Quoted 3 lines · Rahul Pathak
Quoted 1 line · Andy Shevchenko
On Sun, May 11, 2025 at 07:09:26PM +0530, Anup Patel wrote:
...
Quoted 12 lines
Quoted 11 lines
drivers/clk/clk-rpmi.c line 102
Quoted 7 lines
drivers/clk/clk-rpmi.c new file +7
-0+struct rpmi_get_supp_rates_rx { +u32 status; +u32 flags; +u32 remaining; +u32 returned; +u32 rates[]; +};Is it ABI? (I mean if this is interface with some kind of FW) If so, Use proper endianess aware types. Same Q for all data types defined in this driver.
Quoted 3 lines
Sure.
It's the message format defined by the RISC-V RPMI spec.
So, use the endianess as provided. Or is it always native endianess?
...
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
+
devm_kfree(context->dev, rx);Why?! This is a red flag to point that here is misunderstanding or abuse of managed resources approach. Either use
__Free()fromcleanup.hor don't calldevm_kfree(). The latter must have a very good justification to explain why.Yeah, I think it's better to use kzalloc for this case and then free it.
Instead of freeing it explicitly consider using cleanup.h, i.e. __free().
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 10/23] clk: Add clock driver for the RISC-V RPMI clock service group
In reply to Andy ShevchenkoHi Andy
Quoted 190 lines · Andy Shevchenko
Quoted 7 lines · 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/clk-rpmi.c line 13
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+#include <linux/clk-provider.h> +#include <linux/err.h> +#include <linux/mailbox_client.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/mailbox/riscv-rpmi-message.h> Just to point out again that the above misses a lot of headers definitions and/or APIs this driver uses. Follow IWYU principle.
...
Quoted 1 line
+#define
GET_RATE_U64(hi_u32, lo_u32)((u64)(hi_u32) << 32 | (lo_u32))Hmm... Perhaps add this kind of macro to
wordpart.h? IIRC not only this driver uses something like this....
drivers/clk/clk-rpmi.c line 28
Quoted 5 lines
drivers/clk/clk-rpmi.c new file +4
-0+enum rpmi_clk_type { +RPMI_CLK_DISCRETE =0 , +RPMI_CLK_LINEAR =1 , +RPMI_CLK_TYPE_MAX_IDX ,No comma for the terminator. Please, clean all these cases.
Quoted 1 line
+};
...
drivers/clk/clk-rpmi.c line 44
Quoted 7 lines
drivers/clk/clk-rpmi.c new file +7
-0+union rpmi_clk_rates { +u64 discrete[RPMI_CLK_DISCRETE_MAX_NUM_RATES ]; +struct { +u64 min; +u64 max; +u64 step; + } linear;Have you looked at the linear ranges library we have in the kernel? Can you utilise it here?
Quoted 1 line
+};
...
drivers/clk/clk-rpmi.c line 55
Quoted 9 lines
drivers/clk/clk-rpmi.c new file +9
-0+struct rpmi_clk { +struct rpmi_clk_context *context; +u32 id; +u32 num_rates; +u32 transition_latency; +enum rpmi_clk_type type; +union rpmi_clk_rates *rates; +char name[RPMI_CLK_NAME_LEN ]; +struct clk_hw hw;Just a reminder to use
paholeto check that your data layout is optimised for memory consumption.Quoted 1 line
+};
...
drivers/clk/clk-rpmi.c line 102
Quoted 7 lines
drivers/clk/clk-rpmi.c new file +7
-0+struct rpmi_get_supp_rates_rx { +u32 status; +u32 flags; +u32 remaining; +u32 returned; +u32 rates[]; +};Is it ABI? (I mean if this is interface with some kind of FW) If so, Use proper endianess aware types. Same Q for all data types defined in this driver.
...
drivers/clk/clk-rpmi.c line 245
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+for (j =0 ; j < rx->returned; j++) { +if (rateidx >= (clk_rate_idx + rx->returned))Too many parentheses.
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+break ; + rpmi_clk->rates->discrete[rateidx++] = +GET_RATE_U64 (rate_discrete[j].hi, + rate_discrete[j].lo); + } + }...
Quoted 1 line
+
devm_kfree(context->dev, rx);Why?! This is a red flag to point that here is misunderstanding or abuse of managed resources approach. Either use
__Free()fromcleanup.hor don't calldevm_kfree(). The latter must have a very good justification to explain why.Quoted 1 line
+ return 0;
(this is even not an error path, where it might have a little argument for)
...
drivers/clk/clk-rpmi.c line 302
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+/* Keep the requested rate if the clock format +* is of discrete type. Let the platform which +* is actually controlling the clock handle that. +*/ /*
* Use proper style for the multi-line comments. You can
* refer to this comment as an example.
*/...
Quoted 1 line
+out:
Redundant label. Note, the labels are recommended to be named after the flow they will run if goto. This one can be named as
out_literally_with_return_0, which makes it obvious how useless it is.Quoted 1 line
+ return 0;
...
Quoted 1 line
+ rates =
devm_kzalloc(dev, sizeof(union rpmi_clk_rates), GFP_KERNEL);
sizeof(*...)drivers/clk/clk-rpmi.c line 415
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+if (!rates) +return ERR_PTR (-ENOMEM ); + + rpmi_clk =devm_kzalloc (dev,sizeof (struct rpmi_clk ),GFP_KERNEL );Ditto.
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+if (!rpmi_clk) +return ERR_PTR (-ENOMEM );...
drivers/clk/clk-rpmi.c line 430
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+ ret =rpmi_clk_get_supported_rates (clkid, rpmi_clk); +if (ret) +return dev_err_ptr_probe (dev, ret, +"Get supported rates failed for clk-%u, %d\n" , clkid, ret);Indentation issues. Repetitive ret in the message. Please, get familiar with the format
dev_err_probe()uses....
Quoted 1 line
+ int ret,
num_clocks, i;Why is 'i' signed?
...
drivers/clk/clk-rpmi.c line 466
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+/* Allocate RPMI clock context */ + context =devm_kzalloc (dev,sizeof (*context),GFP_KERNEL );Ha-ha, you have even inconsistent style in the same file! So, go through the whole series and make sure that the style used in each file is consistent.
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+if (!context) +return -ENOMEM ;...
drivers/clk/clk-rpmi.c line 489
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+/* Validate RPMI specification version */ +rpmi_mbox_init_get_attribute (&msg,RPMI_MBOX_ATTR_SPEC_VERSION ); + ret =rpmi_mbox_send_message (context->chan, &msg); +if (ret) { +dev_err_probe (dev, ret,"Failed to get spec version\n" ); + goto fail_free_channel;This is simply wrong. You should not do goto before any devm_*() calls. The error path and ->remove(), if present) is broken. Fix it accordingly.
Quoted 6 lines
Here should be
return dev_err_probe(...);it's your homework to understand how to achieve that. Plenty of the examples in the kernel.
So far I could only find drivers with "goto used before devm_*" pattern used. Can you please point me to the example which does not use goto before devm_* apis.
Also, I couldn't understand the problem which may happen because of this. Can you
please explain?
Quoted 26 lines
Quoted 2 lines
+ }
...
include/linux/mailbox/riscv-rpmi-message.h static inline int rpmi_to_linux_error(int rpmi_error) · line 105
Quoted 11 lines
include/linux/mailbox/riscv-rpmi-message.h +10
-0+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 ,No comma in the terminator line.
Quoted 1 line
+};
--
With Best Regards,
Andy Shevchenko
Signature · 4 lines
Thanks Rahul Pathak On Mon, May 12, 2025 at 12:38 PM Andy Shevchenko
Quoted 222 lines · <[email protected]> wrote:
Quoted 7 lines · 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/clk-rpmi.c line 13
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+#include <linux/clk-provider.h> +#include <linux/err.h> +#include <linux/mailbox_client.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/mailbox/riscv-rpmi-message.h> Just to point out again that the above misses a lot of headers definitions and/or APIs this driver uses. Follow IWYU principle.
...
Quoted 1 line
+#define
GET_RATE_U64(hi_u32, lo_u32)((u64)(hi_u32) << 32 | (lo_u32))Hmm... Perhaps add this kind of macro to
wordpart.h? IIRC not only this driver uses something like this....
drivers/clk/clk-rpmi.c line 28
Quoted 5 lines
drivers/clk/clk-rpmi.c new file +4
-0+enum rpmi_clk_type { +RPMI_CLK_DISCRETE =0 , +RPMI_CLK_LINEAR =1 , +RPMI_CLK_TYPE_MAX_IDX ,No comma for the terminator. Please, clean all these cases.
Quoted 1 line
+};
...
drivers/clk/clk-rpmi.c line 44
Quoted 7 lines
drivers/clk/clk-rpmi.c new file +7
-0+union rpmi_clk_rates { +u64 discrete[RPMI_CLK_DISCRETE_MAX_NUM_RATES ]; +struct { +u64 min; +u64 max; +u64 step; + } linear;Have you looked at the linear ranges library we have in the kernel? Can you utilise it here?
Quoted 1 line
+};
...
drivers/clk/clk-rpmi.c line 55
Quoted 9 lines
drivers/clk/clk-rpmi.c new file +9
-0+struct rpmi_clk { +struct rpmi_clk_context *context; +u32 id; +u32 num_rates; +u32 transition_latency; +enum rpmi_clk_type type; +union rpmi_clk_rates *rates; +char name[RPMI_CLK_NAME_LEN ]; +struct clk_hw hw;Just a reminder to use
paholeto check that your data layout is optimised for memory consumption.Quoted 1 line
+};
...
drivers/clk/clk-rpmi.c line 102
Quoted 7 lines
drivers/clk/clk-rpmi.c new file +7
-0+struct rpmi_get_supp_rates_rx { +u32 status; +u32 flags; +u32 remaining; +u32 returned; +u32 rates[]; +};Is it ABI? (I mean if this is interface with some kind of FW) If so, Use proper endianess aware types. Same Q for all data types defined in this driver.
...
drivers/clk/clk-rpmi.c line 245
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+for (j =0 ; j < rx->returned; j++) { +if (rateidx >= (clk_rate_idx + rx->returned))Too many parentheses.
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+break ; + rpmi_clk->rates->discrete[rateidx++] = +GET_RATE_U64 (rate_discrete[j].hi, + rate_discrete[j].lo); + } + }...
Quoted 1 line
+
devm_kfree(context->dev, rx);Why?! This is a red flag to point that here is misunderstanding or abuse of managed resources approach. Either use
__Free()fromcleanup.hor don't calldevm_kfree(). The latter must have a very good justification to explain why.Quoted 1 line
+ return 0;
(this is even not an error path, where it might have a little argument for)
...
drivers/clk/clk-rpmi.c line 302
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+/* Keep the requested rate if the clock format +* is of discrete type. Let the platform which +* is actually controlling the clock handle that. +*/ /*
* Use proper style for the multi-line comments. You can
* refer to this comment as an example.
*/...
Quoted 1 line
+out:
Redundant label. Note, the labels are recommended to be named after the flow they will run if goto. This one can be named as
out_literally_with_return_0, which makes it obvious how useless it is.Quoted 1 line
+ return 0;
...
Quoted 1 line
+ rates =
devm_kzalloc(dev, sizeof(union rpmi_clk_rates), GFP_KERNEL);
sizeof(*...)drivers/clk/clk-rpmi.c line 415
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+if (!rates) +return ERR_PTR (-ENOMEM ); + + rpmi_clk =devm_kzalloc (dev,sizeof (struct rpmi_clk ),GFP_KERNEL );Ditto.
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+if (!rpmi_clk) +return ERR_PTR (-ENOMEM );...
drivers/clk/clk-rpmi.c line 430
Quoted 4 lines
drivers/clk/clk-rpmi.c new file +4
-0+ ret =rpmi_clk_get_supported_rates (clkid, rpmi_clk); +if (ret) +return dev_err_ptr_probe (dev, ret, +"Get supported rates failed for clk-%u, %d\n" , clkid, ret);Indentation issues. Repetitive ret in the message. Please, get familiar with the format
dev_err_probe()uses....
Quoted 1 line
+ int ret,
num_clocks, i;Why is 'i' signed?
...
drivers/clk/clk-rpmi.c line 466
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+/* Allocate RPMI clock context */ + context =devm_kzalloc (dev,sizeof (*context),GFP_KERNEL );Ha-ha, you have even inconsistent style in the same file! So, go through the whole series and make sure that the style used in each file is consistent.
Quoted 2 lines
drivers/clk/clk-rpmi.c new file +2
-0+if (!context) +return -ENOMEM ;...
drivers/clk/clk-rpmi.c line 489
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+/* Validate RPMI specification version */ +rpmi_mbox_init_get_attribute (&msg,RPMI_MBOX_ATTR_SPEC_VERSION ); + ret =rpmi_mbox_send_message (context->chan, &msg); +if (ret) { +dev_err_probe (dev, ret,"Failed to get spec version\n" ); + goto fail_free_channel;This is simply wrong. You should not do goto before any devm_*() calls. The error path and ->remove(), if present) is broken. Fix it accordingly.
Here should be
return dev_err_probe(...);it's your homework to understand how to achieve that. Plenty of the examples in the kernel.
Quoted 1 line
+ }
...
include/linux/mailbox/riscv-rpmi-message.h static inline int rpmi_to_linux_error(int rpmi_error) · line 105
Quoted 11 lines
include/linux/mailbox/riscv-rpmi-message.h +10
-0+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 ,No comma in the terminator line.
Quoted 1 line
+};
--
With Best Regards,
Andy Shevchenko
Signature · 2 lines
Thanks Rahul Pathak
Andy Shevchenko
reviewerRe: [PATCH v3 10/23] clk: Add clock driver for the RISC-V RPMI clock service group
Quoted 3 lines · Rahul Pathak
Quoted 1 line · Andy Shevchenko
On Sun, May 11, 2025 at 07:09:26PM +0530, Anup Patel wrote:
First of all, remove all unneeded context with which you are agree. I should not crawl through dozens of lines of the email to see what you wanted to discuss. Take it as everyday practice, please.
...
Quoted 10 lines
Quoted 10 lines
drivers/clk/clk-rpmi.c line 489
Quoted 6 lines
drivers/clk/clk-rpmi.c new file +6
-0+/* Validate RPMI specification version */ +rpmi_mbox_init_get_attribute (&msg,RPMI_MBOX_ATTR_SPEC_VERSION ); + ret =rpmi_mbox_send_message (context->chan, &msg); +if (ret) { +dev_err_probe (dev, ret,"Failed to get spec version\n" ); + goto fail_free_channel;This is simply wrong. You should not do goto before any devm_*() calls. The error path and ->remove(), if present) is broken. Fix it accordingly.
Quoted 8 lines
Quoted 6 lines
Here should be
return dev_err_probe(...);it's your homework to understand how to achieve that. Plenty of the examples in the kernel.
So far I could only find drivers with "goto used before devm_*" pattern used.
Of course, because they are wrong and most of them need fixing. (Yes, there are some exceptional cases, but I don't believe it's many)
Quoted 2 lines
Can you please point me to the example which does not use goto before devm_* apis.
Tons of them, any which starts with devm_*() call in the probe, most of the drivers/iio/, for instance. Just a random pick here: drivers/iio/accel/bma400*.
(and FWIW it was indeed the very first driver I was looking into while writing
this email)
Quoted 2 lines
Also, I couldn't understand the problem which may happen because of this. Can you please explain?
devm_*() defers the resource deallocation to the end of ->remove() and error path in ->probe(). This breaks the symmetry of the allocating / deallocating resources. At worst case it will be an Oops on ->remove() or when error happens during the ->probe().
...
My gosh, the original text was quoted twice! Next time I won't even look into the email reply which won't have a reduced context.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 11/23 dt-bindings: Add RPMI system MSI message proxy bindings
In reply to Anup PatelAdd device tree bindings for the RPMI system MSI service group based message proxy implemented by the SBI implementation (machine mode firmware or hypervisor).
The RPMI system MSI service group is defined by the RISC-V platform management interface (RPMI) specification.
--- .../riscv,rpmi-mpxy-system-msi.yaml | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-mpxy-system-msi.yaml
Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-mpxy-system-msi.yaml new file +67 -0
@@ -0,0 +1,67 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/interrupt-controller/riscv,rpmi-mpxy-system-msi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: RISC-V RPMI system MSI service group based message proxy + +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. + The SBI implementation machine mode firmware or hypervisor) can + implement an SBI MPXY channel to allow RPMI system MSI service + group access to the supervisor software. + + =========================================== + 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: + description: + Intended for use by the SBI implementation. + const: riscv,rpmi-mpxy-system-msi + + mboxes: + maxItems: 1 + description: + Mailbox channel of the underlying RPMI transport. + + 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. + +required: + - compatible + - mboxes + - riscv,sbi-mpxy-channel-id + +additionalProperties: false + +examples: + - | + interrupt-controller { + compatible = "riscv,rpmi-mpxy-system-msi"; + mboxes = <&rpmi_shmem_mbox 0x2>; + riscv,sbi-mpxy-channel-id = <0x2000>; + }; +...
Signature · 1 line
2.43.0
PATCH v3 12/23 dt-bindings: Add RPMI system MSI interrupt controller bindings
In reply to Anup PatelAdd device tree bindings for the RPMI system MSI service group based interrupt controller for the supervisor software.
The RPMI system MSI service group is defined by the RISC-V platform management interface (RPMI) specification.
--- .../riscv,rpmi-system-msi.yaml | 74 +++++++++++++++++++ 1 file changed, 74 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 +74 -0
@@ -0,0 +1,74 @@ +# 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. + The supervisor software can access RPMI system MSI service group via + SBI MPXY channel or some dedicated supervisor-mode RPMI transport. + + =========================================== + 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: + description: + Intended for use by the supervisor software. + const: riscv,rpmi-system-msi + + mboxes: + maxItems: 1 + description: + Mailbox channel of the underlying RPMI transport or SBI message proxy channel. + + msi-parent: true + + interrupt-controller: true + + "#interrupt-cells": + const: 1 + +required: + - compatible + - mboxes + - msi-parent + - interrupt-controller + - "#interrupt-cells" + +additionalProperties: false + +examples: + - | + 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
PATCH v3 13/23 irqchip: Add driver for the RPMI system MSI service group
In reply to Anup PatelThe 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 | 280 +++++++++++++++++++++ include/linux/mailbox/riscv-rpmi-message.h | 13 + 4 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-riscv-rpmi-sysmsi.c
drivers/irqchip/Kconfig +7 -0
@@ -612,6 +612,13 @@ config RISCV_IMSIC select GENERIC_MSI_IRQ select IRQ_MSI_LIB +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
@@ -102,6 +102,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 +280 -0
280 lines not on this page · raw message
include/linux/mailbox/riscv-rpmi-message.h +13 -0
@@ -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
Andy Shevchenko
reviewerRe: [PATCH v3 13/23] irqchip: Add driver for the RPMI system MSI service group
Quoted 7 lines · 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.
...
Quoted 3 lines
+/*
+ * Copyright (C) 2025 Ventana Micro Systems Inc.
+ */
It can occupy a single line instead of 3 LoCs.
...
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 18
Quoted 13 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +13
-0+#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/cpu.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/mailbox_client.h> +#include <linux/mailbox/riscv-rpmi-message.h> +#include <linux/module.h> +#include <linux/msi.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> +#include <linux/printk.h> +#include <linux/smp.h>
+ types.h
Actually this one is most clean, the rest of the patches where the new code is introduced has semi-random list of the inclusions, please, follow the IWYU principle.
...
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 126
Quoted 6 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +6
-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_set_msi_state (priv, d->hwirq,0 );
Please, use the respective getter and the type:
irq_hw_number_t hwirq = irqd_to_hwirq(d);
Ditto for all other similar cases.
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 129
Quoted 3 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +3
-0+if (ret) { +dev_warn (priv->dev,"Failed to mask hwirq %d (error %d)\n" , + (u32 )d->hwirq, ret);
No, this is wrong in two ways: usage of specified for signed value and passing the unsigned; using explicit casting to something unsigned. Instead ofa the explicit casting, find the best formatting specifier and use it.
Ditto for all your code.
Quoted 3 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +3
-0+ } +irq_chip_mask_parent (d); +}
...
Quoted 19 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +19
-0+static int rpmi_sysmsi_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct rpmi_sysmsi_priv *priv; +int rc; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + priv->dev = dev; +platform_set_drvdata (pdev, priv); + +/* Setup mailbox client */ + priv->client.dev = priv->dev; + priv->client.rx_callback =NULL ; + priv->client.tx_block = false; + priv->client.knows_txdone = true; + priv->client.tx_tout =0 ; +
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 239
Quoted 10 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +10
-0+/* Request mailbox channel */ + priv->chan =mbox_request_channel (&priv->client,0 ); +if (IS_ERR (priv->chan)) +return PTR_ERR (priv->chan); + +/* Get number of system MSIs */ + rc =rpmi_sysmsi_get_num_msi (priv); +if (rc <1 ) { +mbox_free_channel (priv->chan); +return dev_err_probe (dev, -ENODEV ,"No system MSIs found\n" );
Can rc be negative holding an error code? If so, why does the code shadow that?
Quoted 27 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +27
-0+ } + priv->nr_irqs = rc; + +/* Set the device MSI domain if not available */ +if (!dev_get_msi_domain (dev)) { +/* +* The device MSI domain for OF devices is only set at the +* time of populating/creating OF device. If the device MSI +* domain is discovered later after the OF device is created +* then we need to set it explicitly before using any platform +* MSI functions. +*/ +if (is_of_node (dev_fwnode (dev))) +of_msi_configure (dev,to_of_node (dev_fwnode (dev))); + +if (!dev_get_msi_domain (dev)) +return -EPROBE_DEFER ; + } + +if (!msi_create_device_irq_domain (dev,MSI_DEFAULT_DOMAIN , + &rpmi_sysmsi_template, + priv->nr_irqs, priv, priv)) +return dev_err_probe (dev, -ENOMEM ,"failed to create MSI irq domain\n" ); + +dev_info (dev,"%d system MSIs registered\n" , priv->nr_irqs); +return 0 ; +}
...
Quoted 1 line
+/** RPMI system MSI service IDs */
Why does this have a kernel-doc marker?
include/linux/mailbox/riscv-rpmi-message.h enum rpmi_clock_service_id { · line 117
Quoted 8 lines
include/linux/mailbox/riscv-rpmi-message.h +8
-0+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 ,
Please, be consistent in the style of values.
include/linux/mailbox/riscv-rpmi-message.h enum rpmi_clock_service_id { · line 118
Quoted 1 line
include/linux/mailbox/riscv-rpmi-message.h +1
-0+ RPMI_SYSMSI_SRV_ID_MAX_COUNT,
No comma in the terminator entry.
Quoted 1 line
+};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 13/23] irqchip: Add driver for the RPMI system MSI service group
Quoted 10 lines · Andy Shevchenko
Quoted 7 lines · 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.
Quoted 7 lines
...
Quoted 3 lines
+/*
+ * Copyright (C) 2025 Ventana Micro Systems Inc.
+ */It can occupy a single line instead of 3 LoCs.
Okay, I will update.
Quoted 19 lines
...
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 18
Quoted 13 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +13
-0+#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/cpu.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/mailbox_client.h> +#include <linux/mailbox/riscv-rpmi-message.h> +#include <linux/module.h> +#include <linux/msi.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> +#include <linux/printk.h> +#include <linux/smp.h> +
types.h
Quoted 3 lines
Actually this one is most clean, the rest of the patches where the new code is introduced has semi-random list of the inclusions, please, follow the IWYU principle.
Sure, I will simplify the #includes
Quoted 11 lines
...
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 126
Quoted 6 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +6
-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_set_msi_state (priv, d->hwirq,0 );Please, use the respective getter and the type:
Okay
Quoted 9 lines
irq_hw_number_t hwirq = irqd_to_hwirq(d);Ditto for all other similar cases.
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 129
Quoted 3 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +3
-0+if (ret) { +dev_warn (priv->dev,"Failed to mask hwirq %d (error %d)\n" , + (u32 )d->hwirq, ret);
Quoted 6 lines
No, this is wrong in two ways: usage of specified for signed value and passing the unsigned; using explicit casting to something unsigned. Instead ofa the explicit casting, find the best formatting specifier and use it.
Ditto for all your code.
Okay, I will update.
Quoted 30 lines
Quoted 4 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +3
-0+ } +irq_chip_mask_parent (d); +}...
Quoted 23 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +23
-0+static int rpmi_sysmsi_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct rpmi_sysmsi_priv *priv; +int rc; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + priv->dev = dev; +platform_set_drvdata (pdev, priv); + +/* Setup mailbox client */ + priv->client.dev = priv->dev; + priv->client.rx_callback =NULL ; + priv->client.tx_block = false; + priv->client.knows_txdone = true; + priv->client.tx_tout =0 ; + +/* Request mailbox channel */ + priv->chan =mbox_request_channel (&priv->client,0 ); +if (IS_ERR (priv->chan)) +return PTR_ERR (priv->chan);
Quoted 8 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 239
Quoted 6 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +6
-0+ +/* Get number of system MSIs */ + rc =rpmi_sysmsi_get_num_msi (priv); +if (rc <1 ) { +mbox_free_channel (priv->chan); +return dev_err_probe (dev, -ENODEV ,"No system MSIs found\n" );Can rc be negative holding an error code? If so, why does the code shadow that?
Ahh yes, we should print a different error message when rc < 0. I will update.
Quoted 31 lines
Quoted 28 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +27
-0+ } + priv->nr_irqs = rc; + +/* Set the device MSI domain if not available */ +if (!dev_get_msi_domain (dev)) { +/* +* The device MSI domain for OF devices is only set at the +* time of populating/creating OF device. If the device MSI +* domain is discovered later after the OF device is created +* then we need to set it explicitly before using any platform +* MSI functions. +*/ +if (is_of_node (dev_fwnode (dev))) +of_msi_configure (dev,to_of_node (dev_fwnode (dev))); + +if (!dev_get_msi_domain (dev)) +return -EPROBE_DEFER ; + } + +if (!msi_create_device_irq_domain (dev,MSI_DEFAULT_DOMAIN , + &rpmi_sysmsi_template, + priv->nr_irqs, priv, priv)) +return dev_err_probe (dev, -ENOMEM ,"failed to create MSI irq domain\n" ); + +dev_info (dev,"%d system MSIs registered\n" , priv->nr_irqs); +return 0 ; +}...
Quoted 3 lines
Quoted 1 line
+/** RPMI system MSI service IDs */
Why does this have a kernel-doc marker?
Okay, I will use "/* */".
Quoted 11 lines
include/linux/mailbox/riscv-rpmi-message.h enum rpmi_clock_service_id { · line 117
Quoted 9 lines
include/linux/mailbox/riscv-rpmi-message.h +8
-0+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 ,Please, be consistent in the style of values.
Okay, I will update.
Quoted 4 lines
Quoted 2 lines
+
RPMI_SYSMSI_SRV_ID_MAX_COUNT,No comma in the terminator entry.
Okay.
Quoted 8 lines
Quoted 2 lines
+};
--
With Best Regards,
Andy Shevchenko
Regards,
Anup
Andy Shevchenko
reviewerRe: [PATCH v3 13/23] irqchip: Add driver for the RPMI system MSI service group
Quoted 3 lines · Anup Patel
Quoted 1 line · Andy Shevchenko
On Sun, May 11, 2025 at 07:09:29PM +0530, Anup Patel wrote:
...
Quoted 16 lines
Quoted 16 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 18
Quoted 13 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +13
-0+#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/cpu.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/mailbox_client.h> +#include <linux/mailbox/riscv-rpmi-message.h> +#include <linux/module.h> +#include <linux/msi.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> +#include <linux/printk.h> +#include <linux/smp.h> +
types.h
Quoted 5 lines
Quoted 3 lines
Actually this one is most clean, the rest of the patches where the new code is introduced has semi-random list of the inclusions, please, follow the IWYU principle.
Sure, I will simplify the #includes
Oh, IWYU (Include What You Use) is not about simplification. It's about comprehension. It usually means that *more* headers need to be included and *only some* of the existing will be dropped.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 13/23] irqchip: Add driver for the RPMI system MSI service group
Quoted 28 lines · Andy Shevchenko
Quoted 3 lines · Anup Patel
Quoted 1 line · Andy Shevchenko
On Sun, May 11, 2025 at 07:09:29PM +0530, Anup Patel wrote:
...
Quoted 20 lines
Quoted 19 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 18
Quoted 13 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +13
-0+#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/cpu.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/mailbox_client.h> +#include <linux/mailbox/riscv-rpmi-message.h> +#include <linux/module.h> +#include <linux/msi.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> +#include <linux/printk.h> +#include <linux/smp.h> +
types.hActually this one is most clean, the rest of the patches where the new code is introduced has semi-random list of the inclusions, please, follow the IWYU principle.
Quoted 6 lines
Quoted 1 line
Sure, I will simplify the #includes
Oh, IWYU (Include What You Use) is not about simplification. It's about comprehension. It usually means that *more* headers need to be included and *only some* of the existing will be dropped.
Okay, I will update accordingly.
Regards,
Anup
Re: [PATCH v3 13/23] irqchip: Add driver for the RPMI system MSI service group
In reply to Anup PatelQuoted 36 lines · Anup Patel
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +36
-0+static int rpmi_sysmsi_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct rpmi_sysmsi_priv *priv; +int rc; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + priv->dev = dev; +platform_set_drvdata (pdev, priv); + +/* Setup mailbox client */ + priv->client.dev = priv->dev; + priv->client.rx_callback =NULL ; + priv->client.tx_block = false; + priv->client.knows_txdone = true; + priv->client.tx_tout =0 ; + +/* Request mailbox channel */ + priv->chan =mbox_request_channel (&priv->client,0 ); +if (IS_ERR (priv->chan)) +return PTR_ERR (priv->chan); + +/* Get number of system MSIs */ + rc =rpmi_sysmsi_get_num_msi (priv); +if (rc <1 ) { +mbox_free_channel (priv->chan); +return dev_err_probe (dev, -ENODEV ,"No system MSIs found\n" ); + } + priv->nr_irqs = rc; + +/* Set the device MSI domain if not available */ +if (!dev_get_msi_domain (dev)) { +/* +* The device MSI domain for OF devices is only set at the
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 256
Quoted 10 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +10
-0+* time of populating/creating OF device. If the device MSI +* domain is discovered later after the OF device is created +* then we need to set it explicitly before using any platform +* MSI functions. +*/ +if (is_of_node (dev_fwnode (dev))) +of_msi_configure (dev,to_of_node (dev_fwnode (dev))); + +if (!dev_get_msi_domain (dev)) +return -EPROBE_DEFER ;
This leaks the channel.
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 262
Quoted 6 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +6
-0+ } + +if (!msi_create_device_irq_domain (dev,MSI_DEFAULT_DOMAIN , + &rpmi_sysmsi_template, + priv->nr_irqs, priv, priv)) +return dev_err_probe (dev, -ENOMEM ,"failed to create MSI irq domain\n" );
Ditto.
Thanks,
tglx
Re: [PATCH v3 13/23] irqchip: Add driver for the RPMI system MSI service group
Quoted 42 lines · Thomas Gleixner
Quoted 40 lines · Anup Patel
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +40
-0+static int rpmi_sysmsi_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct rpmi_sysmsi_priv *priv; +int rc; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + priv->dev = dev; +platform_set_drvdata (pdev, priv); + +/* Setup mailbox client */ + priv->client.dev = priv->dev; + priv->client.rx_callback =NULL ; + priv->client.tx_block = false; + priv->client.knows_txdone = true; + priv->client.tx_tout =0 ; + +/* Request mailbox channel */ + priv->chan =mbox_request_channel (&priv->client,0 ); +if (IS_ERR (priv->chan)) +return PTR_ERR (priv->chan); + +/* Get number of system MSIs */ + rc =rpmi_sysmsi_get_num_msi (priv); +if (rc <1 ) { +mbox_free_channel (priv->chan); +return dev_err_probe (dev, -ENODEV ,"No system MSIs found\n" ); + } + priv->nr_irqs = rc; + +/* Set the device MSI domain if not available */ +if (!dev_get_msi_domain (dev)) { +/* +* The device MSI domain for OF devices is only set at the +* time of populating/creating OF device. If the device MSI +* domain is discovered later after the OF device is created +* then we need to set it explicitly before using any platform +* MSI functions.
Quoted 8 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 256
Quoted 6 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +6
-0+*/ +if (is_of_node (dev_fwnode (dev))) +of_msi_configure (dev,to_of_node (dev_fwnode (dev))); + +if (!dev_get_msi_domain (dev)) +return -EPROBE_DEFER ;This leaks the channel.
Ahh yes, I will update.
Quoted 8 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c line 262
Quoted 7 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c new file +6
-0+ } + +if (!msi_create_device_irq_domain (dev,MSI_DEFAULT_DOMAIN , + &rpmi_sysmsi_template, + priv->nr_irqs, priv, priv)) +return dev_err_probe (dev, -ENOMEM ,"failed to create MSI irq domain\n" );
Quoted 5 lines
Ditto.
Thanks,
tglx
Thanks,
Anup
PATCH v3 14/23 ACPI: property: Refactor acpi_fwnode_get_reference_args()
In reply to Anup PatelFrom: Sunil V L <[email protected]>
Currently acpi_fwnode_get_reference_args() calls the public function __acpi_node_get_property_reference() which ignores the nargs_prop parameter. To fix this, make __acpi_node_get_property_reference() to call the static acpi_fwnode_get_reference() so that callers of fwnode_get_reference_args() can still pass a valid property name to fetch the number of arguments.
--- drivers/acpi/property.c | 103 ++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 52 deletions(-)
drivers/acpi/property.c +51 -52
@@ -882,45 +882,10 @@ static struct fwnode_handle *acpi_parse_string_ref(const struct fwnode_handle *freturn &dn->fwnode; } -/** -* __acpi_node_get_property_reference - returns handle to the referenced object -* @fwnode: Firmware node to get the property from -* @propname: Name of the property -* @index: Index of the reference to return -* @num_args: Maximum number of arguments after each reference -* @args: Location to store the returned reference with optional arguments -* (may be NULL) -* -* Find property with @name, verifify that it is a package containing at least -* one object reference and if so, store the ACPI device object pointer to the -* target object in @args->adev. If the reference includes arguments, store -* them in the @args->args[] array. -* -* If there's more than one reference in the property value package, @index is -* used to select the one to return. -* -* It is possible to leave holes in the property value set like in the -* example below: -* -* Package () { -* "cs-gpios", -* Package () { -* ^GPIO, 19, 0, 0, -* ^GPIO, 20, 0, 0, -* 0, -* ^GPIO, 21, 0, 0, -* } -* } -* -* Calling this function with index %2 or index %3 return %-ENOENT. If the -* property does not contain any more values %-ENOENT is returned. The NULL -* entry must be single integer and preferably contain value %0. -* -* 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, -struct fwnode_reference_args *args) +static int acpi_fwnode_get_reference_args (const struct fwnode_handle *fwnode, +const char *prop,const char *nargs_prop, +unsigned int args_count,unsigned int index, +struct fwnode_reference_args *args) {const union acpi_object *element, *end;const union acpi_object *obj;
@@ -933,7 +898,7 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,if (!data)return -ENOENT ; - ret =acpi_data_get_property (data, propname,ACPI_TYPE_ANY , &obj); + ret =acpi_data_get_property (data, prop,ACPI_TYPE_ANY , &obj);if (ret)return ret == -EINVAL ? -ENOENT : -EINVAL ;
@@ -999,7 +964,7 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, ret =acpi_get_ref_args (idx == index ? args :NULL ,acpi_fwnode_handle (device), - &element, end, num_args); + &element, end, args_count);if (ret <0 )return ret;
@@ -1017,7 +982,7 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, ret =acpi_get_ref_args (idx == index ? args :NULL , ref_fwnode, &element, end, - num_args); + args_count);if (ret <0 )return ret;
@@ -1039,6 +1004,50 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,return -ENOENT ; } + +/** +* __acpi_node_get_property_reference - returns handle to the referenced object +* @fwnode: Firmware node to get the property from +* @propname: Name of the property +* @index: Index of the reference to return +* @num_args: Maximum number of arguments after each reference +* @args: Location to store the returned reference with optional arguments +* (may be NULL) +* +* Find property with @name, verifify that it is a package containing at least +* one object reference and if so, store the ACPI device object pointer to the +* target object in @args->adev. If the reference includes arguments, store +* them in the @args->args[] array. +* +* If there's more than one reference in the property value package, @index is +* used to select the one to return. +* +* It is possible to leave holes in the property value set like in the +* example below: +* +* Package () { +* "cs-gpios", +* Package () { +* ^GPIO, 19, 0, 0, +* ^GPIO, 20, 0, 0, +* 0, +* ^GPIO, 21, 0, 0, +* } +* } +* +* Calling this function with index %2 or index %3 return %-ENOENT. If the +* property does not contain any more values %-ENOENT is returned. The NULL +* entry must be single integer and preferably contain value %0. +* +* 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, +struct fwnode_reference_args *args) +{ +return acpi_fwnode_get_reference_args (fwnode, propname,NULL , index, num_args, args); +}EXPORT_SYMBOL_GPL (__acpi_node_get_property_reference); static int acpi_data_prop_read_single(const struct acpi_device_data *data,
@@ -1558,16 +1567,6 @@ acpi_fwnode_property_read_string_array(const struct fwnode_handle *fwnode, val, nval); } -static int -acpi_fwnode_get_reference_args (const struct fwnode_handle *fwnode, -const char *prop,const char *nargs_prop, -unsigned int args_count,unsigned int index, -struct fwnode_reference_args *args) -{ -return __acpi_node_get_property_reference (fwnode, prop, index, - args_count, args); -} -static const char *acpi_fwnode_get_name (const struct fwnode_handle *fwnode) {const struct acpi_device *adev;
Signature · 1 line
2.43.0
Andy Shevchenko
reviewerRe: [PATCH v3 14/23] ACPI: property: Refactor acpi_fwnode_get_reference_args()
Quoted 7 lines · Anup Patel
Currently
acpi_fwnode_get_reference_args()calls the public function__acpi_node_get_property_reference()which ignores thenargs_propparameter. To fix this, make__acpi_node_get_property_reference()to call the staticacpi_fwnode_get_reference()so that callers offwnode_get_reference_args()can still pass a valid property name to fetch the number of arguments.
...
drivers/acpi/property.c static struct fwnode_handle *acpi_parse_string_ref(const struct fwnode_handle *f · line 886
Quoted 2 lines
drivers/acpi/property.c +2
-0+static int acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode, + const char *prop, const char *nargs_prop,
Why prop and not propname?
Quoted 2 lines
drivers/acpi/property.c +2
-0+ unsigned int args_count, unsigned int index, + struct fwnode_reference_args *args)
...
drivers/acpi/property.c int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, · line 901
Quoted 2 lines
drivers/acpi/property.c +1
-1- ret =acpi_data_get_property (data, propname,ACPI_TYPE_ANY , &obj); + ret =acpi_data_get_property (data, prop,ACPI_TYPE_ANY , &obj);
Ditto.
Sounds like an unneeded churn.
Quoted 2 lines
drivers/acpi/property.c +0
-0if (ret)return ret == -EINVAL ? -ENOENT : -EINVAL ;
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 15/23 ACPI: property: Add support for cells property
In reply to Anup PatelFrom: Sunil V L <[email protected]>
Currently, ACPI doesn't support cells property when fwnode_property_get_reference_args() is called. ACPI always expects the number of arguments to be passed. However, fwnode_property_get_reference_args() being a common interface for OF and ACPI, it is better to have single calling convention which works for both. Hence, add support for cells property on the reference device to get the number of arguments dynamically.
--- drivers/acpi/property.c | 15 +++++++++++++++ drivers/base/property.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-)
drivers/acpi/property.c +15 -0
@@ -960,6 +960,13 @@ static int acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,if (!device)return -EINVAL ; +if (nargs_prop) { +if (!acpi_dev_get_property (device, nargs_prop, +ACPI_TYPE_INTEGER , &obj)) { + args_count = obj->integer.value; + } + } + element++; ret = acpi_get_ref_args(idx == index ? args : NULL,
@@ -978,6 +985,14 @@ static int acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,if (!ref_fwnode)return -EINVAL ; +if (nargs_prop) { + device =to_acpi_device_node (ref_fwnode); +if (!acpi_dev_get_property (device, nargs_prop, +ACPI_TYPE_INTEGER , &obj)) { + args_count = obj->integer.value; + } + } + element++; ret = acpi_get_ref_args(idx == index ? args : NULL,
drivers/base/property.c +1 -1
@@ -578,7 +578,7 @@ EXPORT_SYMBOL_GPL(fwnode_property_match_property_string);* @prop: The name of the property * @nargs_prop: The name of the property telling the number of * arguments in the referred node. NULL if @nargs is known, -* otherwise @nargs is ignored. Only relevant on OF. +* otherwise @nargs is ignored. * @nargs: Number of arguments. Ignored if @nargs_prop is non-NULL. * @index: Index of the reference, from zero onwards. * @args: Result structure with reference and integer arguments.
Signature · 1 line
2.43.0
Andy Shevchenko
reviewerRe: [PATCH v3 15/23] ACPI: property: Add support for cells property
Quoted 8 lines · Anup Patel
Currently, ACPI doesn't support cells property when
fwnode_property_get_reference_args()is called. ACPI always expects the number of arguments to be passed. However,fwnode_property_get_reference_args()being a common interface for OF and ACPI, it is better to have single calling convention which works for both. Hence, add support for cells property on the reference device to get the number of arguments dynamically.
You can reformat above to make it deviate less (in terms of line lengths):
Currently, ACPI doesn't support cells property when fwnode_property_get_reference_args() is called. ACPI always expects the number of arguments to be passed. However, the above mentioned call being a common interface for OF and ACPI, it is better to have single calling convention which works for both. Hence, add support for cells property on the reference device to get the number of arguments dynamically.
...
Quoted 5 lines
drivers/acpi/property.c +5
-0+if (nargs_prop) { +if (!acpi_dev_get_property (device, nargs_prop, +ACPI_TYPE_INTEGER , &obj)) { + args_count = obj->integer.value; + }
drivers/acpi/property.c static int acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode, · line 994
Quoted 10 lines
drivers/acpi/property.c +9
-0+ } + +if (nargs_prop) { + device =to_acpi_device_node (ref_fwnode); +if (!acpi_dev_get_property (device, nargs_prop, +ACPI_TYPE_INTEGER , &obj)) { + args_count = obj->integer.value; + } + }
These two seems to me enough duplicative to have a common helper:
static unsigned int ...(struct acpi_dev *adev, ...)
{
// define an obj variable?
if (!nargs_prop)
return 0;
if (acpi_dev_get_property(adev, nargs_prop, ACPI_TYPE_INTEGER, &obj))
return 0;
return obj->integer.value;
}Yes, the nember of LoCs most likely will increase, but the point here is better maintenance experience.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sunil V L
maintainerRe: [PATCH v3 15/23] ACPI: property: Add support for cells property
Hi Andy,
Quoted 12 lines · Andy Shevchenko
Quoted 8 lines · Anup Patel
Currently, ACPI doesn't support cells property when
fwnode_property_get_reference_args()is called. ACPI always expects the number of arguments to be passed. However,fwnode_property_get_reference_args()being a common interface for OF and ACPI, it is better to have single calling convention which works for both. Hence, add support for cells property on the reference device to get the number of arguments dynamically.You can reformat above to make it deviate less (in terms of line lengths):
Quoted 8 lines
Currently, ACPI doesn't support cells property when
fwnode_property_get_reference_args()is called. ACPI always expects the number of arguments to be passed. However, the above mentioned call being a common interface for OF and ACPI, it is better to have single calling convention which works for both. Hence, add support for cells property on the reference device to get the number of arguments dynamically.
Sure. Let me update in the next revision. Thanks!
Quoted 33 lines
...
Quoted 5 lines
drivers/acpi/property.c +5
-0+if (nargs_prop) { +if (!acpi_dev_get_property (device, nargs_prop, +ACPI_TYPE_INTEGER , &obj)) { + args_count = obj->integer.value; + }drivers/acpi/property.c static int acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode, · line 994
Quoted 10 lines
drivers/acpi/property.c +9
-0+ } + +if (nargs_prop) { + device =to_acpi_device_node (ref_fwnode); +if (!acpi_dev_get_property (device, nargs_prop, +ACPI_TYPE_INTEGER , &obj)) { + args_count = obj->integer.value; + } + }These two seems to me enough duplicative to have a common helper:
static unsigned int ...(struct
acpi_dev*adev, ...){ // define an obj variable? if (!nargs_prop) return 0; if (acpi_dev_get_property(adev, nargs_prop, ACPI_TYPE_INTEGER, &obj)) return 0; return obj->integer.value; }
Quoted 3 lines
Yes, the nember of LoCs most likely will increase, but the point here is better maintenance experience.
Makes sense. Let me do it in the next version.
Thanks!
Sunil
PATCH v3 16/23 ACPI: scan: Update honor list for RPMI System MSI
In reply to Anup PatelFrom: 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
@@ -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
PATCH v3 17/23 ACPI: RISC-V: Create interrupt controller list in sorted order
In reply to Anup PatelFrom: Sunil V L <[email protected]>
Currently, the interrupt controller list is created without any order. Create the list sorted with the GSI base of the interrupt controllers.
--- drivers/acpi/riscv/irq.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/acpi/riscv/irq.c +12 -2
@@ -115,7 +115,7 @@ struct fwnode_handle *riscv_acpi_get_gsi_domain_id(u32 gsi)static int __init riscv_acpi_register_ext_intc (u32 gsi_base,u32 nr_irqs,u32 nr_idcs,u32 id,u32 type) { -struct riscv_ext_intc_list *ext_intc_element; +struct riscv_ext_intc_list *ext_intc_element, *node; ext_intc_element =kzalloc (sizeof (*ext_intc_element),GFP_KERNEL );if (!ext_intc_element)
@@ -125,7 +125,17 @@ static int __init riscv_acpi_register_ext_intc(u32 gsi_base, u32 nr_irqs, u32 nr ext_intc_element->nr_irqs = nr_irqs; ext_intc_element->nr_idcs = nr_idcs; ext_intc_element->id = id; -list_add_tail (&ext_intc_element->list, &ext_intc_list); +if (list_empty (&ext_intc_list)) { +list_add (&ext_intc_element->list, &ext_intc_list); +return 0 ; + } + +list_for_each_entry (node, &ext_intc_list, list) { +if (node->gsi_base < ext_intc_element->gsi_base) +break ; + } + +__list_add (&ext_intc_element->list, node->list.prev, &node->list);return 0 ; }
Signature · 1 line
2.43.0
PATCH v3 18/23 ACPI: RISC-V: Add support to update gsi range
In reply to Anup PatelFrom: Sunil V L <[email protected]>
Some RISC-V interrupt controllers like RPMI based system MSI interrupt controllers do not have MADT entry defined. These interrupt controllers exist only in the namespace. ACPI spec defines _GSB method to get the GSI base of the interrupt controller, However, there is no such standard method to get the GSI range. To support such interrupt controllers, set the GSI range of such interrupt controllers to non-overlapping range and provide API for interrupt controller driver to update it with proper value.
--- arch/riscv/include/asm/irq.h | 5 +++++ drivers/acpi/riscv/irq.c | 38 ++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-)
arch/riscv/include/asm/irq.h +5 -0
@@ -40,6 +40,7 @@ unsigned long acpi_rintc_ext_parent_to_hartid(unsigned int plic_id, unsigned intunsigned int acpi_rintc_get_plic_nr_contexts (unsigned int plic_id);unsigned int acpi_rintc_get_plic_context (unsigned int plic_id,unsigned int ctxt_idx);int __init acpi_rintc_get_imsic_mmio_info (u32 index,struct resource *res); +int riscv_acpi_update_gsi_range (u32 gsi_base,u32 nr_irqs);#else static inline int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base,
@@ -74,6 +75,10 @@ static inline int __init acpi_rintc_get_imsic_mmio_info(u32 index, struct resourreturn 0 ; } +static inline int riscv_acpi_update_gsi_range (u32 gsi_base,u32 nr_irqs) +{ +return -1 ; +}#endif /* CONFIG_ACPI */ #endif /* _ASM_RISCV_IRQ_H */
drivers/acpi/riscv/irq.c +36 -2
@@ -10,6 +10,8 @@#include "init.h" +#define RISCV_ACPI_INTC_FLAG_PENDING BIT(0) +struct riscv_ext_intc_list {acpi_handle handle;u32 gsi_base;
@@ -17,6 +19,7 @@ struct riscv_ext_intc_list {u32 nr_idcs;u32 id;u32 type; +u32 flag;struct list_head list; };
@@ -69,6 +72,22 @@ static acpi_status riscv_acpi_update_gsi_handle(u32 gsi_base, acpi_handle handlereturn AE_NOT_FOUND ; } +int riscv_acpi_update_gsi_range (u32 gsi_base,u32 nr_irqs) +{ +struct riscv_ext_intc_list *ext_intc_element; + +list_for_each_entry (ext_intc_element, &ext_intc_list, list) { +if (gsi_base == ext_intc_element->gsi_base && + (ext_intc_element->flag &RISCV_ACPI_INTC_FLAG_PENDING )) { + ext_intc_element->nr_irqs = nr_irqs; + ext_intc_element->flag &= ~RISCV_ACPI_INTC_FLAG_PENDING ; +return 0 ; + } + } + +return -1 ; +} +int riscv_acpi_get_gsi_info (struct fwnode_handle *fwnode,u32 *gsi_base,u32 *id,u32 *nr_irqs,u32 *nr_idcs) {
@@ -115,14 +134,22 @@ struct fwnode_handle *riscv_acpi_get_gsi_domain_id(u32 gsi)static int __init riscv_acpi_register_ext_intc (u32 gsi_base,u32 nr_irqs,u32 nr_idcs,u32 id,u32 type) { -struct riscv_ext_intc_list *ext_intc_element, *node; +struct riscv_ext_intc_list *ext_intc_element, *node, *prev; ext_intc_element =kzalloc (sizeof (*ext_intc_element),GFP_KERNEL );if (!ext_intc_element)return -ENOMEM ; ext_intc_element->gsi_base = gsi_base; - ext_intc_element->nr_irqs = nr_irqs; + +/* If nr_irqs is zero, indicate it in flag and set to max range possible */ +if (!nr_irqs) { + ext_intc_element->flag |=RISCV_ACPI_INTC_FLAG_PENDING ; + ext_intc_element->nr_irqs =U32_MAX - ext_intc_element->gsi_base; + }else { + ext_intc_element->nr_irqs = nr_irqs; + } + ext_intc_element->nr_idcs = nr_idcs; ext_intc_element->id = id;if (list_empty (&ext_intc_list)) {
@@ -135,6 +162,13 @@ static int __init riscv_acpi_register_ext_intc(u32 gsi_base, u32 nr_irqs, u32 nrbreak ; } +/* Adjust the previous node's GSI range if that has pending registration */ + prev =list_prev_entry (node, list); +if (!list_entry_is_head (prev, &ext_intc_list, list)) { +if (prev->flag &RISCV_ACPI_INTC_FLAG_PENDING ) + prev->nr_irqs = ext_intc_element->gsi_base - prev->gsi_base; + } +__list_add (&ext_intc_element->list, node->list.prev, &node->list);return 0 ; }
Signature · 1 line
2.43.0
Andy Shevchenko
reviewerRe: [PATCH v3 18/23] ACPI: RISC-V: Add support to update gsi range
Quoted 10 lines · Anup Patel
From: Sunil V L <[email protected]>
Some RISC-V interrupt controllers like RPMI based system MSI interrupt controllers do not have MADT entry defined. These interrupt controllers exist only in the namespace. ACPI spec defines
_GSBmethod to get the GSI base of the interrupt controller, However, there is no such standard method to get the GSI range. To support such interrupt controllers, set the GSI range of such interrupt controllers to non-overlapping range and provide API for interrupt controller driver to update it with proper value.
...
arch/riscv/include/asm/irq.h static inline int __init acpi_rintc_get_imsic_mmio_info(u32 index, struct resour · line 80
Quoted 3 lines
arch/riscv/include/asm/irq.h +3
-0+static inline int riscv_acpi_update_gsi_range (u32 gsi_base,u32 nr_irqs) +{ +return -1 ;
Why not using the defined error code?
Quoted 1 line
+}
...
Quoted 4 lines
drivers/acpi/riscv/irq.c +4
-0+int riscv_acpi_update_gsi_range (u32 gsi_base,u32 nr_irqs) +{ +struct riscv_ext_intc_list *ext_intc_element; +
drivers/acpi/riscv/irq.c static acpi_status riscv_acpi_update_gsi_handle(u32 gsi_base, acpi_handle handle · line 88
Quoted 10 lines
drivers/acpi/riscv/irq.c +9
-0+list_for_each_entry (ext_intc_element, &ext_intc_list, list) { +if (gsi_base == ext_intc_element->gsi_base && + (ext_intc_element->flag &RISCV_ACPI_INTC_FLAG_PENDING )) { + ext_intc_element->nr_irqs = nr_irqs; + ext_intc_element->flag &= ~RISCV_ACPI_INTC_FLAG_PENDING ; +return 0 ; + } + } +return -1 ;
Ditto.
Quoted 1 line
+}
...
drivers/acpi/riscv/irq.c struct fwnode_handle *riscv_acpi_get_gsi_domain_id(u32 gsi) · line 146
Quoted 2 lines
drivers/acpi/riscv/irq.c +2
-0+/* If nr_irqs is zero, indicate it in flag and set to max range possible */ +if (!nr_irqs) {
Make conditional positive.
drivers/acpi/riscv/irq.c struct fwnode_handle *riscv_acpi_get_gsi_domain_id(u32 gsi) · line 148
Quoted 2 lines
drivers/acpi/riscv/irq.c +2
-0+ ext_intc_element->flag |=RISCV_ACPI_INTC_FLAG_PENDING ; + ext_intc_element->nr_irqs =U32_MAX - ext_intc_element->gsi_base;
One space too many.
Quoted 3 lines
drivers/acpi/riscv/irq.c +3
-0+ }else { + ext_intc_element->nr_irqs = nr_irqs; + }
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 19/23 ACPI: RISC-V: Add RPMI System MSI to GSI mapping
In reply to Anup PatelFrom: 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 | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
arch/riscv/include/asm/irq.h +1 -0
@@ -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 +30 -0
@@ -173,6 +173,33 @@ static int __init riscv_acpi_register_ext_intc(u32 gsi_base, u32 nr_irqs, u32 nrreturn 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; + } + +riscv_acpi_register_ext_intc (gbase,0 ,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) {
@@ -227,6 +254,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
PATCH v3 20/23 mailbox/riscv-sbi-mpxy: Add ACPI support
In reply to Anup PatelFrom: 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 | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/mailbox/riscv-sbi-mpxy-mbox.c +21 -1
@@ -6,9 +6,11 @@*/ #include <asm/sbi.h> +#include <linux/acpi.h> #include <linux/cpu.h> #include <linux/err.h> #include <linux/init.h> +#include <linux/irqchip/riscv-imsic.h> #include <linux/jump_label.h> #include <linux/kernel.h> #include <linux/mailbox_controller.h>
@@ -775,6 +777,7 @@ static int mpxy_mbox_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct mpxy_mbox_channel *mchan; +struct irq_domain *msi_domain;struct mpxy_mbox *mbox;int i, msi_idx, rc;u32 *channel_ids;
@@ -907,8 +910,13 @@ 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 (dev))) +if (is_of_node (dev_fwnode (dev))) {of_msi_configure (dev,to_of_node (dev_fwnode (dev))); + }else { + msi_domain =irq_find_matching_fwnode (imsic_acpi_get_fwnode (dev), +DOMAIN_BUS_PLATFORM_MSI ); +dev_set_msi_domain (dev, msi_domain); + } }/* Setup MSIs for mailbox (if required) */
@@ -953,6 +961,11 @@ 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 ;
@@ -972,10 +985,17 @@ static const struct of_device_id mpxy_mbox_of_match[] = { };MODULE_DEVICE_TABLE (of, mpxy_mbox_of_match); +static const struct acpi_device_id mpxy_mbox_acpi_match[] = { + {"RSCV0005" }, + {} +}; +MODULE_DEVICE_TABLE (acpi, mpxy_mbox_acpi_match); +static struct platform_driver mpxy_mbox_driver = { .driver = { .name ="riscv-sbi-mpxy-mbox" , .of_match_table = mpxy_mbox_of_match, + .acpi_match_table = mpxy_mbox_acpi_match, }, .probe = mpxy_mbox_probe, .remove = mpxy_mbox_remove,
Signature · 1 line
2.43.0
Andy Shevchenko
reviewerRe: [PATCH v3 20/23] mailbox/riscv-sbi-mpxy: Add ACPI support
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.
...
drivers/mailbox/riscv-sbi-mpxy-mbox.c static int mpxy_mbox_probe(struct platform_device *pdev) · line 915
Quoted 4 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c +2
-1-if (is_of_node (dev_fwnode (dev))) +if (is_of_node (dev_fwnode (dev))) {of_msi_configure (dev,to_of_node (dev_fwnode (dev))); + }else {
You probably want to have this as
} else if (is_acpi_..._node()) { // you should decide if it is data, device or any type of ACPI node you match withQuoted 5 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c +4
-0+ msi_domain =irq_find_matching_fwnode (imsic_acpi_get_fwnode (dev), +DOMAIN_BUS_PLATFORM_MSI ); +dev_set_msi_domain (dev, msi_domain); + } }
...
drivers/mailbox/riscv-sbi-mpxy-mbox.c static int mpxy_mbox_probe(struct platform_device *pdev) · line 965
Quoted 2 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c +2
-0+#ifdef CONFIG_ACPI +if (!acpi_disabled)
Hmm... Why do you need this check? What for?
Quoted 2 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c +2
-0+acpi_dev_clear_dependencies (ACPI_COMPANION (dev)); +#endif
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sunil V L
maintainerRe: [PATCH v3 20/23] mailbox/riscv-sbi-mpxy: Add ACPI support
Quoted 8 lines · Andy Shevchenko
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.
...
Quoted 9 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c static int mpxy_mbox_probe(struct platform_device *pdev) · line 915
Quoted 4 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c +2
-1-if (is_of_node (dev_fwnode (dev))) +if (is_of_node (dev_fwnode (dev))) {of_msi_configure (dev,to_of_node (dev_fwnode (dev))); + }else {You probably want to have this as
} else if (is_acpi_..._node()) { // you should decide if it is data, device or any type of ACPI node you match with
Sure.
Quoted 8 lines
Quoted 5 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c +4
-0+ msi_domain =irq_find_matching_fwnode (imsic_acpi_get_fwnode (dev), +DOMAIN_BUS_PLATFORM_MSI ); +dev_set_msi_domain (dev, msi_domain); + } }...
Quoted 5 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c static int mpxy_mbox_probe(struct platform_device *pdev) · line 965
Quoted 2 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c +2
-0+#ifdef CONFIG_ACPI +if (!acpi_disabled)Hmm... Why do you need this check? What for?
When we boot with DT, ACPI_COMPANION(dev) will return NULL which will cause a crash in acpi_dev_clear_dependencies(). Let me know if I am missing something.
Quoted 3 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c static int mpxy_mbox_probe(struct platform_device *pdev) · line 967
Quoted 2 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c +2
-0+acpi_dev_clear_dependencies (ACPI_COMPANION (dev)); +#endif
Thanks,
Sunil
Andy Shevchenko
reviewerRe: [PATCH v3 20/23] mailbox/riscv-sbi-mpxy: Add ACPI support
Quoted 2 lines · Sunil V L
Quoted 1 line · Andy Shevchenko
On Sun, May 11, 2025 at 07:09:36PM +0530, Anup Patel wrote:
...
Quoted 8 lines
Quoted 5 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c static int mpxy_mbox_probe(struct platform_device *pdev) · line 965
Quoted 2 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c +2
-0+#ifdef CONFIG_ACPI +if (!acpi_disabled)Hmm... Why do you need this check? What for?
When we boot with DT,
ACPI_COMPANION(dev)will return NULL which will cause a crash inacpi_dev_clear_dependencies(). Let me know if I am missing something.
Yes, just check that the companion is NULL, rather than the above.
struct acpi_device *adev; adev = ACPI_COMPANION(dev); if (adev) acpi_dev_clear_dependencies(adev);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c +2
-0+acpi_dev_clear_dependencies (ACPI_COMPANION (dev)); +#endif
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sunil V L
maintainerRe: [PATCH v3 20/23] mailbox/riscv-sbi-mpxy: Add ACPI support
Quoted 15 lines · Andy Shevchenko
Quoted 2 lines · Sunil V L
Quoted 1 line · Andy Shevchenko
On Sun, May 11, 2025 at 07:09:36PM +0530, Anup Patel wrote:
...
Quoted 8 lines
Quoted 5 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c static int mpxy_mbox_probe(struct platform_device *pdev) · line 965
Quoted 2 lines
drivers/mailbox/riscv-sbi-mpxy-mbox.c +2
-0+#ifdef CONFIG_ACPI +if (!acpi_disabled)Hmm... Why do you need this check? What for?
When we boot with DT,
ACPI_COMPANION(dev)will return NULL which will cause a crash inacpi_dev_clear_dependencies(). Let me know if I am missing something.
Quoted 8 lines
Yes, just check that the companion is NULL, rather than the above.
struct acpi_device *adev; adev = ACPI_COMPANION(dev); if (adev) acpi_dev_clear_dependencies(adev);
Ah Ok. Sure. Will update.
Thanks!
Sunil
PATCH v3 21/23 irqchip/riscv-rpmi-sysmsi: Add ACPI support
In reply to Anup PatelFrom: 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 | 41 +++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-)
drivers/irqchip/Kconfig +1 -1
@@ -614,7 +614,7 @@ config RISCV_IMSIC 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 +38 -3
85 lines not on this page · raw message
Signature · 1 line
2.43.0
Andy Shevchenko
reviewerRe: [PATCH v3 21/23] irqchip/riscv-rpmi-sysmsi: Add ACPI support
Quoted 2 lines · Anup Patel
Add ACPI support for the RISC-V RPMI system MSI based irqchip driver.
...
struct fwnode_handle *fwnode; ... fwnode = dev_fwnode(dev);
drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 251
Quoted 5 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +5
-0+if (is_acpi_node (dev_fwnode (dev))) { +u32 nr_irqs; + + rc =riscv_acpi_get_gsi_info (dev_fwnode (dev), &priv->gsi_base, &id, + &nr_irqs,NULL );
...(fwnode, ...)
...and so on...
Quoted 4 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +4
-0+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 10 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +7
-1+ +/* Update with actual GSI range */ +if (nr_irqs != priv->nr_irqs) +riscv_acpi_update_gsi_range (priv->gsi_base, priv->nr_irqs); + } -if (is_of_node (dev_fwnode (dev))) +if (is_of_node (dev_fwnode (dev))) {of_msi_configure (dev,to_of_node (dev_fwnode (dev))); + }else {
} else if (is_acpi_..._node(...)) {Quoted 4 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +4
-0+ msi_domain =irq_find_matching_fwnode (imsic_acpi_get_fwnode (dev), +DOMAIN_BUS_PLATFORM_MSI ); +dev_set_msi_domain (dev, msi_domain); + }
...
drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 289
Quoted 2 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
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sunil V L
maintainerRe: [PATCH v3 21/23] irqchip/riscv-rpmi-sysmsi: Add ACPI support
Quoted 18 lines · Andy Shevchenko
Quoted 2 lines · Anup Patel
Add ACPI support for the RISC-V RPMI system MSI based irqchip driver.
...
struct fwnode_handle *fwnode; ... fwnode = dev_fwnode(dev);drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 251
Quoted 5 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +5
-0+if (is_acpi_node (dev_fwnode (dev))) { +u32 nr_irqs; + + rc =riscv_acpi_get_gsi_info (dev_fwnode (dev), &priv->gsi_base, &id, + &nr_irqs,NULL );...(fwnode, ...)
Quoted 2 lines
...and so on...
Sure.
Quoted 10 lines
Quoted 9 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +9
-0+if (rc) { +dev_err (dev,"failed to find GSI mapping\n" ); +return rc; + } + +/* Update with actual GSI range */ +if (nr_irqs != priv->nr_irqs) +riscv_acpi_update_gsi_range (priv->gsi_base, priv->nr_irqs); + }
Quoted 7 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 273
Quoted 4 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +2
-1-if (is_of_node (dev_fwnode (dev))) +if (is_of_node (dev_fwnode (dev))) {of_msi_configure (dev,to_of_node (dev_fwnode (dev))); + }else {} else if (is_acpi_..._node(...)) {
Okay.
Quoted 7 lines
Quoted 4 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +4
-0+ msi_domain =irq_find_matching_fwnode (imsic_acpi_get_fwnode (dev), +DOMAIN_BUS_PLATFORM_MSI ); +dev_set_msi_domain (dev, msi_domain); + }...
Quoted 5 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c static int rpmi_sysmsi_probe(struct platform_device *pdev) · line 289
Quoted 2 lines
drivers/irqchip/irq-riscv-rpmi-sysmsi.c +2
-0+#ifdef CONFIG_ACPI +if (!acpi_disabled)Why?
Same code as in the other patch. I will update this in the next version in case any change required.
Thanks,
Sunil
PATCH v3 22/23 RISC-V: Enable GPIO keyboard and event device in RV64 defconfig
In reply to Anup PatelThe 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
@@ -141,6 +141,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
PATCH v3 23/23 MAINTAINERS: Add entry for RISC-V RPMI and MPXY drivers
In reply to Anup PatelAdd Rahul and myself as maintainers for RISC-V RPMI and MPXY drivers.
--- MAINTAINERS | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
MAINTAINERS +15 -0
@@ -20885,6 +20885,21 @@ F: drivers/perf/riscv_pmu.c F: drivers/perf/riscv_pmu_legacy.c F: drivers/perf/riscv_pmu_sbi.c +RISC-V RPMI AND MPXY DRIVERS +M: Rahul Pathak <[email protected]> +M: Anup Patel <[email protected]> +L: [email protected] +F: Documentation/devicetree/bindings/clock/riscv,rpmi-clock.yaml +F: Documentation/devicetree/bindings/clock/riscv,rpmi-mpxy-clock.yaml +F: Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-mpxy-system-msi.yaml +F: Documentation/devicetree/bindings/interrupt-controller/riscv,rpmi-system-msi.yaml +F: Documentation/devicetree/bindings/mailbox/riscv,rpmi-shmem-mbox.yaml +F: Documentation/devicetree/bindings/mailbox/riscv,sbi-mpxy-mbox.yaml +F: drivers/clk/clk-rpmi.c +F: drivers/irqchip/irq-riscv-rpmi-sysmsi.c +F: drivers/mailbox/riscv-sbi-mpxy-mbox.c +F: include/linux/mailbox/riscv-rpmi-message.h + RISC-V SPACEMIT SoC Support M: Yixun Lan <[email protected]> L: [email protected]
Signature · 1 line
2.43.0