Skip to contentSkip to conversation

Add support for RPMI to U-Boot

PATCH Superseded Charles Perry 4 participants 18 messages Jun 26 – Jul 6

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Add support for RPMI to U-Boot

Hello,

This series adds support for RISC-V Platform Management Interface (RPMI) to U-Boot. RPMI is an OS-agnostic protocol for communication between an Application Processor (AP) and a Platform Microcontroller (PuC) [1]. The goals and purpose of RPMI are similar to ARM's SCMI.

This patchset first adds an abstraction layer for the transport (UCLASS_RPMI), then adds two transport layer (SBI MPXY and shared memory) and finally adds two client, or service group in RPMI jargon: Clock and device power service groups.

This series also include a sandbox mode for which the RPMI transport doesn't attach to a firmware but contains a simulation of a firmware. This reuses code from librpmi [2] to create the message responses.

Apart from the spec [1], this series reuses code from the Linux SBI MPXY driver [3], OpenSBI shared memory transport [4] and Linux RPMI clock driver [5].

This was tested on a PIC64-HPSC SoC which features an application cluster and a system controller with isolated address spaces, hence the need for RPMI. I've tested the interoperability between RPMI clients and transports with an S-Mode U-boot (using the MPXY transport) and M-Mode U-Boot (using shared memory transport) and the following device tree fragment:

```
	firmware {
		rpmi: mailbox@7000000000 {
			compatible = "riscv,rpmi-shmem-mbox";
			reg = <0x70 0x00000000 0x0 0x3000>,
				<0x70 0x00003000 0x0 0x3000>,
				<0x70 0x00006000 0x0 0x1000>,
				<0x70 0x00007000 0x0 0x1000>;
			reg-names = "a2p-req", "p2a-ack", "p2a-req", "a2p-ack";
			riscv,slot-size = <64>;
			#mbox-cells = <1>;
		};

ifndef CONFIG_RISCV_MMODE
		clock-service {
			compatible = "riscv,rpmi-mpxy-clock";
			mboxes = <&rpmi 0x8>;
			riscv,sbi-mpxy-channel-id = <0x1000>;
		};

		device-power-service {
			compatible = "riscv,rpmi-mpxy-device-power";
			mboxes = <&rpmi 0x9>;
			riscv,sbi-mpxy-channel-id = <0x1001>;
		};

		mpxy_mbox: mailbox {
			compatible = "riscv,sbi-mpxy-mbox";
			#mbox-cells = <2>;
		};
endif

		sysc_clk: clock-controller {
			compatible = "riscv,rpmi-clock";
ifdef CONFIG_RISCV_MMODE
			mboxes = <&rpmi 0x8>;
else
			mboxes = <&mpxy_mbox 0x1000 0x0>;
endif
			#clock-cells = <1>;
		};

		sysc_dpwr: power-domain-controller {
			compatible = "riscv,rpmi-device-power";
ifdef CONFIG_RISCV_MMODE
			mboxes = <&rpmi 0x9>;
else
			mboxes = <&mpxy_mbox 0x1001 0x0>;
endif
			#power-domain-cells = <1>;
		};
	};
```

[1]: https://github.com/riscv-non-isa/riscv-rpmi
[2]: https://github.com/riscv-software-src/librpmi
[3]: https://elixir.bootlin.com/linux/v7.0.10/source/drivers/mailbox/riscv-sbi-mpxy-mbox.c
[4]: https://elixir.bootlin.com/opensbi/v1.8.1/source/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
[5]: https://elixir.bootlin.com/linux/v7.0.10/source/drivers/clk/clk-rpmi.c

Cc Rahul Pathak <[email protected]>
Cc Anup Patel <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Alexandre Ghiti <[email protected]>
Cc Romain Caritey <[email protected]>
Cc Mame Maria Mbaye <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heinrich Schuchardt <[email protected]>
Cc Rick Chen <[email protected]>
Cc Leo Yu-Chi Liang <[email protected]>

Charles Perry (7):
firmware: add support for RPMI
firmware: rpmi: add support for the SBI MPXY transport
firmware: rpmi: add support for shared memory transport
drivers: clk: add support for RPMI clocks
drivers: power: add support for RPMI power domains
firmware: rpmi: add a test and a sandbox driver
firmware: rpmi: add a test and sandbox for device power

 MAINTAINERS                                |   9 +
 arch/riscv/include/asm/sbi.h               |  57 +++
 arch/sandbox/dts/test.dts                  |  23 +
 configs/sandbox_defconfig                  |   3 +
 drivers/clk/Kconfig                        |   7 +
 drivers/clk/Makefile                       |   1 +
 drivers/clk/clk_rpmi.c                     | 346 +++++++++++++++
 drivers/firmware/Kconfig                   |   1 +
 drivers/firmware/Makefile                  |   1 +
 drivers/firmware/rpmi/Kconfig              |  27 ++
 drivers/firmware/rpmi/Makefile             |   4 +
 drivers/firmware/rpmi/rpmi-sandbox-clock.c | 446 +++++++++++++++++++
 drivers/firmware/rpmi/rpmi-sandbox-power.c | 174 ++++++++
 drivers/firmware/rpmi/rpmi-sandbox.c       | 158 +++++++
 drivers/firmware/rpmi/rpmi-sandbox.h       |  48 +++
 drivers/firmware/rpmi/rpmi-sbi-mpxy.c      | 449 +++++++++++++++++++
 drivers/firmware/rpmi/rpmi-shmem.c         | 474 +++++++++++++++++++++
 drivers/firmware/rpmi/rpmi-uclass.c        | 138 ++++++
 drivers/power/domain/Kconfig               |   7 +
 drivers/power/domain/Makefile              |   1 +
 drivers/power/domain/rpmi-power-domain.c   | 229 ++++++++++
 include/dm/uclass-id.h                     |   1 +
 include/rpmi-uclass.h                      |  79 ++++
 include/rpmi.h                             | 159 +++++++
 include/rpmi_proto.h                       | 143 +++++++
 test/dm/Makefile                           |   1 +
 test/dm/rpmi.c                             |  69 +++
 27 files changed, 3055 insertions(+)
 create mode 100644 drivers/clk/clk_rpmi.c
 create mode 100644 drivers/firmware/rpmi/Kconfig
 create mode 100644 drivers/firmware/rpmi/Makefile
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox-clock.c
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox-power.c
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox.c
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox.h
 create mode 100644 drivers/firmware/rpmi/rpmi-sbi-mpxy.c
 create mode 100644 drivers/firmware/rpmi/rpmi-shmem.c
 create mode 100644 drivers/firmware/rpmi/rpmi-uclass.c
 create mode 100644 drivers/power/domain/rpmi-power-domain.c
 create mode 100644 include/rpmi-uclass.h
 create mode 100644 include/rpmi.h
 create mode 100644 include/rpmi_proto.h
 create mode 100644 test/dm/rpmi.c
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/7 firmware: add support for RPMI

RISC-V Platform Management Interface (RPMI) defines an OS-agnostic protocol for communication between an Application Processor (AP) and a platform microcontroller (PuC) [1]

Add UCLASS_RPMI to abstract the implementation details of an RPMI transport layer. A transport driver should implement the struct rpmi_transport_ops callback interface while an RPMI client driver should use struct rpmi_chan and the rpmi_* API:

* rpmi_get_by_index()
* rpmi_open()
* rpmi_close()
* rpmi_get_attr()
* rpmi_send_with_resp()
* rpmi_send_posted()

The most important part of the API is rpmi_send_with_resp() and rpmi_send_posted() which is used to send a message and possibly receive a response from the firmware.

rpmi_get_attr() can be used to retrieve attributes of the channel like the implementation ID or the maximum message size. This is to retrieve information that lives outside of the service group of the rpmi_chan, either in the "base service group" or in the transport layer itself.

rpmi_get_by_index() can be used to initialize a struct rpmi_chan using info from the device tree.

rpmi_open() and rpmi_close() must be called once at initialization and deinitialization by clients to let the transport layer do some stateful things if needed.

A helper function is also added: rpmi_check_versions() which is just a wrapper around rpmi_get_attr() to do some basic version checking that all clients should perform.

[1]: https://github.com/riscv-non-isa/riscv-rpmi

---
 MAINTAINERS                         |   6 ++
 drivers/firmware/Kconfig            |   1 +
 drivers/firmware/Makefile           |   1 +
 drivers/firmware/rpmi/Kconfig       |   9 ++
 drivers/firmware/rpmi/Makefile      |   1 +
 drivers/firmware/rpmi/rpmi-uclass.c | 138 ++++++++++++++++++++++++
 include/dm/uclass-id.h              |   1 +
 include/rpmi-uclass.h               |  79 ++++++++++++++
 include/rpmi.h                      | 159 ++++++++++++++++++++++++++++
 include/rpmi_proto.h                |  63 +++++++++++
 10 files changed, 458 insertions(+)
 create mode 100644 drivers/firmware/rpmi/Kconfig
 create mode 100644 drivers/firmware/rpmi/Makefile
 create mode 100644 drivers/firmware/rpmi/rpmi-uclass.c
 create mode 100644 include/rpmi-uclass.h
 create mode 100644 include/rpmi.h
 create mode 100644 include/rpmi_proto.h
MAINTAINERS +6 -0
index 571af1964654..8b8ae8e6cc9f 100644
@@ -1689,6 +1689,12 @@ F:	drivers/usb/gadget/f_rockusb.c
 F:	cmd/rockusb.c
 F:	doc/README.rockusb
 
+RPMI
+M:	Charles Perry <[email protected]>
+S:	Maintained
+F:	drivers/firmware/rpmi/
+F:	include/rpmi*
+
 SANDBOX
 M:	Simon Glass <[email protected]>
 S:	Maintained
drivers/firmware/Kconfig +1 -0
index 220de7319506..d1c3c2f666ee 100644
@@ -49,3 +49,4 @@ config ARM_SMCCC_FEATURES
 
 source "drivers/firmware/arm-ffa/Kconfig"
 source "drivers/firmware/scmi/Kconfig"
+source "drivers/firmware/rpmi/Kconfig"
drivers/firmware/Makefile +1 -0
index 9e7b118b074f..7d7b09a5d392 100644
@@ -4,3 +4,4 @@ obj-$(CONFIG_TI_SCI_PROTOCOL)	+= ti_sci.o
 obj-$(CONFIG_SANDBOX)		+= firmware-sandbox.o
 obj-$(CONFIG_ZYNQMP_FIRMWARE)	+= firmware-zynqmp.o
 obj-$(CONFIG_SCMI_FIRMWARE)	+= scmi/
+obj-$(CONFIG_RPMI_FIRMWARE)	+= rpmi/
drivers/firmware/rpmi/Kconfig new file +9 -0
new file mode 100644
index 000000000000..54fd77ad8f48
@@ -0,0 +1,9 @@
+config RPMI_FIRMWARE
+	bool "Enable RPMI support"
+	depends on RISCV && DM && OF_CONTROL
+	select FIRMWARE
+	help
+	  RISC-V Platform Management Interface (RPMI) defines an OS-agnostic
+	  protocol for communication between an Application Processor (AP) and a
+	  platform microcontroller (PuC). The RPMI specification is available
+	  at: https://github.com/riscv-non-isa/riscv-rpmi
drivers/firmware/rpmi/Makefile new file +1 -0
new file mode 100644
index 000000000000..d69c718d150e
@@ -0,0 +1 @@
+obj-y	+= rpmi-uclass.o
drivers/firmware/rpmi/rpmi-uclass.c new file +138 -0

138 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 36b5d87c304f..9e86780dcfb7 100644
@@ -128,6 +128,7 @@ enum uclass_id {
 	UCLASS_RESET,		/* Reset controller device */
 	UCLASS_RKMTD,		/* Rockchip MTD device */
 	UCLASS_RNG,		/* Random Number Generator */
+	UCLASS_RPMI,		/* RPMI transport */
 	UCLASS_RTC,		/* Real time clock device */
 	UCLASS_SCMI_AGENT,	/* Interface with an SCMI server */
 	UCLASS_SCMI_BASE,	/* Interface for SCMI Base protocol */
include/rpmi-uclass.h new file +79 -0

79 lines not on this page · raw message

include/rpmi.h new file +159 -0

159 lines not on this page · raw message

include/rpmi_proto.h new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 1/7] firmware: add support for RPMI

Quoted 57 lines · Charles Perry

RISC-V Platform Management Interface (RPMI) defines an OS-agnostic protocol for communication between an Application Processor (AP) and a platform microcontroller (PuC) [1]

Add UCLASS_RPMI to abstract the implementation details of an RPMI transport layer. A transport driver should implement the struct rpmi_transport_ops callback interface while an RPMI client driver should use struct rpmi_chan and the rpmi_* API:

* rpmi_get_by_index()
* rpmi_open()
* rpmi_close()
* rpmi_get_attr()
* rpmi_send_with_resp()
* rpmi_send_posted()

The most important part of the API is rpmi_send_with_resp() and rpmi_send_posted() which is used to send a message and possibly receive a response from the firmware.

rpmi_get_attr() can be used to retrieve attributes of the channel like the implementation ID or the maximum message size. This is to retrieve information that lives outside of the service group of the rpmi_chan, either in the "base service group" or in the transport layer itself.

rpmi_get_by_index() can be used to initialize a struct rpmi_chan using info from the device tree.

rpmi_open() and rpmi_close() must be called once at initialization and deinitialization by clients to let the transport layer do some stateful things if needed.

A helper function is also added: rpmi_check_versions() which is just a wrapper around rpmi_get_attr() to do some basic version checking that all clients should perform.

[1]: https://github.com/riscv-non-isa/riscv-rpmi

---
 MAINTAINERS                         |   6 ++
 drivers/firmware/Kconfig            |   1 +
 drivers/firmware/Makefile           |   1 +
 drivers/firmware/rpmi/Kconfig       |   9 ++
 drivers/firmware/rpmi/Makefile      |   1 +
 drivers/firmware/rpmi/rpmi-uclass.c | 138 ++++++++++++++++++++++++
 include/dm/uclass-id.h              |   1 +
 include/rpmi-uclass.h               |  79 ++++++++++++++
 include/rpmi.h                      | 159 ++++++++++++++++++++++++++++
 include/rpmi_proto.h                |  63 +++++++++++
 10 files changed, 458 insertions(+)
 create mode 100644 drivers/firmware/rpmi/Kconfig
 create mode 100644 drivers/firmware/rpmi/Makefile
 create mode 100644 drivers/firmware/rpmi/rpmi-uclass.c
 create mode 100644 include/rpmi-uclass.h
 create mode 100644 include/rpmi.h
 create mode 100644 include/rpmi_proto.h

...

Quoted 7 lines
drivers/firmware/rpmi/rpmi-uclass.c new file +1 -0
new file mode 100644
index 000000000000..b725f9e59441
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0

drivers/firmware/rpmi/rpmi-uclass.c line 11

Quoted 10 lines
drivers/firmware/rpmi/rpmi-uclass.c new file +10 -0
+/*
+ * Copyright (C) 2026 Microchip Technology Inc. All rights reserved.
+ */
+
+#define LOG_CATEGORY UCLASS_RPMI
+
+#include <dm.h>
+#include <log.h>
+#include <rpmi-uclass.h>
+#include <dm/device_compat.h>

Should we sort the headers? This applies to rest of the series, too.

...

drivers/firmware/rpmi/rpmi-uclass.c line 109

Quoted 13 lines
drivers/firmware/rpmi/rpmi-uclass.c new file +13 -0
+int rpmi_check_versions(struct rpmi_chan *chan, u32 min_proto_version,
+			u32 servicegroup_id_expect,
+			u32 min_servicegroup_version)
+{
+	u32 proto_version, servicegroup_id, servicegroup_version;
+	int ret;
+
+	ret = rpmi_get_attr(chan, RPMI_ATTR_SPEC_VERSION, &proto_version);
+	if (ret)
+		return ret;
+
+	if (proto_version < min_proto_version) {
+		dev_err(chan->dev, "protocol version mismatch\n");

The error is caused by a "too old" protocol version instead of a "mismatched" one, shouldn't we be precise here?

Furthermore, it would be good to print the the expected and implemented versions as well to ease debugging. debug() could be used so we don't get the binary size increased in a normal build. So do the servicegroup_id and servicegroup_version's case.

Quoted 24 lines
drivers/firmware/rpmi/rpmi-uclass.c new file +24 -0
+		return -EINVAL;
+	}
+
+	ret = rpmi_get_attr(chan, RPMI_ATTR_SERVICEGROUP_ID, &servicegroup_id);
+	if (ret)
+		return ret;
+
+	if (servicegroup_id != servicegroup_id_expect) {
+		dev_err(chan->dev, "service group match fail\n");
+		return -EINVAL;
+	}
+
+	ret = rpmi_get_attr(chan, RPMI_ATTR_SERVICEGROUP_VERSION,
+			    &servicegroup_version);
+	if (ret)
+		return ret;
+
+	if (servicegroup_version < min_servicegroup_version) {
+		dev_err(chan->dev, "service group version mismatch\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}

...

Quoted 5 lines
include/rpmi.h new file +0 -0
new file mode 100644
index 000000000000..de802026b31a

...

Quoted 4 lines
include/rpmi.h new file +4 -0
+static inline int rpmi_to_linux_error(int rpmi_error)
+{
+	switch (rpmi_error) {
+	case RPMI_SUCCESS:

include/rpmi.h line 43

Quoted 10 lines
include/rpmi.h new file +10 -0
+		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;

RPMI_ERR_HW_FAULT means "failed due to hardware fault" according to RPMI specification, does it really count as "-EFAULT" which is "bad address"?

Quoted 6 lines
include/rpmi.h new file +6 -0
+	case RPMI_ERR_ALREADY:
+		return -EALREADY;
+	case RPMI_ERR_BUSY:
+		return -EBUSY;
+	case RPMI_ERR_TIMEOUT:
+		return -ETIMEDOUT;

include/rpmi.h line 59

Quoted 10 lines
include/rpmi.h new file +10 -0
+	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;
+	}
+}

Regards,
Yao Zi

#3 lore raw

Re: [PATCH 1/7] firmware: add support for RPMI

Quoted 72 lines · Yao Zi
Quoted 57 lines · Charles Perry

RISC-V Platform Management Interface (RPMI) defines an OS-agnostic protocol for communication between an Application Processor (AP) and a platform microcontroller (PuC) [1]

Add UCLASS_RPMI to abstract the implementation details of an RPMI transport layer. A transport driver should implement the struct rpmi_transport_ops callback interface while an RPMI client driver should use struct rpmi_chan and the rpmi_* API:

* rpmi_get_by_index()
* rpmi_open()
* rpmi_close()
* rpmi_get_attr()
* rpmi_send_with_resp()
* rpmi_send_posted()

The most important part of the API is rpmi_send_with_resp() and rpmi_send_posted() which is used to send a message and possibly receive a response from the firmware.

rpmi_get_attr() can be used to retrieve attributes of the channel like the implementation ID or the maximum message size. This is to retrieve information that lives outside of the service group of the rpmi_chan, either in the "base service group" or in the transport layer itself.

rpmi_get_by_index() can be used to initialize a struct rpmi_chan using info from the device tree.

rpmi_open() and rpmi_close() must be called once at initialization and deinitialization by clients to let the transport layer do some stateful things if needed.

A helper function is also added: rpmi_check_versions() which is just a wrapper around rpmi_get_attr() to do some basic version checking that all clients should perform.

[1]: https://github.com/riscv-non-isa/riscv-rpmi

---
 MAINTAINERS                         |   6 ++
 drivers/firmware/Kconfig            |   1 +
 drivers/firmware/Makefile           |   1 +
 drivers/firmware/rpmi/Kconfig       |   9 ++
 drivers/firmware/rpmi/Makefile      |   1 +
 drivers/firmware/rpmi/rpmi-uclass.c | 138 ++++++++++++++++++++++++
 include/dm/uclass-id.h              |   1 +
 include/rpmi-uclass.h               |  79 ++++++++++++++
 include/rpmi.h                      | 159 ++++++++++++++++++++++++++++
 include/rpmi_proto.h                |  63 +++++++++++
 10 files changed, 458 insertions(+)
 create mode 100644 drivers/firmware/rpmi/Kconfig
 create mode 100644 drivers/firmware/rpmi/Makefile
 create mode 100644 drivers/firmware/rpmi/rpmi-uclass.c
 create mode 100644 include/rpmi-uclass.h
 create mode 100644 include/rpmi.h
 create mode 100644 include/rpmi_proto.h

...

Quoted 11 lines
drivers/firmware/rpmi/rpmi-uclass.c new file +5 -0
new file mode 100644
index 000000000000..b725f9e59441
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Microchip Technology Inc. All rights reserved.
+ */
+
Quoted 8 lines

drivers/firmware/rpmi/rpmi-uclass.c line 11

Quoted 6 lines
drivers/firmware/rpmi/rpmi-uclass.c new file +6 -0
+#define LOG_CATEGORY UCLASS_RPMI
+
+#include <dm.h>
+#include <log.h>
+#include <rpmi-uclass.h>
+#include <dm/device_compat.h>

Should we sort the headers? This applies to rest of the series, too.

Ack.

Quoted 20 lines

...

drivers/firmware/rpmi/rpmi-uclass.c line 109

Quoted 13 lines
drivers/firmware/rpmi/rpmi-uclass.c new file +13 -0
+int rpmi_check_versions(struct rpmi_chan *chan, u32 min_proto_version,
+			u32 servicegroup_id_expect,
+			u32 min_servicegroup_version)
+{
+	u32 proto_version, servicegroup_id, servicegroup_version;
+	int ret;
+
+	ret = rpmi_get_attr(chan, RPMI_ATTR_SPEC_VERSION, &proto_version);
+	if (ret)
+		return ret;
+
+	if (proto_version < min_proto_version) {
+		dev_err(chan->dev, "protocol version mismatch\n");

The error is caused by a "too old" protocol version instead of a "mismatched" one, shouldn't we be precise here?

Quoted 4 lines

Furthermore, it would be good to print the the expected and implemented versions as well to ease debugging. debug() could be used so we don't get the binary size increased in a normal build. So do the servicegroup_id and servicegroup_version's case.

Ack for everything.

Quoted 46 lines
Quoted 25 lines
drivers/firmware/rpmi/rpmi-uclass.c new file +24 -0
+		return -EINVAL;
+	}
+
+	ret = rpmi_get_attr(chan, RPMI_ATTR_SERVICEGROUP_ID, &servicegroup_id);
+	if (ret)
+		return ret;
+
+	if (servicegroup_id != servicegroup_id_expect) {
+		dev_err(chan->dev, "service group match fail\n");
+		return -EINVAL;
+	}
+
+	ret = rpmi_get_attr(chan, RPMI_ATTR_SERVICEGROUP_VERSION,
+			    &servicegroup_version);
+	if (ret)
+		return ret;
+
+	if (servicegroup_version < min_servicegroup_version) {
+		dev_err(chan->dev, "service group version mismatch\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}

...

Quoted 5 lines
include/rpmi.h new file +0 -0
new file mode 100644
index 000000000000..de802026b31a

...

Quoted 10 lines
include/rpmi.h new file +10 -0
+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:
Quoted 8 lines

include/rpmi.h line 43

Quoted 4 lines
include/rpmi.h new file +4 -0
+		return -EPERM;
+	case RPMI_ERR_INVALID_ADDR:
+	case RPMI_ERR_HW_FAULT:
+		return -EFAULT;

RPMI_ERR_HW_FAULT means "failed due to hardware fault" according to RPMI specification, does it really count as "-EFAULT" which is "bad address"?

This is taken as-is from Linux [1]. So unless there's a good reason to do things differently, I suggest we keep it as-is.

[1]: https://elixir.bootlin.com/linux/v7.1.2/source/include/linux/mailbox/riscv-rpmi-message.h#L62

Thanks,
Charles

#4 lore raw

PATCH 2/7 firmware: rpmi: add support for the SBI MPXY transport

In reply to Charles Perry

This adds an RPMI transport driver for the Supervisor Binary Interface (SBI) message proxy (MPXY) extension [1].

This is for S-Mode U-Boot where some supervisor software (such as OpenSBI) runs in M-Mode and handles the low level communication with the PuC.

[1]: https://github.com/riscv-non-isa/riscv-sbi-doc (chapter 20)

---
 arch/riscv/include/asm/sbi.h          |  57 ++++
 drivers/firmware/rpmi/Kconfig         |   9 +
 drivers/firmware/rpmi/Makefile        |   1 +
 drivers/firmware/rpmi/rpmi-sbi-mpxy.c | 449 ++++++++++++++++++++++++++
 4 files changed, 516 insertions(+)
 create mode 100644 drivers/firmware/rpmi/rpmi-sbi-mpxy.c
arch/riscv/include/asm/sbi.h +57 -0
index 47124dbaac84..10e03257d8e6 100644
@@ -10,6 +10,7 @@
 #define _ASM_RISCV_SBI_H
 
 #include <linux/types.h>
+#include <linux/errno.h>
 
 enum sbi_ext_id {
 	SBI_EXT_0_1_SET_TIMER = 0x0,
@@ -104,6 +105,17 @@ enum sbi_ext_dbcn_fid {
 	SBI_EXT_DBCN_CONSOLE_WRITE_BYTE,
 };
 
+enum sbi_ext_mpxy_fid {
+	SBI_EXT_MPXY_GET_SHMEM_SIZE = 0,
+	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,
+};
+
 #ifdef CONFIG_SBI_V01
 #define SBI_EXT_SET_TIMER		SBI_EXT_0_1_SET_TIMER
 #define SBI_FID_SET_TIMER		0
@@ -132,6 +144,14 @@ enum sbi_ext_dbcn_fid {
 #define SBI_SPEC_VERSION_MAJOR_MASK	0x7f
 #define SBI_SPEC_VERSION_MINOR_MASK	0xffffff
 
+static inline unsigned long sbi_mk_version(unsigned long major,
+					   unsigned long minor)
+{
+	return ((major & SBI_SPEC_VERSION_MAJOR_MASK)
+		<< SBI_SPEC_VERSION_MAJOR_SHIFT) |
+	       (minor & SBI_SPEC_VERSION_MINOR_MASK);
+}
+
 /* SBI return error codes */
 #define SBI_SUCCESS			0
 #define SBI_ERR_FAILURE			-1
@@ -139,6 +159,43 @@ enum sbi_ext_dbcn_fid {
 #define SBI_ERR_INVALID_PARAM		-3
 #define SBI_ERR_DENIED			-4
 #define SBI_ERR_INVALID_ADDRESS		-5
+#define SBI_ERR_ALREADY_AVAILABLE	-6
+#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		-14
+
+static inline int sbi_to_linux_error(int err)
+{
+	switch (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:
+		return -EINVAL;
+	case SBI_ERR_BAD_RANGE:
+		return -ERANGE;
+	case SBI_ERR_INVALID_ADDRESS:
+		return -EFAULT;
+	case SBI_ERR_NO_SHMEM:
+		return -ENOMEM;
+	case SBI_ERR_TIMEOUT:
+		return -ETIMEDOUT;
+	case SBI_ERR_IO:
+		return -EIO;
+	case SBI_ERR_NOT_SUPPORTED:
+	case SBI_ERR_FAILURE:
+	default:
+		return -EOPNOTSUPP;
+	};
+}
 
 struct sbiret {
 	long error;
drivers/firmware/rpmi/Kconfig +9 -0
index 54fd77ad8f48..708d931263ff 100644
@@ -7,3 +7,12 @@ config RPMI_FIRMWARE
 	  protocol for communication between an Application Processor (AP) and a
 	  platform microcontroller (PuC). The RPMI specification is available
 	  at: https://github.com/riscv-non-isa/riscv-rpmi
+
+config RPMI_SBI_MPXY
+	bool "RPMI over SBI MPXY transport"
+	depends on RPMI_FIRMWARE && SBI
+	help
+	  Enable support for transport of RPMI messages over the message proxy
+	  (MPXY) extension of the supervisor binary interface (SBI). The
+	  specification for the MPXY extension is available at:
+	  https://github.com/riscv-non-isa/riscv-sbi-doc (chapter 20)
drivers/firmware/rpmi/Makefile +1 -0
index d69c718d150e..71c4aeaed910 100644
@@ -1 +1,2 @@
 obj-y	+= rpmi-uclass.o
+obj-$(CONFIG_RPMI_SBI_MPXY) += rpmi-sbi-mpxy.o
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +449 -0

449 lines not on this page · raw message

Signature · 1 line
2.47.3
#5 lore raw

Re: [PATCH 2/7] firmware: rpmi: add support for the SBI MPXY transport

Quoted 17 lines · Charles Perry

This adds an RPMI transport driver for the Supervisor Binary Interface (SBI) message proxy (MPXY) extension [1].

This is for S-Mode U-Boot where some supervisor software (such as OpenSBI) runs in M-Mode and handles the low level communication with the PuC.

[1]: https://github.com/riscv-non-isa/riscv-sbi-doc (chapter 20)

---
 arch/riscv/include/asm/sbi.h          |  57 ++++
 drivers/firmware/rpmi/Kconfig         |   9 +
 drivers/firmware/rpmi/Makefile        |   1 +
 drivers/firmware/rpmi/rpmi-sbi-mpxy.c | 449 ++++++++++++++++++++++++++
 4 files changed, 516 insertions(+)
 create mode 100644 drivers/firmware/rpmi/rpmi-sbi-mpxy.c

...

Quoted 5 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +0 -0
new file mode 100644
index 000000000000..84af4787187a

...

drivers/firmware/rpmi/rpmi-sbi-mpxy.c line 89

Quoted 13 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +13 -0
+/* 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_IMPL_ID,
+	SBI_MPXY_RPMI_ATTR_IMPL_VERSION,
+	SBI_MPXY_RPMI_ATTR_MAX_ID
+};
+
+/*
+ * RPMI specific SBI MPXY channel attributes.
+ */
+struct sbi_mpxy_rpmi_channel_attrs {

Would it make sense to organize sbi_mpxy_rpmi_channel_attrs as an array indexed by sbi_mpxy_rpmi_attributed_id subtracted by SBI_MPXY_RPMI_ATTR_MSGPROTO_ATTR_START? With which we could simplify rpmi_sbi_mpxy_get_attr().

Quoted 9 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +9 -0
+	/* RPMI service group ID */
+	u32 servicegroup_id;
+	/* RPMI service group version */
+	u32 servicegroup_version;
+	/* RPMI implementation ID */
+	u32 impl_id;
+	/* RPMI implementation version */
+	u32 impl_version;
+};

...

Quoted 31 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +31 -0
+static int rpmi_sbi_mpxy_get_attr(struct rpmi_chan *chan,
+				  enum rpmi_attribute_id id, u32 *data)
+{
+	struct rpmi_sbi_mpxy *mpxy = dev_get_priv(chan->dev);
+	struct sbi_mpxy_chan_desc *desc = &mpxy->channel_descs[chan->id];
+
+	switch (id) {
+	case RPMI_ATTR_SPEC_VERSION:
+		*data = desc->attrs.msg_proto_version;
+		break;
+	case RPMI_ATTR_MAX_MSG_DATA_SIZE:
+		*data = desc->max_xfer_len;
+		break;
+	case RPMI_ATTR_SERVICEGROUP_ID:
+		*data = desc->rpmi_attrs.servicegroup_id;
+		break;
+	case RPMI_ATTR_SERVICEGROUP_VERSION:
+		*data = desc->rpmi_attrs.servicegroup_version;
+		break;
+	case RPMI_ATTR_IMPL_ID:
+		*data = desc->rpmi_attrs.impl_id;
+		break;
+	case RPMI_ATTR_IMPL_VERSION:
+		*data = desc->rpmi_attrs.impl_version;
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}

...

Quoted 45 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +45 -0
+static int rpmi_sbi_mpxy_probe(struct udevice *dev)
+{
+	struct rpmi_sbi_mpxy *mpxy = dev_get_priv(dev);
+	struct sbi_mpxy_chan_desc *desc;
+	unsigned long flags;
+	struct sbiret sret;
+	int i, ret;
+
+	mpxy->dev = dev;
+
+	/* Probe for SBI MPXY extension */
+	if (sbi_get_spec_version() < sbi_mk_version(1, 0) ||
+	    sbi_probe_extension(SBI_EXT_MPXY) <= 0) {
+		dev_info(dev, "SBI MPXY extension not available\n");
+		return -ENODEV;
+	}
+
+	/* Find-out shared memory size */
+	ret = rpmi_sbi_mpxy_get_shmem_size(&mpxy->shmem_size);
+	if (ret) {
+		dev_err(dev, "failed to get MPXY shared memory size\n");
+		return -ENODEV;
+	}
+
+	mpxy->shmem = memalign(PAGE_SIZE, mpxy->shmem_size);
+	if (!mpxy->shmem)
+		return -ENOMEM;
+
+	/* Setup shmem in OVERWRITE mode. (flags[1:0] = 00b) */
+	flags = 0;
+	sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SET_SHMEM,
+			 virt_to_phys(mpxy->shmem), 0, flags, 0, 0, 0);
+	if (sret.error) {
+		ret = sbi_to_linux_error(sret.error);
+		goto err;
+	}
+
+	ret = rpmi_sbi_mpxy_get_channel_ids(mpxy);
+	if (ret)
+		goto err;
+
+	for (i = 0; i < mpxy->channel_count; i++) {
+		desc = &mpxy->channel_descs[i];
+		desc->max_xfer_len =
+			min((u32)mpxy->shmem_size, desc->attrs.msg_max_len);

drivers/firmware/rpmi/rpmi-sbi-mpxy.c line 411

Quoted 10 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +10 -0
+	}
+
+	return 0;
+
+err:
+	if (mpxy->channel_descs)
+		free(mpxy->channel_descs);
+
+	if (mpxy->shmem)
+		free(mpxy->shmem);

free() is no-op when the argument is NULL, so the check is redundant. This applies to rpmi_sbi_mpxy_remove() and other similar cases in the series, too.

Quoted 6 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +6 -0
+
+	return ret;
+}
+
+static int rpmi_sbi_mpxy_remove(struct udevice *dev)
+{

drivers/firmware/rpmi/rpmi-sbi-mpxy.c line 427

Quoted 10 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +10 -0
+	struct rpmi_sbi_mpxy *mpxy = dev_get_priv(dev);
+
+	if (mpxy->channel_descs)
+		free(mpxy->channel_descs);
+
+	if (mpxy->shmem)
+		free(mpxy->shmem);
+
+	return 0;
+}

Regards,
Yao Zi

#6 lore raw

Re: [PATCH 2/7] firmware: rpmi: add support for the SBI MPXY transport

Quoted 39 lines · Yao Zi
Quoted 17 lines · Charles Perry

This adds an RPMI transport driver for the Supervisor Binary Interface (SBI) message proxy (MPXY) extension [1].

This is for S-Mode U-Boot where some supervisor software (such as OpenSBI) runs in M-Mode and handles the low level communication with the PuC.

[1]: https://github.com/riscv-non-isa/riscv-sbi-doc (chapter 20)

---
 arch/riscv/include/asm/sbi.h          |  57 ++++
 drivers/firmware/rpmi/Kconfig         |   9 +
 drivers/firmware/rpmi/Makefile        |   1 +
 drivers/firmware/rpmi/rpmi-sbi-mpxy.c | 449 ++++++++++++++++++++++++++
 4 files changed, 516 insertions(+)
 create mode 100644 drivers/firmware/rpmi/rpmi-sbi-mpxy.c

...

Quoted 5 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +0 -0
new file mode 100644
index 000000000000..84af4787187a

...

Quoted 10 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +10 -0
+/* 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_IMPL_ID,
+	SBI_MPXY_RPMI_ATTR_IMPL_VERSION,
+	SBI_MPXY_RPMI_ATTR_MAX_ID
+};
+
+/*
Quoted 8 lines
Quoted 3 lines

+ * RPMI specific SBI MPXY channel attributes.
+ */
+struct sbi_mpxy_rpmi_channel_attrs {

Would it make sense to organize sbi_mpxy_rpmi_channel_attrs as an array indexed by sbi_mpxy_rpmi_attributed_id subtracted by SBI_MPXY_RPMI_ATTR_MSGPROTO_ATTR_START? With which we could simplify rpmi_sbi_mpxy_get_attr().

Yes I'll give this a try. I also find this a bit repetitive that the attributes have an id and a struct where each members are sorted by attribute id. Thanks!

Quoted 98 lines
Quoted 10 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +9 -0
+	/* RPMI service group ID */
+	u32 servicegroup_id;
+	/* RPMI service group version */
+	u32 servicegroup_version;
+	/* RPMI implementation ID */
+	u32 impl_id;
+	/* RPMI implementation version */
+	u32 impl_version;
+};

...

Quoted 31 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +31 -0
+static int rpmi_sbi_mpxy_get_attr(struct rpmi_chan *chan,
+				  enum rpmi_attribute_id id, u32 *data)
+{
+	struct rpmi_sbi_mpxy *mpxy = dev_get_priv(chan->dev);
+	struct sbi_mpxy_chan_desc *desc = &mpxy->channel_descs[chan->id];
+
+	switch (id) {
+	case RPMI_ATTR_SPEC_VERSION:
+		*data = desc->attrs.msg_proto_version;
+		break;
+	case RPMI_ATTR_MAX_MSG_DATA_SIZE:
+		*data = desc->max_xfer_len;
+		break;
+	case RPMI_ATTR_SERVICEGROUP_ID:
+		*data = desc->rpmi_attrs.servicegroup_id;
+		break;
+	case RPMI_ATTR_SERVICEGROUP_VERSION:
+		*data = desc->rpmi_attrs.servicegroup_version;
+		break;
+	case RPMI_ATTR_IMPL_ID:
+		*data = desc->rpmi_attrs.impl_id;
+		break;
+	case RPMI_ATTR_IMPL_VERSION:
+		*data = desc->rpmi_attrs.impl_version;
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}

...

Quoted 51 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +51 -0
+static int rpmi_sbi_mpxy_probe(struct udevice *dev)
+{
+	struct rpmi_sbi_mpxy *mpxy = dev_get_priv(dev);
+	struct sbi_mpxy_chan_desc *desc;
+	unsigned long flags;
+	struct sbiret sret;
+	int i, ret;
+
+	mpxy->dev = dev;
+
+	/* Probe for SBI MPXY extension */
+	if (sbi_get_spec_version() < sbi_mk_version(1, 0) ||
+	    sbi_probe_extension(SBI_EXT_MPXY) <= 0) {
+		dev_info(dev, "SBI MPXY extension not available\n");
+		return -ENODEV;
+	}
+
+	/* Find-out shared memory size */
+	ret = rpmi_sbi_mpxy_get_shmem_size(&mpxy->shmem_size);
+	if (ret) {
+		dev_err(dev, "failed to get MPXY shared memory size\n");
+		return -ENODEV;
+	}
+
+	mpxy->shmem = memalign(PAGE_SIZE, mpxy->shmem_size);
+	if (!mpxy->shmem)
+		return -ENOMEM;
+
+	/* Setup shmem in OVERWRITE mode. (flags[1:0] = 00b) */
+	flags = 0;
+	sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SET_SHMEM,
+			 virt_to_phys(mpxy->shmem), 0, flags, 0, 0, 0);
+	if (sret.error) {
+		ret = sbi_to_linux_error(sret.error);
+		goto err;
+	}
+
+	ret = rpmi_sbi_mpxy_get_channel_ids(mpxy);
+	if (ret)
+		goto err;
+
+	for (i = 0; i < mpxy->channel_count; i++) {
+		desc = &mpxy->channel_descs[i];
+		desc->max_xfer_len =
+			min((u32)mpxy->shmem_size, desc->attrs.msg_max_len);
+	}
+
+	return 0;
+
+err:
+	if (mpxy->channel_descs)
Quoted 8 lines

drivers/firmware/rpmi/rpmi-sbi-mpxy.c line 411

Quoted 4 lines
drivers/firmware/rpmi/rpmi-sbi-mpxy.c new file +4 -0
+		free(mpxy->channel_descs);
+
+	if (mpxy->shmem)
+		free(mpxy->shmem);

free() is no-op when the argument is NULL, so the check is redundant. This applies to rpmi_sbi_mpxy_remove() and other similar cases in the series, too.

Ack.

Thanks,
Charles

#7 lore raw

PATCH 3/7 firmware: rpmi: add support for shared memory transport

In reply to Charles Perry

Add support for transport of RPMI messages over shared memory as described in the RPMI spec [1]. This uses two or four ring buffers composed of a fixed number of "slots" to pass messages between the AP and the PuC. U-Boot is the Application processor (AP) and sends messages through the a2p-req queue and receives response though the p2a-ack queue. There is no support for platform microcontroller (PuC) initiated requests nor notifications.

This transport can be used in M or S mode U-Boot, but in the S-mode case, one must make sure that the supervisor software isn't already using the AP side of the shared memory.

[1]: https://github.com/riscv-non-isa/riscv-rpmi (chapter 2)

---
 drivers/firmware/rpmi/Kconfig      |   8 +
 drivers/firmware/rpmi/Makefile     |   1 +
 drivers/firmware/rpmi/rpmi-shmem.c | 474 +++++++++++++++++++++++++++++
 include/rpmi_proto.h               |  23 ++
 4 files changed, 506 insertions(+)
 create mode 100644 drivers/firmware/rpmi/rpmi-shmem.c
drivers/firmware/rpmi/Kconfig +8 -0
index 708d931263ff..421a1fa9deba 100644
@@ -16,3 +16,11 @@ config RPMI_SBI_MPXY
 	  (MPXY) extension of the supervisor binary interface (SBI). The
 	  specification for the MPXY extension is available at:
 	  https://github.com/riscv-non-isa/riscv-sbi-doc (chapter 20)
+
+config RPMI_SHMEM
+	bool "RPMI over shared memory transport"
+	depends on RPMI_FIRMWARE
+	help
+	  Enable support for transport of RPMI messages over shared memory as
+	  described in chapter 2 of the RPMI specification, available at:
+	  https://github.com/riscv-non-isa/riscv-rpmi
drivers/firmware/rpmi/Makefile +1 -0
index 71c4aeaed910..4f4bcb929db4 100644
@@ -1,2 +1,3 @@
 obj-y	+= rpmi-uclass.o
 obj-$(CONFIG_RPMI_SBI_MPXY) += rpmi-sbi-mpxy.o
+obj-$(CONFIG_RPMI_SHMEM) += rpmi-shmem.o
drivers/firmware/rpmi/rpmi-shmem.c new file +474 -0

474 lines not on this page · raw message

include/rpmi_proto.h +23 -0
index 012ae93d7317..4b557bfeedf5 100644
@@ -60,4 +60,27 @@ enum rpmi_servicegroup_id {
 	RPMI_SRVGRP_VENDOR_END		= 0xFFFF,
 };
 
+/** RPMI Base ServiceGroup Service IDs */
+enum rpmi_base_service_id {
+	RPMI_BASE_SRV_ENABLE_NOTIFICATION = 0x01,
+	RPMI_BASE_SRV_GET_IMPLEMENTATION_VERSION = 0x02,
+	RPMI_BASE_SRV_GET_IMPLEMENTATION_IDN = 0x03,
+	RPMI_BASE_SRV_GET_SPEC_VERSION = 0x04,
+	RPMI_BASE_SRV_GET_PLATFORM_INFO = 0x05,
+	RPMI_BASE_SRV_PROBE_SERVICE_GROUP = 0x06,
+	RPMI_BASE_SRV_GET_ATTRIBUTES = 0x07,
+};
+
+/** RPMI Messages Types */
+enum rpmi_message_type {
+	/* Normal request backed with ack */
+	RPMI_MSG_NORMAL_REQUEST = 0x0,
+	/* Request without any ack */
+	RPMI_MSG_POSTED_REQUEST = 0x1,
+	/* Acknowledgment for normal request message */
+	RPMI_MSG_ACKNOWLDGEMENT = 0x2,
+	/* Notification message */
+	RPMI_MSG_NOTIFICATION = 0x3,
+};
+
 #endif
Signature · 1 line
2.47.3
#8 lore raw

PATCH 4/7 drivers: clk: add support for RPMI clocks

In reply to Charles Perry

The RISC-V Platform Management Interface (RPMI) defines a service group for control and monitoring of clocks [1]. This can be exposed as a UCLASS_CLK driver.

[1]: https://github.com/riscv-non-isa/riscv-rpmi (chapter 4.8)

---
 MAINTAINERS            |   1 +
 drivers/clk/Kconfig    |   7 +
 drivers/clk/Makefile   |   1 +
 drivers/clk/clk_rpmi.c | 346 +++++++++++++++++++++++++++++++++++++++++
 include/rpmi_proto.h   |  39 +++++
 5 files changed, 394 insertions(+)
 create mode 100644 drivers/clk/clk_rpmi.c
MAINTAINERS +1 -0
index 8b8ae8e6cc9f..0bf6582ef493 100644
@@ -1692,6 +1692,7 @@ F:	doc/README.rockusb
 RPMI
 M:	Charles Perry <[email protected]>
 S:	Maintained
+F:	drivers/clk/clk_rpmi.c
 F:	drivers/firmware/rpmi/
 F:	include/rpmi*
 
drivers/clk/Kconfig +7 -0
index c2da7b3938b6..c8cb4a4a71cd 100644
@@ -181,6 +181,13 @@ config CLK_OCTEON
 	help
 	  Enable this to support the clocks on Octeon MIPS platforms.
 
+config CLK_RPMI
+	bool "Enable RPMI clock driver"
+	depends on CLK && RPMI_FIRMWARE
+	help
+	  Enable this option if you want to support clock devices exposed
+	  by RISC-V Platform Management Interface (RPMI).
+
 config SANDBOX_CLK_CCF
 	bool "Sandbox Common Clock Framework [CCF] support"
 	depends on SANDBOX
drivers/clk/Makefile +1 -0
index 5f0c0d8a5c28..b0d9ca3cf9bb 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_CLK_OCTEON) += clk_octeon.o
 obj-$(CONFIG_CLK_OWL) += owl/
 obj-$(CONFIG_CLK_QCOM) += qcom/
 obj-$(CONFIG_CLK_RENESAS) += renesas/
+obj-$(CONFIG_CLK_RPMI) += clk_rpmi.o
 obj-$(CONFIG_$(PHASE_)CLK_SCMI) += clk_scmi.o
 obj-$(CONFIG_CLK_SIFIVE) += sifive/
 obj-$(CONFIG_CLK_SOPHGO) += sophgo/
drivers/clk/clk_rpmi.c new file +346 -0

346 lines not on this page · raw message

include/rpmi_proto.h +39 -0
index 4b557bfeedf5..dc0937ce7053 100644
@@ -83,4 +83,43 @@ enum rpmi_message_type {
 	RPMI_MSG_NOTIFICATION = 0x3,
 };
 
+/* 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
+};
+
+/** Clock rate match mode */
+enum rpmi_clock_rate_match {
+	RPMI_CLK_RATE_MATCH_PLATFORM	= 0,
+	RPMI_CLK_RATE_MATCH_ROUND_DOWN	= 1,
+	RPMI_CLK_RATE_MATCH_ROUND_UP	= 2,
+	RPMI_CLK_RATE_MATCH_MAX
+};
+
+/** Supported clock states */
+enum rpmi_clock_state {
+	RPMI_CLK_STATE_DISABLED	= 0,
+	RPMI_CLK_STATE_ENABLED	= 1,
+	RPMI_CLK_STATE_MAX
+};
+
+/** Clock type based on rate format */
+enum rpmi_clock_type {
+	RPMI_CLK_TYPE_DISCRETE	= 0,
+	RPMI_CLK_TYPE_LINEAR	= 1,
+	RPMI_CLK_TYPE_MAX
+};
+
+#define RPMI_CLK_NAME_LEN 16
+
+#define RPMI_CLOCK_RATE_INVALID		(-1ULL)
+
 #endif
Signature · 1 line
2.47.3
#9 lore raw

Re: [PATCH 4/7] drivers: clk: add support for RPMI clocks

Quoted 15 lines · Charles Perry

The RISC-V Platform Management Interface (RPMI) defines a service group for control and monitoring of clocks [1]. This can be exposed as a UCLASS_CLK driver.

[1]: https://github.com/riscv-non-isa/riscv-rpmi (chapter 4.8)

---
 MAINTAINERS            |   1 +
 drivers/clk/Kconfig    |   7 +
 drivers/clk/Makefile   |   1 +
 drivers/clk/clk_rpmi.c | 346 +++++++++++++++++++++++++++++++++++++++++
 include/rpmi_proto.h   |  39 +++++
 5 files changed, 394 insertions(+)
 create mode 100644 drivers/clk/clk_rpmi.c

...

Quoted 6 lines
drivers/clk/clk_rpmi.c new file +0 -0
new file mode 100644
index 000000000000..d2efb057600b
@@ -0,0 +1,346 @@

...

drivers/clk/clk_rpmi.c line 55

Quoted 3 lines
drivers/clk/clk_rpmi.c new file +3 -0
+struct rpmi_clk_def {
+	u32 num_rates;
+	u32 transition_latency;

rpmi_clk_def.transition_latency only gets assigned in rpmi_clk_get_attrs() and never used. Since U-Boot's clock infrastructure doesn't care about it at all, maybe we could drop the field?

Quoted 3 lines
drivers/clk/clk_rpmi.c new file +3 -0
+	enum rpmi_clock_type type;
+	char name[RPMI_CLK_NAME_LEN + 1];
+};

...

Quoted 11 lines
drivers/clk/clk_rpmi.c new file +11 -0
+static int _rpmi_clk_enable_disable(struct rpmi_clk_priv *priv, u32 clkid,
+				    bool ena)
+{
+	struct rpmi_set_config_tx tx = {
+		.clkid = cpu_to_le32(clkid),
+		.config = cpu_to_le32(ena ? RPMI_CLK_STATE_ENABLED :
+					    RPMI_CLK_STATE_DISABLED),
+	};
+	__le32 rx;
+	int ret, status;
+

drivers/clk/clk_rpmi.c line 86

Quoted 10 lines
drivers/clk/clk_rpmi.c new file +10 -0
+	ret = rpmi_send_with_resp(&priv->chan, RPMI_CLK_SRV_SET_CONFIG, &tx,
+				  sizeof(tx), &rx, sizeof(rx), NULL);
+	if (ret)
+		return ret;
+
+	status = le32_to_cpu(rx);
+	if (status)
+		return rpmi_to_linux_error(status);
+
+	return 0;

Please return rpmi_to_linux_error(status) and drop the if above.

Quoted 19 lines
drivers/clk/clk_rpmi.c new file +19 -0
+}
+
+static ulong _rpmi_clk_get_rate(struct rpmi_clk_priv *priv, u32 clkid)
+{
+	__le32 tx = cpu_to_le32(clkid);
+	struct rpmi_get_rate_rx rx;
+	int ret, status;
+
+	ret = rpmi_send_with_resp(&priv->chan, RPMI_CLK_SRV_GET_RATE, &tx,
+				  sizeof(tx), &rx, sizeof(rx), NULL);
+	if (ret)
+		return ret;
+
+	status = le32_to_cpu(rx.status);
+	if (status)
+		return rpmi_to_linux_error(status);
+
+	return (((u64)(le32_to_cpu(rx.hi)) << 32) | (u32)(le32_to_cpu(rx.lo)));
+}

...

drivers/clk/clk_rpmi.c line 127

Quoted 2 lines
drivers/clk/clk_rpmi.c new file +2 -0
+static int _rpmi_clk_set_rate(struct rpmi_clk_priv *priv, u32 clkid,
+			      unsigned long rate)

This function is declared to return int, but...

Quoted 10 lines
drivers/clk/clk_rpmi.c new file +10 -0
+{
+	struct rpmi_set_rate_tx tx = {
+		.clkid = cpu_to_le32(clkid),
+		.flags = 0,
+		.lo = cpu_to_le32(lower_32_bits(rate)),
+		.hi = cpu_to_le32(upper_32_bits(rate)),
+	};
+	__le32 rx;
+	int ret, status;
+

drivers/clk/clk_rpmi.c line 147

Quoted 10 lines
drivers/clk/clk_rpmi.c new file +10 -0
+	ret = rpmi_send_with_resp(&priv->chan, RPMI_CLK_SRV_SET_RATE, &tx,
+				  sizeof(tx), &rx, sizeof(rx), NULL);
+	if (ret)
+		return ret;
+
+	status = le32_to_cpu(rx);
+	if (status)
+		return rpmi_to_linux_error(status);
+
+	return _rpmi_clk_get_rate(priv, clkid);

_rpmi_clk_get_rate() returns ulong. This unnecessarily truncates the rate on 64bit platform when it's above approximately 2.1GHz.

Quoted 1 line

+}

Regards,
Yao Zi

#10 lore raw

Re: [PATCH 4/7] drivers: clk: add support for RPMI clocks

Quoted 28 lines · Yao Zi
Quoted 15 lines · Charles Perry

The RISC-V Platform Management Interface (RPMI) defines a service group for control and monitoring of clocks [1]. This can be exposed as a UCLASS_CLK driver.

[1]: https://github.com/riscv-non-isa/riscv-rpmi (chapter 4.8)

---
 MAINTAINERS            |   1 +
 drivers/clk/Kconfig    |   7 +
 drivers/clk/Makefile   |   1 +
 drivers/clk/clk_rpmi.c | 346 +++++++++++++++++++++++++++++++++++++++++
 include/rpmi_proto.h   |  39 +++++
 5 files changed, 394 insertions(+)
 create mode 100644 drivers/clk/clk_rpmi.c

...

Quoted 6 lines
drivers/clk/clk_rpmi.c new file +0 -0
new file mode 100644
index 000000000000..d2efb057600b
@@ -0,0 +1,346 @@

...

Quoted 7 lines

drivers/clk/clk_rpmi.c line 55

Quoted 3 lines
drivers/clk/clk_rpmi.c new file +3 -0
+struct rpmi_clk_def {
+	u32 num_rates;
+	u32 transition_latency;

rpmi_clk_def.transition_latency only gets assigned in rpmi_clk_get_attrs() and never used. Since U-Boot's clock infrastructure doesn't care about it at all, maybe we could drop the field?

Ack.

Quoted 22 lines
Quoted 4 lines
drivers/clk/clk_rpmi.c new file +3 -0
+	enum rpmi_clock_type type;
+	char name[RPMI_CLK_NAME_LEN + 1];
+};

...

Quoted 15 lines
drivers/clk/clk_rpmi.c new file +15 -0
+static int _rpmi_clk_enable_disable(struct rpmi_clk_priv *priv, u32 clkid,
+				    bool ena)
+{
+	struct rpmi_set_config_tx tx = {
+		.clkid = cpu_to_le32(clkid),
+		.config = cpu_to_le32(ena ? RPMI_CLK_STATE_ENABLED :
+					    RPMI_CLK_STATE_DISABLED),
+	};
+	__le32 rx;
+	int ret, status;
+
+	ret = rpmi_send_with_resp(&priv->chan, RPMI_CLK_SRV_SET_CONFIG, &tx,
+				  sizeof(tx), &rx, sizeof(rx), NULL);
+	if (ret)
+		return ret;
Quoted 8 lines

drivers/clk/clk_rpmi.c line 86

Quoted 6 lines
drivers/clk/clk_rpmi.c new file +6 -0
+
+	status = le32_to_cpu(rx);
+	if (status)
+		return rpmi_to_linux_error(status);
+
+	return 0;

Please return rpmi_to_linux_error(status) and drop the if above.

Ack.

Quoted 43 lines
Quoted 20 lines
drivers/clk/clk_rpmi.c new file +19 -0
+}
+
+static ulong _rpmi_clk_get_rate(struct rpmi_clk_priv *priv, u32 clkid)
+{
+	__le32 tx = cpu_to_le32(clkid);
+	struct rpmi_get_rate_rx rx;
+	int ret, status;
+
+	ret = rpmi_send_with_resp(&priv->chan, RPMI_CLK_SRV_GET_RATE, &tx,
+				  sizeof(tx), &rx, sizeof(rx), NULL);
+	if (ret)
+		return ret;
+
+	status = le32_to_cpu(rx.status);
+	if (status)
+		return rpmi_to_linux_error(status);
+
+	return (((u64)(le32_to_cpu(rx.hi)) << 32) | (u32)(le32_to_cpu(rx.lo)));
+}

...

drivers/clk/clk_rpmi.c line 127

Quoted 2 lines
drivers/clk/clk_rpmi.c new file +2 -0
+static int _rpmi_clk_set_rate(struct rpmi_clk_priv *priv, u32 clkid,
+			      unsigned long rate)

This function is declared to return int, but...

Quoted 15 lines
drivers/clk/clk_rpmi.c new file +15 -0
+{
+	struct rpmi_set_rate_tx tx = {
+		.clkid = cpu_to_le32(clkid),
+		.flags = 0,
+		.lo = cpu_to_le32(lower_32_bits(rate)),
+		.hi = cpu_to_le32(upper_32_bits(rate)),
+	};
+	__le32 rx;
+	int ret, status;
+
+	ret = rpmi_send_with_resp(&priv->chan, RPMI_CLK_SRV_SET_RATE, &tx,
+				  sizeof(tx), &rx, sizeof(rx), NULL);
+	if (ret)
+		return ret;
+
Quoted 8 lines

drivers/clk/clk_rpmi.c line 147

Quoted 5 lines
drivers/clk/clk_rpmi.c new file +5 -0
+	status = le32_to_cpu(rx);
+	if (status)
+		return rpmi_to_linux_error(status);
+
+	return _rpmi_clk_get_rate(priv, clkid);

_rpmi_clk_get_rate() returns ulong. This unnecessarily truncates the rate on 64bit platform when it's above approximately 2.1GHz.

Good catch.

I'll keep the return code as int here and put the call to _rpmi_clk_get_rate() inside rpmi_clk_set_rate() instead.

Thanks,
Charles

#11 lore raw

PATCH 5/7 drivers: power: add support for RPMI power domains

In reply to Charles Perry

The RISC-V Platform Management Interface (RPMI) defines the device power service group [1] that is used to control power domains. This is used to implement a UCLASS_POWER_DOMAIN driver.

[1]: https://github.com/riscv-non-isa/riscv-rpmi (chapter 4.9)

---
 MAINTAINERS                              |   1 +
 drivers/power/domain/Kconfig             |   7 +
 drivers/power/domain/Makefile            |   1 +
 drivers/power/domain/rpmi-power-domain.c | 229 +++++++++++++++++++++++
 include/rpmi_proto.h                     |  18 ++
 5 files changed, 256 insertions(+)
 create mode 100644 drivers/power/domain/rpmi-power-domain.c
MAINTAINERS +1 -0
index 0bf6582ef493..d2b18d9b13db 100644
@@ -1694,6 +1694,7 @@ M:	Charles Perry <[email protected]>
 S:	Maintained
 F:	drivers/clk/clk_rpmi.c
 F:	drivers/firmware/rpmi/
+F:	drivers/power/domain/rpmi-power-domain.c
 F:	include/rpmi*
 
 SANDBOX
drivers/power/domain/Kconfig +7 -0
index 4112b777371d..e8484b193cad 100644
@@ -106,6 +106,13 @@ config RENESAS_R8A78000_POWER_DOMAIN
 	  and reset driver. The MDLC is responsible for managing both
 	  power domains and resets on R-Car R8A78000 X5H SoC.
 
+config RPMI_POWER_DOMAIN
+	bool "Enable the RPMI Power domain driver"
+	depends on POWER_DOMAIN && RPMI_FIRMWARE
+	help
+	  Enable this option if you want to support power domains managed by
+	  the RISC-V Platform Management Interface (RPMI) protocol.
+
 config SANDBOX_POWER_DOMAIN
 	bool "Enable the sandbox power domain test driver"
 	depends on POWER_DOMAIN && SANDBOX
drivers/power/domain/Makefile +1 -0
index 110153d5cf81..9c42160e18be 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_MESON_GX_VPU_POWER_DOMAIN) += meson-gx-pwrc-vpu.o
 obj-$(CONFIG_MESON_EE_POWER_DOMAIN) += meson-ee-pwrc.o
 obj-$(CONFIG_MESON_SECURE_POWER_DOMAIN) += meson-secure-pwrc.o
 obj-$(CONFIG_RENESAS_R8A78000_POWER_DOMAIN) += renesas-r8a78000-power-domain.o
+obj-$(CONFIG_RPMI_POWER_DOMAIN) += rpmi-power-domain.o
 obj-$(CONFIG_SANDBOX_POWER_DOMAIN) += sandbox-power-domain.o
 obj-$(CONFIG_SANDBOX_POWER_DOMAIN) += sandbox-power-domain-test.o
 obj-$(CONFIG_SCMI_POWER_DOMAIN) += scmi-power-domain.o
drivers/power/domain/rpmi-power-domain.c new file +229 -0

229 lines not on this page · raw message

include/rpmi_proto.h +18 -0
index dc0937ce7053..d2512617f75c 100644
@@ -122,4 +122,22 @@ enum rpmi_clock_type {
 
 #define RPMI_CLOCK_RATE_INVALID		(-1ULL)
 
+/* RPMI Device_Power (DPWR) service IDs */
+enum rpmi_dpwr_service_id {
+	RPMI_DPWR_SRV_ENABLE_NOTIFICATION = 0x01,
+	RPMI_DPWR_SRV_GET_NUM_DOMAINS = 0x02,
+	RPMI_DPWR_SRV_GET_ATTRIBUTES = 0x03,
+	RPMI_DPWR_SRV_SET_DPWR_STATE = 0x04,
+	RPMI_DPWR_SRV_GET_DPWR_STATE = 0x05,
+	RPMI_DPWR_SRV_ID_MAX,
+};
+
+enum rpmi_dpwr_state {
+	RPMI_DPWR_STATE_INVALID = -1,
+	RPMI_DPWR_STATE_ON = 0,
+	RPMI_DPWR_STATE_OFF = 3,
+};
+
+#define RPMI_DPWR_NAME_LEN 16
+
 #endif
Signature · 1 line
2.47.3
#12 lore raw

Re: [PATCH 5/7] drivers: power: add support for RPMI power domains

Quoted 8 lines · Charles Perry

The RISC-V Platform Management Interface (RPMI) defines the device power service group [1] that is used to control power domains. This is used to implement a UCLASS_POWER_DOMAIN driver.

[1]: https://github.com/riscv-non-isa/riscv-rpmi (chapter 4.9)

---

...

drivers/power/domain/rpmi-power-domain.c line 215

Quoted 4 lines
drivers/power/domain/rpmi-power-domain.c new file +4 -0
+};
+
+static const struct udevice_id rpmi_pd_ids[] = {
+	{ .compatible = "riscv,rpmi-device-power" },

Not find this binding in Linux kernel or dt-schema.

Regards
Peng.

#13 lore raw

Re: [PATCH 5/7] drivers: power: add support for RPMI power domains

Quoted 17 lines · Peng Fan
Quoted 8 lines · Charles Perry

The RISC-V Platform Management Interface (RPMI) defines the device power service group [1] that is used to control power domains. This is used to implement a UCLASS_POWER_DOMAIN driver.

[1]: https://github.com/riscv-non-isa/riscv-rpmi (chapter 4.9)

---

...

drivers/power/domain/rpmi-power-domain.c line 215

Quoted 4 lines
drivers/power/domain/rpmi-power-domain.c new file +4 -0
+};
+
+static const struct udevice_id rpmi_pd_ids[] = {
+	{ .compatible = "riscv,rpmi-device-power" },

Not find this binding in Linux kernel or dt-schema.

Quoted 2 lines

Regards
Peng.

Right.

I'll remove the device power service group in the next version. This is not strictly needed for the initial introduction of RPMI and can be added latter.

Thanks,
Charles

#14 lore raw

PATCH 6/7 firmware: rpmi: add a test and a sandbox driver

In reply to Charles Perry

Create a new transport layer that sends the messages to a simulated RPMI firmware.

For now, this only contains a simulation of the clock service group which is implemented using code from librpmi [1] and adapted.

Also add a test in test/dm that makes use of the RPMI clock driver.

[1]: https://github.com/riscv-software-src/librpmi/blob/3f3c4ca47339a8795432e260f17e1fc5091c9a3a/lib/rpmi_service_group_clock.c

---
 MAINTAINERS                                |   1 +
 arch/sandbox/dts/test.dts                  |  12 +
 configs/sandbox_defconfig                  |   2 +
 drivers/firmware/rpmi/Kconfig              |   3 +-
 drivers/firmware/rpmi/Makefile             |   1 +
 drivers/firmware/rpmi/rpmi-sandbox-clock.c | 446 +++++++++++++++++++++
 drivers/firmware/rpmi/rpmi-sandbox.c       | 156 +++++++
 drivers/firmware/rpmi/rpmi-sandbox.h       |  47 +++
 test/dm/Makefile                           |   1 +
 test/dm/rpmi.c                             |  48 +++
 10 files changed, 716 insertions(+), 1 deletion(-)
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox-clock.c
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox.c
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox.h
 create mode 100644 test/dm/rpmi.c
MAINTAINERS +1 -0
index d2b18d9b13db..96fee47ade6c 100644
@@ -1696,6 +1696,7 @@ F:	drivers/clk/clk_rpmi.c
 F:	drivers/firmware/rpmi/
 F:	drivers/power/domain/rpmi-power-domain.c
 F:	include/rpmi*
+F:	test/dm/rpmi.c
 
 SANDBOX
 M:	Simon Glass <[email protected]>
arch/sandbox/dts/test.dts +12 -0
index 0887de4333b0..e5d6f398fb35 100644
@@ -874,6 +874,18 @@
 		sm: secure-monitor {
 			compatible = "sandbox,sm";
 		};
+
+		rpmi: rpmi {
+			compatible = "sandbox,rpmi-transport";
+			#mbox-cells = <1>;
+		};
+
+		rpmi_clock: rpmi-clock {
+			compatible = "riscv,rpmi-clock";
+			mboxes = <&rpmi 0x8>;
+			#clock-cells = <1>;
+			clocks = <&rpmi_clock 0>, <&rpmi_clock 1>, <&rpmi_clock 2>, <&rpmi_clock 3>;
+		};
 	};
 
 	fpga {
configs/sandbox_defconfig +2 -0
index ba800f7d19da..f1637e1ff09c 100644
@@ -191,6 +191,7 @@ CONFIG_BUTTON_GPIO=y
 CONFIG_CLK=y
 CONFIG_CLK_K210=y
 CONFIG_CLK_K210_SET_RATE=y
+CONFIG_CLK_RPMI=y
 CONFIG_SANDBOX_CLK_CCF=y
 CONFIG_CLK_SCMI=y
 CONFIG_CPU=y
@@ -207,6 +208,7 @@ CONFIG_FASTBOOT_FLASH=y
 CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_ARM_FFA_TRANSPORT=y
 CONFIG_SCMI_FIRMWARE=y
+CONFIG_RPMI_FIRMWARE=y
 CONFIG_FPGA_ALTERA=y
 CONFIG_FPGA_STRATIX_II=y
 CONFIG_FPGA_STRATIX_V=y
drivers/firmware/rpmi/Kconfig +2 -1
index 421a1fa9deba..b462d3693987 100644
@@ -1,6 +1,7 @@
 config RPMI_FIRMWARE
 	bool "Enable RPMI support"
-	depends on RISCV && DM && OF_CONTROL
+	depends on RISCV || SANDBOX
+	depends on DM && OF_CONTROL
 	select FIRMWARE
 	help
 	  RISC-V Platform Management Interface (RPMI) defines an OS-agnostic
drivers/firmware/rpmi/Makefile +1 -0
index 4f4bcb929db4..150e98a72df9 100644
@@ -1,3 +1,4 @@
 obj-y	+= rpmi-uclass.o
 obj-$(CONFIG_RPMI_SBI_MPXY) += rpmi-sbi-mpxy.o
 obj-$(CONFIG_RPMI_SHMEM) += rpmi-shmem.o
+obj-$(CONFIG_SANDBOX)	+= rpmi-sandbox.o rpmi-sandbox-clock.o
drivers/firmware/rpmi/rpmi-sandbox-clock.c new file +446 -0

446 lines not on this page · raw message

drivers/firmware/rpmi/rpmi-sandbox.c new file +156 -0

156 lines not on this page · raw message

drivers/firmware/rpmi/rpmi-sandbox.h new file +47 -0

47 lines not on this page · raw message

test/dm/Makefile +1 -0
index 0e3c63568ddb..ee03b4e13de2 100644
@@ -109,6 +109,7 @@ obj-$(CONFIG_CMD_RKMTD) += rkmtd.o
 obj-$(CONFIG_$(PHASE_)DM_RNG) += rng.o
 obj-$(CONFIG_DM_RTC) += rtc.o
 obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o
+obj-$(CONFIG_RPMI_FIRMWARE) += rpmi.o
 obj-$(CONFIG_SCSI) += scsi.o
 obj-$(CONFIG_DM_SERIAL) += serial.o
 obj-$(CONFIG_DM_SPI_FLASH) += sf.o
test/dm/rpmi.c new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.47.3
#15 lore raw

PATCH 7/7 firmware: rpmi: add a test and sandbox for device power

In reply to Charles Perry

Add a simulation of the device power service group using code from librpmi [1] and adapted.

[1]: https://github.com/riscv-software-src/librpmi/blob/3f3c4ca47339a8795432e260f17e1fc5091c9a3a/lib/rpmi_service_group_device_power.c

---
 arch/sandbox/dts/test.dts                  |  11 ++
 configs/sandbox_defconfig                  |   1 +
 drivers/firmware/rpmi/Makefile             |   2 +-
 drivers/firmware/rpmi/rpmi-sandbox-power.c | 174 +++++++++++++++++++++
 drivers/firmware/rpmi/rpmi-sandbox.c       |   2 +
 drivers/firmware/rpmi/rpmi-sandbox.h       |   1 +
 test/dm/rpmi.c                             |  21 +++
 7 files changed, 211 insertions(+), 1 deletion(-)
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox-power.c
arch/sandbox/dts/test.dts +11 -0
index e5d6f398fb35..7e25053851f4 100644
@@ -886,6 +886,12 @@
 			#clock-cells = <1>;
 			clocks = <&rpmi_clock 0>, <&rpmi_clock 1>, <&rpmi_clock 2>, <&rpmi_clock 3>;
 		};
+
+		rpmi_dpwr: rpmi-power-domain {
+			compatible = "riscv,rpmi-device-power";
+			mboxes = <&rpmi 0x9>;
+			#power-domain-cells = <1>;
+		};
 	};
 
 	fpga {
@@ -1927,6 +1933,11 @@
 		regul1-supply = <&regul1_scmi>;
 	};
 
+	rpmi-power-domain-test {
+		compatible = "sandbox,power-domain-test";
+		power-domains = <&rpmi_dpwr 1>;
+	};
+
 	pinctrl {
 		compatible = "sandbox,pinctrl";
 
configs/sandbox_defconfig +1 -0
index f1637e1ff09c..59967bd2ee0f 100644
@@ -289,6 +289,7 @@ CONFIG_PINCONF=y
 CONFIG_PINCTRL_SANDBOX=y
 CONFIG_PINCTRL_SINGLE=y
 CONFIG_POWER_DOMAIN=y
+CONFIG_RPMI_POWER_DOMAIN=y
 CONFIG_SANDBOX_POWER_DOMAIN=y
 CONFIG_SCMI_POWER_DOMAIN=y
 CONFIG_DM_PMIC=y
drivers/firmware/rpmi/Makefile +1 -1
index 150e98a72df9..c73ad92baec1 100644
@@ -1,4 +1,4 @@
 obj-y	+= rpmi-uclass.o
 obj-$(CONFIG_RPMI_SBI_MPXY) += rpmi-sbi-mpxy.o
 obj-$(CONFIG_RPMI_SHMEM) += rpmi-shmem.o
-obj-$(CONFIG_SANDBOX)	+= rpmi-sandbox.o rpmi-sandbox-clock.o
+obj-$(CONFIG_SANDBOX)	+= rpmi-sandbox.o rpmi-sandbox-clock.o rpmi-sandbox-power.o
drivers/firmware/rpmi/rpmi-sandbox-power.c new file +174 -0

174 lines not on this page · raw message

drivers/firmware/rpmi/rpmi-sandbox.c +2 -0
index 5597c27067eb..c34c61da5d9e 100644
@@ -29,6 +29,8 @@ const struct rpmi_service_group *rpmi_sandbox_sg(u32 servicegroup_id)
 	switch (servicegroup_id) {
 	case RPMI_SRVGRP_CLOCK:
 		return &rpmi_sandbox_clock_sg;
+	case RPMI_SRVGRP_DEVICE_POWER:
+		return &rpmi_sandbox_dpwr_sg;
 	default:
 		return NULL;
 	}
drivers/firmware/rpmi/rpmi-sandbox.h +1 -0
index 132d1e9e8be6..7dea5035929e 100644
@@ -43,5 +43,6 @@ struct rpmi_service_group {
 };
 
 extern const struct rpmi_service_group rpmi_sandbox_clock_sg;
+extern const struct rpmi_service_group rpmi_sandbox_dpwr_sg;
 
 #endif
test/dm/rpmi.c +21 -0
index 1ea29780a480..e886b9ab2da4 100644
@@ -9,6 +9,7 @@
 #include <stdio.h>
 #include <dm/device-internal.h>
 #include <dm/test.h>
+#include <asm/power-domain.h>
 #include <test/ut.h>
 
 static int dm_test_rpmi_clock(struct unit_test_state *uts)
@@ -46,3 +47,23 @@ static int dm_test_rpmi_clock(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_rpmi_clock, UTF_SCAN_FDT);
+
+static int dm_test_rpmi_dpwr(struct unit_test_state *uts)
+{
+	struct udevice *rpmi_dev, *dpwr_dev, *dpwr_consumer;
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_RPMI, "rpmi", &rpmi_dev));
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_POWER_DOMAIN,
+					      "rpmi-power-domain", &dpwr_dev));
+
+	ut_assertok(uclass_get_device_by_name(
+		UCLASS_MISC, "rpmi-power-domain-test", &dpwr_consumer));
+
+	ut_assertok(sandbox_power_domain_test_get(dpwr_consumer));
+	ut_assertok(sandbox_power_domain_test_on(dpwr_consumer));
+	ut_assertok(sandbox_power_domain_test_off(dpwr_consumer));
+
+	return 0;
+}
+DM_TEST(dm_test_rpmi_dpwr, UTF_SCAN_FDT);
Signature · 1 line
2.47.3
#16 lore raw
In reply to Charles Perry
Quoted 100 lines · Charles Perry

Hello,

This series adds support for RISC-V Platform Management Interface (RPMI) to U-Boot. RPMI is an OS-agnostic protocol for communication between an Application Processor (AP) and a Platform Microcontroller (PuC) [1]. The goals and purpose of RPMI are similar to ARM's SCMI.

This patchset first adds an abstraction layer for the transport (UCLASS_RPMI), then adds two transport layer (SBI MPXY and shared memory) and finally adds two client, or service group in RPMI jargon: Clock and device power service groups.

This series also include a sandbox mode for which the RPMI transport doesn't attach to a firmware but contains a simulation of a firmware. This reuses code from librpmi [2] to create the message responses.

Apart from the spec [1], this series reuses code from the Linux SBI MPXY driver [3], OpenSBI shared memory transport [4] and Linux RPMI clock driver [5].

This was tested on a PIC64-HPSC SoC which features an application cluster and a system controller with isolated address spaces, hence the need for RPMI. I've tested the interoperability between RPMI clients and transports with an S-Mode U-boot (using the MPXY transport) and M-Mode U-Boot (using shared memory transport) and the following device tree fragment:

```
        firmware {
                rpmi: mailbox@7000000000 {
                        compatible = "riscv,rpmi-shmem-mbox";
                        reg = <0x70 0x00000000 0x0 0x3000>,
                                <0x70 0x00003000 0x0 0x3000>,
                                <0x70 0x00006000 0x0 0x1000>,
                                <0x70 0x00007000 0x0 0x1000>;
                        reg-names = "a2p-req", "p2a-ack", "p2a-req", "a2p-ack";
                        riscv,slot-size = <64>;
                        #mbox-cells = <1>;
                };

ifndef CONFIG_RISCV_MMODE
                clock-service {
                        compatible = "riscv,rpmi-mpxy-clock";
                        mboxes = <&rpmi 0x8>;
                        riscv,sbi-mpxy-channel-id = <0x1000>;
                };

                device-power-service {
                        compatible = "riscv,rpmi-mpxy-device-power";
                        mboxes = <&rpmi 0x9>;
                        riscv,sbi-mpxy-channel-id = <0x1001>;
                };

                mpxy_mbox: mailbox {
                        compatible = "riscv,sbi-mpxy-mbox";
                        #mbox-cells = <2>;
                };
endif

                sysc_clk: clock-controller {
                        compatible = "riscv,rpmi-clock";
ifdef CONFIG_RISCV_MMODE
                        mboxes = <&rpmi 0x8>;
else
                        mboxes = <&mpxy_mbox 0x1000 0x0>;
endif
                        #clock-cells = <1>;
                };

                sysc_dpwr: power-domain-controller {
                        compatible = "riscv,rpmi-device-power";
ifdef CONFIG_RISCV_MMODE
                        mboxes = <&rpmi 0x9>;
else
                        mboxes = <&mpxy_mbox 0x1001 0x0>;
endif
                        #power-domain-cells = <1>;
                };
        };
```

[1]: https://github.com/riscv-non-isa/riscv-rpmi
[2]: https://github.com/riscv-software-src/librpmi
[3]: https://elixir.bootlin.com/linux/v7.0.10/source/drivers/mailbox/riscv-sbi-mpxy-mbox.c
[4]: https://elixir.bootlin.com/opensbi/v1.8.1/source/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
[5]: https://elixir.bootlin.com/linux/v7.0.10/source/drivers/clk/clk-rpmi.c

Cc Rahul Pathak <[email protected]>
Cc Anup Patel <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Alexandre Ghiti <[email protected]>
Cc Romain Caritey <[email protected]>
Cc Mame Maria Mbaye <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heinrich Schuchardt <[email protected]>
Cc Rick Chen <[email protected]>
Cc Leo Yu-Chi Liang <[email protected]>
Quoted 8 lines

Charles Perry (7):
firmware: add support for RPMI
firmware: rpmi: add support for the SBI MPXY transport
firmware: rpmi: add support for shared memory transport
drivers: clk: add support for RPMI clocks
drivers: power: add support for RPMI power domains
firmware: rpmi: add a test and a sandbox driver
firmware: rpmi: add a test and sandbox for device power

I have a more general question.

Why add separate firmware framework for RPMI ?

You can just extend the existing U-Boot mailbox framework and just like we have in Linux. The separate transport drivers will be mailbox-controller drivers and each service group will have a separate mailbox-client driver under appropriate driver subsystem.

Quoted 45 lines
 MAINTAINERS                                |   9 +
 arch/riscv/include/asm/sbi.h               |  57 +++
 arch/sandbox/dts/test.dts                  |  23 +
 configs/sandbox_defconfig                  |   3 +
 drivers/clk/Kconfig                        |   7 +
 drivers/clk/Makefile                       |   1 +
 drivers/clk/clk_rpmi.c                     | 346 +++++++++++++++
 drivers/firmware/Kconfig                   |   1 +
 drivers/firmware/Makefile                  |   1 +
 drivers/firmware/rpmi/Kconfig              |  27 ++
 drivers/firmware/rpmi/Makefile             |   4 +
 drivers/firmware/rpmi/rpmi-sandbox-clock.c | 446 +++++++++++++++++++
 drivers/firmware/rpmi/rpmi-sandbox-power.c | 174 ++++++++
 drivers/firmware/rpmi/rpmi-sandbox.c       | 158 +++++++
 drivers/firmware/rpmi/rpmi-sandbox.h       |  48 +++
 drivers/firmware/rpmi/rpmi-sbi-mpxy.c      | 449 +++++++++++++++++++
 drivers/firmware/rpmi/rpmi-shmem.c         | 474 +++++++++++++++++++++
 drivers/firmware/rpmi/rpmi-uclass.c        | 138 ++++++
 drivers/power/domain/Kconfig               |   7 +
 drivers/power/domain/Makefile              |   1 +
 drivers/power/domain/rpmi-power-domain.c   | 229 ++++++++++
 include/dm/uclass-id.h                     |   1 +
 include/rpmi-uclass.h                      |  79 ++++
 include/rpmi.h                             | 159 +++++++
 include/rpmi_proto.h                       | 143 +++++++
 test/dm/Makefile                           |   1 +
 test/dm/rpmi.c                             |  69 +++
 27 files changed, 3055 insertions(+)
 create mode 100644 drivers/clk/clk_rpmi.c
 create mode 100644 drivers/firmware/rpmi/Kconfig
 create mode 100644 drivers/firmware/rpmi/Makefile
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox-clock.c
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox-power.c
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox.c
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox.h
 create mode 100644 drivers/firmware/rpmi/rpmi-sbi-mpxy.c
 create mode 100644 drivers/firmware/rpmi/rpmi-shmem.c
 create mode 100644 drivers/firmware/rpmi/rpmi-uclass.c
 create mode 100644 drivers/power/domain/rpmi-power-domain.c
 create mode 100644 include/rpmi-uclass.h
 create mode 100644 include/rpmi.h
 create mode 100644 include/rpmi_proto.h
 create mode 100644 test/dm/rpmi.c
Quoted 3 lines

--
2.47.3

Regards,
Anup

#17 lore raw
Quoted 113 lines · Anup Patel
Quoted 100 lines · Charles Perry

Hello,

This series adds support for RISC-V Platform Management Interface (RPMI) to U-Boot. RPMI is an OS-agnostic protocol for communication between an Application Processor (AP) and a Platform Microcontroller (PuC) [1]. The goals and purpose of RPMI are similar to ARM's SCMI.

This patchset first adds an abstraction layer for the transport (UCLASS_RPMI), then adds two transport layer (SBI MPXY and shared memory) and finally adds two client, or service group in RPMI jargon: Clock and device power service groups.

This series also include a sandbox mode for which the RPMI transport doesn't attach to a firmware but contains a simulation of a firmware. This reuses code from librpmi [2] to create the message responses.

Apart from the spec [1], this series reuses code from the Linux SBI MPXY driver [3], OpenSBI shared memory transport [4] and Linux RPMI clock driver [5].

This was tested on a PIC64-HPSC SoC which features an application cluster and a system controller with isolated address spaces, hence the need for RPMI. I've tested the interoperability between RPMI clients and transports with an S-Mode U-boot (using the MPXY transport) and M-Mode U-Boot (using shared memory transport) and the following device tree fragment:

```
        firmware {
                rpmi: mailbox@7000000000 {
                        compatible = "riscv,rpmi-shmem-mbox";
                        reg = <0x70 0x00000000 0x0 0x3000>,
                                <0x70 0x00003000 0x0 0x3000>,
                                <0x70 0x00006000 0x0 0x1000>,
                                <0x70 0x00007000 0x0 0x1000>;
                        reg-names = "a2p-req", "p2a-ack", "p2a-req", "a2p-ack";
                        riscv,slot-size = <64>;
                        #mbox-cells = <1>;
                };

ifndef CONFIG_RISCV_MMODE
                clock-service {
                        compatible = "riscv,rpmi-mpxy-clock";
                        mboxes = <&rpmi 0x8>;
                        riscv,sbi-mpxy-channel-id = <0x1000>;
                };

                device-power-service {
                        compatible = "riscv,rpmi-mpxy-device-power";
                        mboxes = <&rpmi 0x9>;
                        riscv,sbi-mpxy-channel-id = <0x1001>;
                };

                mpxy_mbox: mailbox {
                        compatible = "riscv,sbi-mpxy-mbox";
                        #mbox-cells = <2>;
                };
endif

                sysc_clk: clock-controller {
                        compatible = "riscv,rpmi-clock";
ifdef CONFIG_RISCV_MMODE
                        mboxes = <&rpmi 0x8>;
else
                        mboxes = <&mpxy_mbox 0x1000 0x0>;
endif
                        #clock-cells = <1>;
                };

                sysc_dpwr: power-domain-controller {
                        compatible = "riscv,rpmi-device-power";
ifdef CONFIG_RISCV_MMODE
                        mboxes = <&rpmi 0x9>;
else
                        mboxes = <&mpxy_mbox 0x1001 0x0>;
endif
                        #power-domain-cells = <1>;
                };
        };
```

[1]: https://github.com/riscv-non-isa/riscv-rpmi
[2]: https://github.com/riscv-software-src/librpmi
[3]: https://elixir.bootlin.com/linux/v7.0.10/source/drivers/mailbox/riscv-sbi-mpxy-mbox.c
[4]: https://elixir.bootlin.com/opensbi/v1.8.1/source/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
[5]: https://elixir.bootlin.com/linux/v7.0.10/source/drivers/clk/clk-rpmi.c

Cc Rahul Pathak <[email protected]>
Cc Anup Patel <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Alexandre Ghiti <[email protected]>
Cc Romain Caritey <[email protected]>
Cc Mame Maria Mbaye <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heinrich Schuchardt <[email protected]>
Cc Rick Chen <[email protected]>
Cc Leo Yu-Chi Liang <[email protected]>
Quoted 8 lines

Charles Perry (7):
firmware: add support for RPMI
firmware: rpmi: add support for the SBI MPXY transport
firmware: rpmi: add support for shared memory transport
drivers: clk: add support for RPMI clocks
drivers: power: add support for RPMI power domains
firmware: rpmi: add a test and a sandbox driver
firmware: rpmi: add a test and sandbox for device power

I have a more general question.

Quoted 7 lines

Why add separate firmware framework for RPMI ?

You can just extend the existing U-Boot mailbox framework and just like we have in Linux. The separate transport drivers will be mailbox-controller drivers and each service group will have a separate mailbox-client driver under appropriate driver subsystem.

The mailbox framework of U-Boot is much simpler than the one of Linux and there's no real incentive to have RPMI piggyback on it. The extra code needed to do function dispatch with an enum and a union (struct rpmi_mbox_message [1] and this function [2] in Linux) so that everything can be funneled into the ->send_data() callback would add more churn than creating a new RPMI framework separate from mailbox. rpmi-uclass.c is 138 lines of code which is what I call the RPMI framework, which is about as much code as the definitions and code for the function dispatch code I mentionned above.

[1]: https://elixir.bootlin.com/linux/v7.1.2/source/include/linux/mailbox/riscv-rpmi-message.h#L144
[2]: https://elixir.bootlin.com/linux/v7.1.2/source/drivers/mailbox/riscv-sbi-mpxy-mbox.c#L400

Thanks,
Charles

Quoted 52 lines
Quoted 46 lines

 MAINTAINERS                                |   9 +
 arch/riscv/include/asm/sbi.h               |  57 +++
 arch/sandbox/dts/test.dts                  |  23 +
 configs/sandbox_defconfig                  |   3 +
 drivers/clk/Kconfig                        |   7 +
 drivers/clk/Makefile                       |   1 +
 drivers/clk/clk_rpmi.c                     | 346 +++++++++++++++
 drivers/firmware/Kconfig                   |   1 +
 drivers/firmware/Makefile                  |   1 +
 drivers/firmware/rpmi/Kconfig              |  27 ++
 drivers/firmware/rpmi/Makefile             |   4 +
 drivers/firmware/rpmi/rpmi-sandbox-clock.c | 446 +++++++++++++++++++
 drivers/firmware/rpmi/rpmi-sandbox-power.c | 174 ++++++++
 drivers/firmware/rpmi/rpmi-sandbox.c       | 158 +++++++
 drivers/firmware/rpmi/rpmi-sandbox.h       |  48 +++
 drivers/firmware/rpmi/rpmi-sbi-mpxy.c      | 449 +++++++++++++++++++
 drivers/firmware/rpmi/rpmi-shmem.c         | 474 +++++++++++++++++++++
 drivers/firmware/rpmi/rpmi-uclass.c        | 138 ++++++
 drivers/power/domain/Kconfig               |   7 +
 drivers/power/domain/Makefile              |   1 +
 drivers/power/domain/rpmi-power-domain.c   | 229 ++++++++++
 include/dm/uclass-id.h                     |   1 +
 include/rpmi-uclass.h                      |  79 ++++
 include/rpmi.h                             | 159 +++++++
 include/rpmi_proto.h                       | 143 +++++++
 test/dm/Makefile                           |   1 +
 test/dm/rpmi.c                             |  69 +++
 27 files changed, 3055 insertions(+)
 create mode 100644 drivers/clk/clk_rpmi.c
 create mode 100644 drivers/firmware/rpmi/Kconfig
 create mode 100644 drivers/firmware/rpmi/Makefile
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox-clock.c
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox-power.c
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox.c
 create mode 100644 drivers/firmware/rpmi/rpmi-sandbox.h
 create mode 100644 drivers/firmware/rpmi/rpmi-sbi-mpxy.c
 create mode 100644 drivers/firmware/rpmi/rpmi-shmem.c
 create mode 100644 drivers/firmware/rpmi/rpmi-uclass.c
 create mode 100644 drivers/power/domain/rpmi-power-domain.c
 create mode 100644 include/rpmi-uclass.h
 create mode 100644 include/rpmi.h
 create mode 100644 include/rpmi_proto.h
 create mode 100644 test/dm/rpmi.c
Quoted 3 lines

--
2.47.3

Regards,
Anup