firmware: add new driver for SCMI firmwares
Subsystems (3)
PATCH 1/4 firmware: add new driver for SCMI firmwares
This change introduces SCMI agent driver in U-Boot in the firmware U-class.
SCMI agent driver is designed for platforms that embed a SCMI server in a firmware hosted for example by a companion co-processor or the secure world of the executing processor.
SCMI protocols allow an SCMI agent to discover and access external resources as clock, reset controllers and many more. SCMI agent and server communicate following the SCMI specification [1]. SCMI agent complies with the DT bindings defined in the Linux kernel source tree regarding SCMI agent description since v5.8-rc1.
These bindings describe 2 supported message transport layer: using mailbox uclass devices or using Arm SMC invocation instruction. Both use a piece or shared memory for message data exchange.
In the current state, the SCMI agent driver does not bind to any SCMI protocol to a U-Boot device driver. Former changes will implement dedicated driver (i.e. an SCMI clock driver or an SCMI reset controller driver) and add bind supported SCMI protocols in scmi_agent_bind().
Links: [1] https://developer.arm.com/architectures/system-architectures/software-standards/scmi
---
drivers/firmware/Kconfig | 15 ++ drivers/firmware/Makefile | 1 + drivers/firmware/scmi.c | 439 ++++++++++++++++++++++++++++++++++++++ include/scmi.h | 82 +++++++ 4 files changed, 537 insertions(+) create mode 100644 drivers/firmware/scmi.c create mode 100644 include/scmi.h
drivers/firmware/Kconfig +15 -0
@@ -1,6 +1,21 @@ config FIRMWARE bool "Enable Firmware driver support" +config SCMI_FIRMWARE + bool "Enable SCMI support" + select FIRMWARE + select OF_TRANSLATE + depends on DM_MAILBOX || ARM_SMCCC + help + An SCMI agent communicates with a related SCMI server firmware + located in another sub-system, as a companion micro controller + or a companion host in the CPU system. + + Communications between agent (client) and the SCMI server are + based on message exchange. Messages can be exchange over tranport + channels as a mailbox device or an Arm SMCCC service with some + piece of identified shared memory. + config SPL_FIRMWARE bool "Enable Firmware driver support in SPL" depends on FIRMWARE
drivers/firmware/Makefile +1 -0
@@ -2,4 +2,5 @@ obj-$(CONFIG_FIRMWARE) += firmware-uclass.o obj-$(CONFIG_$(SPL_)ARM_PSCI_FW) += psci.o obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o obj-$(CONFIG_SANDBOX) += firmware-sandbox.o +obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o obj-$(CONFIG_ZYNQMP_FIRMWARE) += firmware-zynqmp.o
drivers/firmware/scmi.c new file +439 -0
439 lines not on this page · raw message
include/scmi.h new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/4 dt-bindings: arm: SCMI bindings documentation
Dump SCMI DT bindings documentation from Linux kernel source tree v5.8-rc1.
---
doc/device-tree-bindings/arm/arm,scmi.txt | 197 ++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 doc/device-tree-bindings/arm/arm,scmi.txt
doc/device-tree-bindings/arm/arm,scmi.txt new file +197 -0
@@ -0,0 +1,197 @@ +System Control and Management Interface (SCMI) Message Protocol +---------------------------------------------------------- + +The SCMI is intended to allow agents such as OSPM to manage various functions +that are provided by the hardware platform it is running on, including power +and performance functions. + +This binding is intended to define the interface the firmware implementing +the SCMI as described in ARM document number ARM DEN 0056A ("ARM System Control +and Management Interface Platform Design Document")[0] provide for OSPM in +the device tree. + +Required properties: + +The scmi node with the following properties shall be under the /firmware/ node. + +- compatible : shall be "arm,scmi" or "arm,scmi-smc" for smc/hvc transports +- mboxes: List of phandle and mailbox channel specifiers. It should contain + exactly one or two mailboxes, one for transmitting messages("tx") + and another optional for receiving the notifications("rx") if + supported. +- shmem : List of phandle pointing to the shared memory(SHM) area as per + generic mailbox client binding. +- #address-cells : should be '1' if the device has sub-nodes, maps to + protocol identifier for a given sub-node. +- #size-cells : should be '0' as 'reg' property doesn't have any size + associated with it. +- arm,smc-id : SMC id required when using smc or hvc transports + +Optional properties: + +- mbox-names: shall be "tx" or "rx" depending on mboxes entries. + +See Documentation/devicetree/bindings/mailbox/mailbox.txt for more details +about the generic mailbox controller and client driver bindings. + +The mailbox is the only permitted method of calling the SCMI firmware. +Mailbox doorbell is used as a mechanism to alert the presence of a +messages and/or notification. + +Each protocol supported shall have a sub-node with corresponding compatible +as described in the following sections. If the platform supports dedicated +communication channel for a particular protocol, the 3 properties namely: +mboxes, mbox-names and shmem shall be present in the sub-node corresponding +to that protocol. + +Clock/Performance bindings for the clocks/OPPs based on SCMI Message Protocol +------------------------------------------------------------ + +This binding uses the common clock binding[1]. + +Required properties: +- #clock-cells : Should be 1. Contains the Clock ID value used by SCMI commands. + +Power domain bindings for the power domains based on SCMI Message Protocol +------------------------------------------------------------ + +This binding for the SCMI power domain providers uses the generic power +domain binding[2]. + +Required properties: + - #power-domain-cells : Should be 1. Contains the device or the power + domain ID value used by SCMI commands. + +Sensor bindings for the sensors based on SCMI Message Protocol +-------------------------------------------------------------- +SCMI provides an API to access the various sensors on the SoC. + +Required properties: +- #thermal-sensor-cells: should be set to 1. This property follows the + thermal device tree bindings[3]. + + Valid cell values are raw identifiers (Sensor ID) + as used by the firmware. Refer to platform details + for your implementation for the IDs to use. + +Reset signal bindings for the reset domains based on SCMI Message Protocol +------------------------------------------------------------ + +This binding for the SCMI reset domain providers uses the generic reset +signal binding[5]. + +Required properties: + - #reset-cells : Should be 1. Contains the reset domain ID value used + by SCMI commands. + +SRAM and Shared Memory for SCMI +------------------------------- + +A small area of SRAM is reserved for SCMI communication between application +processors and SCP. + +The properties should follow the generic mmio-sram description found in [4] + +Each sub-node represents the reserved area for SCMI. + +Required sub-node properties: +- reg : The base offset and size of the reserved area with the SRAM +- compatible : should be "arm,scmi-shmem" for Non-secure SRAM based + shared memory + +[0] http://infocenter.arm.com/help/topic/com.arm.doc.den0056a/index.html +[1] Documentation/devicetree/bindings/clock/clock-bindings.txt +[2] Documentation/devicetree/bindings/power/power-domain.yaml +[3] Documentation/devicetree/bindings/thermal/thermal.txt +[4] Documentation/devicetree/bindings/sram/sram.yaml +[5] Documentation/devicetree/bindings/reset/reset.txt + +Example: + +sram at 50000000 { + compatible = "mmio-sram"; + reg = <0x0 0x50000000 0x0 0x10000>; + + #address-cells = <1>; + #size-cells = <1>; + ranges = <0 0x0 0x50000000 0x10000>; + + cpu_scp_lpri: scp-shmem at 0 { + compatible = "arm,scmi-shmem"; + reg = <0x0 0x200>; + }; + + cpu_scp_hpri: scp-shmem at 200 { + compatible = "arm,scmi-shmem"; + reg = <0x200 0x200>; + }; +}; + +mailbox at 40000000 { + .... + #mbox-cells = <1>; + reg = <0x0 0x40000000 0x0 0x10000>; +}; + +firmware { + + ... + + scmi { + compatible = "arm,scmi"; + mboxes = <&mailbox 0 &mailbox 1>; + mbox-names = "tx", "rx"; + shmem = <&cpu_scp_lpri &cpu_scp_hpri>; + #address-cells = <1>; + #size-cells = <0>; + + scmi_devpd: protocol at 11 { + reg = <0x11>; + #power-domain-cells = <1>; + }; + + scmi_dvfs: protocol at 13 { + reg = <0x13>; + #clock-cells = <1>; + }; + + scmi_clk: protocol at 14 { + reg = <0x14>; + #clock-cells = <1>; + }; + + scmi_sensors0: protocol at 15 { + reg = <0x15>; + #thermal-sensor-cells = <1>; + }; + + scmi_reset: protocol at 16 { + reg = <0x16>; + #reset-cells = <1>; + }; + }; +}; + +cpu at 0 { + ... + reg = <0 0>; + clocks = <&scmi_dvfs 0>; +}; + +hdlcd at 7ff60000 { + ... + reg = <0 0x7ff60000 0 0x1000>; + clocks = <&scmi_clk 4>; + power-domains = <&scmi_devpd 1>; + resets = <&scmi_reset 10>; +}; + +thermal-zones { + soc_thermal { + polling-delay-passive = <100>; + polling-delay = <1000>; + /* sensor ID */ + thermal-sensors = <&scmi_sensors0 3>; + ... + }; +};
Signature · 1 line
2.17.1
PATCH 2/4 dt-bindings: arm: SCMI bindings documentation
Quoted 10 lines · Etienne Carriere
Dump SCMI DT bindings documentation from Linux kernel source tree v5.8-rc1.
Signed-off-by Etienne Carriere <[email protected]>---
doc/device-tree-bindings/arm/arm,scmi.txt | 197 ++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 doc/device-tree-bindings/arm/arm,scmi.txt
PATCH 3/4 clk: add clock driver for SCMI agents
In reply to Etienne CarriereThis change introduces a clock driver for SCMI agent devices. When SCMI agent and SCMI clock drivers are enabled, SCMI agent binds a clock device for each SCMI clock protocol devices enabled in the FDT.
SCMI clock driver is embedded upon CONFIG_CLK_SCMI=y. If enabled, CONFIG_SCMI_AGENT is also enabled.
SCMI Clock protocol is defined in the SCMI specification [1].
Links: [1] https://developer.arm.com/architectures/system-architectures/software-standards/scmi
---
drivers/clk/Kconfig | 8 +++ drivers/clk/Makefile | 1 + drivers/clk/clk_scmi.c | 152 ++++++++++++++++++++++++++++++++++++++++ drivers/firmware/scmi.c | 3 + 4 files changed, 164 insertions(+) create mode 100644 drivers/clk/clk_scmi.c
drivers/clk/Kconfig +8 -0
@@ -152,6 +152,14 @@ config CLK_CDCE9XX Enable the clock synthesizer driver for CDCE913/925/937/949 series of chips. +config CLK_SCMI + bool "Enable SCMI clock driver" + select SCMI_FIRMWARE + help + Enable this option if you want to support clock devices exposed + by a SCMI agent based on SCMI clock protocol communication + with a SCMI server. + source "drivers/clk/analogbits/Kconfig" source "drivers/clk/at91/Kconfig" source "drivers/clk/exynos/Kconfig"
drivers/clk/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_CLK_K210) += kendryte/ obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o obj-$(CONFIG_CLK_OWL) += owl/ obj-$(CONFIG_CLK_RENESAS) += renesas/ +obj-$(CONFIG_CLK_SCMI) += clk_scmi.o obj-$(CONFIG_CLK_SIFIVE) += sifive/ obj-$(CONFIG_ARCH_SUNXI) += sunxi/ obj-$(CONFIG_CLK_STM32F) += clk_stm32f.o
drivers/clk/clk_scmi.c new file +152 -0
152 lines not on this page · raw message
drivers/firmware/scmi.c +3 -0
@@ -399,6 +399,9 @@ static int scmi_bind(struct udevice *dev)continue ;switch (protocol_id) { +case SCMI_PROTOCOL_ID_CLOCK : + drv =DM_GET_DRIVER (scmi_clock); +break ;default :dev_info (dev,"Ignore unsupported SCMI protocol %u\n" , protocol_id);
Signature · 1 line
2.17.1
PATCH 3/4 clk: add clock driver for SCMI agents
Hi Etienne,
Quoted 11 lines · Etienne Carriere
This change introduces a clock driver for SCMI agent devices. When SCMI agent and SCMI clock drivers are enabled, SCMI agent binds a clock device for each SCMI clock protocol devices enabled in the FDT.
SCMI clock driver is embedded upon
CONFIG_CLK_SCMI=y. If enabled,CONFIG_SCMI_AGENTis also enabled.SCMI Clock protocol is defined in the SCMI specification [1].
Links: [1] https://developer.arm.com/architectures/system-architectures/software-standards/scmi
That doesn't seem to work for me (404 error)
Quoted 15 lines
Signed-off-by Etienne Carriere <[email protected]>---
drivers/clk/Kconfig | 8 +++ drivers/clk/Makefile | 1 + drivers/clk/clk_scmi.c | 152 ++++++++++++++++++++++++++++++++++++++++ drivers/firmware/scmi.c | 3 + 4 files changed, 164 insertions(+) create mode 100644 drivers/clk/clk_scmi.cdrivers/clk/Kconfig +0
-0
drivers/clk/Kconfig config CLK_CDCE9XX · line 157
Quoted 6 lines
drivers/clk/Kconfig +3
-0@@ -152,6 +152,14 @@ config CLK_CDCE9XX Enable the clock synthesizer driver for CDCE913/925/937/949 series of chips. +config CLK_SCMI + bool "Enable SCMI clock driver" + select SCMI_FIRMWARE
perhaps 'depends on' would be better?
Quoted 63 lines
drivers/clk/Kconfig +5
-0+ help + Enable this option if you want to support clock devices exposed + by a SCMI agent based on SCMI clock protocol communication + with a SCMI server. + source "drivers/clk/analogbits/Kconfig" source "drivers/clk/at91/Kconfig" source "drivers/clk/exynos/Kconfig"drivers/clk/Makefile +1
-0@@ -31,6 +31,7 @@ obj-$(CONFIG_CLK_K210) += kendryte/ obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o obj-$(CONFIG_CLK_OWL) += owl/ obj-$(CONFIG_CLK_RENESAS) += renesas/ +obj-$(CONFIG_CLK_SCMI) += clk_scmi.o obj-$(CONFIG_CLK_SIFIVE) += sifive/ obj-$(CONFIG_ARCH_SUNXI) += sunxi/ obj-$(CONFIG_CLK_STM32F) += clk_stm32f.odrivers/clk/clk_scmi.c new file +37
-0@@ -0,0 +1,152 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2019-2020 Linaro Limited +*/ +#include <common.h> +#include <clk-uclass.h> +#include <dm.h> +#include <scmi.h> +#include <asm/types.h> + +enum scmi_clock_message_id { +SCMI_CLOCK_RATE_SET =0x5 , +SCMI_CLOCK_RATE_GET =0x6 , +SCMI_CLOCK_CONFIG_SET =0x7 , +}; + +#define SCMI_CLK_RATE_ASYNC_NOTIFY BIT(0) +#define SCMI_CLK_RATE_ASYNC_NORESP (BIT(0) | BIT(1)) +#define SCMI_CLK_RATE_ROUND_DOWN 0 +#define SCMI_CLK_RATE_ROUND_UP BIT(2) +#define SCMI_CLK_RATE_ROUND_CLOSEST BIT(3) + +struct scmi_clk_state_in { +u32 clock_id; +u32 attributes; +}; + +struct scmi_clk_state_out { +s32 status; +}; + +static int scmi_clk_gate (struct clk *clk,int enable) +{ +struct scmi_clk_state_in in = { + .clock_id = clk->id, + .attributes = enable, + };
drivers/clk/clk_scmi.c line 47
Quoted 10 lines
drivers/clk/clk_scmi.c new file +10
-0+struct scmi_clk_state_out out; +struct scmi_msg scmi_msg = { + .protocol_id =SCMI_PROTOCOL_ID_CLOCK , + .message_id =SCMI_CLOCK_CONFIG_SET , + .in_msg = (u8 *)&in, + .in_msg_sz =sizeof (in), + .out_msg = (u8 *)&out, + .out_msg_sz =sizeof (out), + }; +int rc;
Again please use 'ret'.
Quoted 37 lines
drivers/clk/clk_scmi.c new file +37
-0+ + rc =scmi_send_and_process_msg (clk->dev->parent, &scmi_msg); +if (rc) +return rc; + +return scmi_to_linux_errno (out.status); +} + +static int scmi_clk_enable (struct clk *clk) +{ +return scmi_clk_gate (clk,1 ); +} + +static int scmi_clk_disable (struct clk *clk) +{ +return scmi_clk_gate (clk,0 ); +} + +struct scmi_clk_rate_get_in { +u32 clock_id; +}; + +struct scmi_clk_rate_get_out { +s32 status; +u32 rate_lsb; +u32 rate_msb; +}; + +static ulong scmi_clk_get_rate (struct clk *clk) +{ +struct scmi_clk_rate_get_in in = { + .clock_id = clk->id, + }; +struct scmi_clk_rate_get_out out; +struct scmi_msg scmi_msg = { + .protocol_id =SCMI_PROTOCOL_ID_CLOCK , + .message_id =SCMI_CLOCK_RATE_GET ,
drivers/clk/clk_scmi.c line 94
Quoted 10 lines
drivers/clk/clk_scmi.c new file +10
-0+ .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; +int rc; + + rc =scmi_send_and_process_msg (clk->dev->parent, &scmi_msg); +if (rc) +return 0 ;
Why not rc?
drivers/clk/clk_scmi.c line 100
Quoted 6 lines
drivers/clk/clk_scmi.c new file +6
-0+ + rc =scmi_to_linux_errno (out.status); +if (rc) +return 0 ; + +return (ulong)(((u64 )out.rate_msb <<32 ) | out.rate_lsb);
This is odd. Can you use ulong instead of u64 to avoid two casts?
drivers/clk/clk_scmi.c line 103
Quoted 3 lines
drivers/clk/clk_scmi.c new file +3
-0+} + +struct scmi_clk_rate_set_in {
struct comment. I think these need to go in some sort of protocol header.
Quoted 64 lines
drivers/clk/clk_scmi.c new file +49
-0+u32 clock_id; +u32 flags; +u32 rate_lsb; +u32 rate_msb; +}; + +struct scmi_clk_rate_set_out { +s32 status; +}; + +static ulong scmi_clk_set_rate (struct clk *clk,ulong rate) +{ +struct scmi_clk_rate_set_in in = { + .clock_id = clk->id, + .flags =SCMI_CLK_RATE_ASYNC_NORESP | +SCMI_CLK_RATE_ROUND_CLOSEST , + .rate_lsb = (u32 )rate, + .rate_msb = (u32)((u64 )rate >>32 ), + }; +struct scmi_clk_rate_set_out out; +struct scmi_msg scmi_msg = { + .protocol_id =SCMI_PROTOCOL_ID_CLOCK , + .message_id =SCMI_CLOCK_RATE_SET , + .in_msg = (u8 *)&in, + .in_msg_sz =sizeof (in), + .out_msg = (u8 *)&out, + .out_msg_sz =sizeof (out), + }; +int rc; + + rc =scmi_send_and_process_msg (clk->dev->parent, &scmi_msg); +if (rc) +return 0 ; + +return scmi_to_linux_errno (out.status); +} + +static const struct clk_ops scmi_clk_ops = { + .enable = scmi_clk_enable, + .disable = scmi_clk_disable, + .get_rate = scmi_clk_get_rate, + .set_rate = scmi_clk_set_rate, +}; + +U_BOOT_DRIVER (scmi_clock) = { + .name ="scmi_clk" , + .id =UCLASS_CLK , + .ops = &scmi_clk_ops, +};drivers/firmware/scmi.c +3
-1@@ -399,6 +399,9 @@ static int scmi_bind(struct udevice *dev)continue ;switch (protocol_id) { +case SCMI_PROTOCOL_ID_CLOCK : + drv =DM_GET_DRIVER (scmi_clock); +break ;default :dev_info (dev,"Ignore unsupported SCMI protocol %u\n" , protocol_id); --
Quoted 2 lines
2.17.1
Can you add a sandbox test for this?
Regards,
Simon
PATCH 3/4 clk: add clock driver for SCMI agents
Hello Simon and all,
Quoted 10 lines · Simon Glass
Hi Etienne,
Quoted 5 lines · Etienne Carriere
This change introduces a clock driver for SCMI agent devices. When SCMI agent and SCMI clock drivers are enabled, SCMI agent binds a clock device for each SCMI clock protocol devices enabled in the FDT.
Quoted 8 lines
Quoted 6 lines
SCMI clock driver is embedded upon
CONFIG_CLK_SCMI=y. If enabled,CONFIG_SCMI_AGENTis also enabled.SCMI Clock protocol is defined in the SCMI specification [1].
Links: [1] https://developer.arm.com/architectures/system-architectures/software-standards/scmi
That doesn't seem to work for me (404 error)
I think that Arm site was broken when you tried. Works fine and this seems to be the official Arm URL for the SCMI specification.
Quoted 19 lines
Quoted 19 lines
Signed-off-by Etienne Carriere <[email protected]>---
drivers/clk/Kconfig | 8 +++ drivers/clk/Makefile | 1 + drivers/clk/clk_scmi.c | 152 ++++++++++++++++++++++++++++++++++++++++ drivers/firmware/scmi.c | 3 + 4 files changed, 164 insertions(+) create mode 100644 drivers/clk/clk_scmi.cdrivers/clk/Kconfig +0
-0@@ -152,6 +152,14 @@ config CLK_CDCE9XX Enable the clock synthesizer driver for CDCE913/925/937/949 series of chips.
Quoted 5 lines
drivers/clk/Kconfig config CLK_CDCE9XX · line 157
Quoted 3 lines
drivers/clk/Kconfig +3
-0+config CLK_SCMI + bool "Enable SCMI clock driver" + select SCMI_FIRMWAREperhaps 'depends on' would be better?
Ok
Quoted 68 lines
Quoted 68 lines
drivers/clk/Kconfig +5
-0+ help + Enable this option if you want to support clock devices exposed + by a SCMI agent based on SCMI clock protocol communication + with a SCMI server. + source "drivers/clk/analogbits/Kconfig" source "drivers/clk/at91/Kconfig" source "drivers/clk/exynos/Kconfig"drivers/clk/Makefile +1
-0@@ -31,6 +31,7 @@ obj-$(CONFIG_CLK_K210) += kendryte/ obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o obj-$(CONFIG_CLK_OWL) += owl/ obj-$(CONFIG_CLK_RENESAS) += renesas/ +obj-$(CONFIG_CLK_SCMI) += clk_scmi.o obj-$(CONFIG_CLK_SIFIVE) += sifive/ obj-$(CONFIG_ARCH_SUNXI) += sunxi/ obj-$(CONFIG_CLK_STM32F) += clk_stm32f.odrivers/clk/clk_scmi.c new file +41
-0@@ -0,0 +1,152 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2019-2020 Linaro Limited +*/ +#include <common.h> +#include <clk-uclass.h> +#include <dm.h> +#include <scmi.h> +#include <asm/types.h> + +enum scmi_clock_message_id { +SCMI_CLOCK_RATE_SET =0x5 , +SCMI_CLOCK_RATE_GET =0x6 , +SCMI_CLOCK_CONFIG_SET =0x7 , +}; + +#define SCMI_CLK_RATE_ASYNC_NOTIFY BIT(0) +#define SCMI_CLK_RATE_ASYNC_NORESP (BIT(0) | BIT(1)) +#define SCMI_CLK_RATE_ROUND_DOWN 0 +#define SCMI_CLK_RATE_ROUND_UP BIT(2) +#define SCMI_CLK_RATE_ROUND_CLOSEST BIT(3) + +struct scmi_clk_state_in { +u32 clock_id; +u32 attributes; +}; + +struct scmi_clk_state_out { +s32 status; +}; + +static int scmi_clk_gate (struct clk *clk,int enable) +{ +struct scmi_clk_state_in in = { + .clock_id = clk->id, + .attributes = enable, + }; +struct scmi_clk_state_out out; +struct scmi_msg scmi_msg = { + .protocol_id =SCMI_PROTOCOL_ID_CLOCK , + .message_id =SCMI_CLOCK_CONFIG_SET ,
Quoted 8 lines
drivers/clk/clk_scmi.c line 47
Quoted 6 lines
drivers/clk/clk_scmi.c new file +6
-0+ .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; +int rc;Again please use 'ret'.
Sure, will do.
Quoted 42 lines
Quoted 42 lines
drivers/clk/clk_scmi.c new file +41
-0+ + rc =scmi_send_and_process_msg (clk->dev->parent, &scmi_msg); +if (rc) +return rc; + +return scmi_to_linux_errno (out.status); +} + +static int scmi_clk_enable (struct clk *clk) +{ +return scmi_clk_gate (clk,1 ); +} + +static int scmi_clk_disable (struct clk *clk) +{ +return scmi_clk_gate (clk,0 ); +} + +struct scmi_clk_rate_get_in { +u32 clock_id; +}; + +struct scmi_clk_rate_get_out { +s32 status; +u32 rate_lsb; +u32 rate_msb; +}; + +static ulong scmi_clk_get_rate (struct clk *clk) +{ +struct scmi_clk_rate_get_in in = { + .clock_id = clk->id, + }; +struct scmi_clk_rate_get_out out; +struct scmi_msg scmi_msg = { + .protocol_id =SCMI_PROTOCOL_ID_CLOCK , + .message_id =SCMI_CLOCK_RATE_GET , + .in_msg = (u8 *)&in, + .in_msg_sz =sizeof (in), + .out_msg = (u8 *)&out, + .out_msg_sz =sizeof (out),
Quoted 8 lines
drivers/clk/clk_scmi.c line 94
Quoted 6 lines
drivers/clk/clk_scmi.c new file +6
-0+ }; +int rc; + + rc =scmi_send_and_process_msg (clk->dev->parent, &scmi_msg); +if (rc) +return 0 ;Why not rc?
True, thanks.
Quoted 9 lines
drivers/clk/clk_scmi.c line 100
Quoted 7 lines
drivers/clk/clk_scmi.c new file +6
-0+ + rc =scmi_to_linux_errno (out.status); +if (rc) +return 0 ; + +return (ulong)(((u64 )out.rate_msb <<32 ) | out.rate_lsb);This is odd. Can you use ulong instead of u64 to avoid two casts?
A ulong would fit on a 64bit machine but not on a 32bit as compiler will likely complain that the '<< 32' operation is meaningless.
Quoted 6 lines
drivers/clk/clk_scmi.c line 103
Quoted 4 lines
drivers/clk/clk_scmi.c new file +3
-0+} + +struct scmi_clk_rate_set_in {struct comment. I think these need to go in some sort of protocol header.
These structures are used only by this very SCMI clock driver hence I don't think it deserves exposure in a shared header file.
Quoted 57 lines
Quoted 57 lines
drivers/clk/clk_scmi.c new file +49
-0+u32 clock_id; +u32 flags; +u32 rate_lsb; +u32 rate_msb; +}; + +struct scmi_clk_rate_set_out { +s32 status; +}; + +static ulong scmi_clk_set_rate (struct clk *clk,ulong rate) +{ +struct scmi_clk_rate_set_in in = { + .clock_id = clk->id, + .flags =SCMI_CLK_RATE_ASYNC_NORESP | +SCMI_CLK_RATE_ROUND_CLOSEST , + .rate_lsb = (u32 )rate, + .rate_msb = (u32)((u64 )rate >>32 ), + }; +struct scmi_clk_rate_set_out out; +struct scmi_msg scmi_msg = { + .protocol_id =SCMI_PROTOCOL_ID_CLOCK , + .message_id =SCMI_CLOCK_RATE_SET , + .in_msg = (u8 *)&in, + .in_msg_sz =sizeof (in), + .out_msg = (u8 *)&out, + .out_msg_sz =sizeof (out), + }; +int rc; + + rc =scmi_send_and_process_msg (clk->dev->parent, &scmi_msg); +if (rc) +return 0 ; + +return scmi_to_linux_errno (out.status); +} + +static const struct clk_ops scmi_clk_ops = { + .enable = scmi_clk_enable, + .disable = scmi_clk_disable, + .get_rate = scmi_clk_get_rate, + .set_rate = scmi_clk_set_rate, +}; + +U_BOOT_DRIVER (scmi_clock) = { + .name ="scmi_clk" , + .id =UCLASS_CLK , + .ops = &scmi_clk_ops, +};drivers/firmware/scmi.c +0
-0@@ -399,6 +399,9 @@ static int scmi_bind(struct udevice *dev)continue ;
Quoted 12 lines
Quoted 10 lines
drivers/firmware/scmi.c +3
-1switch (protocol_id) { +case SCMI_PROTOCOL_ID_CLOCK : + drv =DM_GET_DRIVER (scmi_clock); +break ;default :dev_info (dev,"Ignore unsupported SCMI protocol %u\n" , protocol_id); --2.17.1
Can you add a sandbox test for this?
Ok I'm looking at that.
Quoted 3 lines
Regards,
Simon
PATCH 3/4 clk: add clock driver for SCMI agents
Quoted 16 lines · Etienne Carriere
Hello Simon and all,
Quoted 13 lines · Simon Glass
Hi Etienne,
Quoted 8 lines · Etienne Carriere
This change introduces a clock driver for SCMI agent devices. When SCMI agent and SCMI clock drivers are enabled, SCMI agent binds a clock device for each SCMI clock protocol devices enabled in the FDT.
SCMI clock driver is embedded upon
CONFIG_CLK_SCMI=y. If enabled,CONFIG_SCMI_AGENTis also enabled.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
SCMI Clock protocol is defined in the SCMI specification [1].
Links: [1] https://developer.arm.com/architectures/system-architectures/software-standards/scmi
That doesn't seem to work for me (404 error)
I think that Arm site was broken when you tried. Works fine and this seems to be the official Arm URL for the SCMI specification.
Hopefully this works, I have this in one of the kernel doc.
https://developer.arm.com/documentation/den0056/latest
Signature · 2 lines
Regards, Sudeep
PATCH 4/4 reset: add reset controller driver for SCMI agents
In reply to Etienne CarriereThis change introduces a reset controller driver for SCMI agent devices. When SCMI agent and SCMI reset domain drivers are enabled, SCMI agent binds a reset controller device for each SCMI reset domain protocol devices enabled in the FDT.
SCMI reset driver is embedded upon CONFIG_RESET_SCMI=y. If enabled, CONFIG_SCMI_AGENT is also enabled.
SCMI Reset Domain protocol is defined in the SCMI specification [1].
Links: [1] https://developer.arm.com/architectures/system-architectures/software-standards/scmi
---
drivers/firmware/scmi.c | 3 ++ drivers/reset/Kconfig | 8 ++++ drivers/reset/Makefile | 1 + drivers/reset/reset-scmi.c | 86 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 drivers/reset/reset-scmi.c
drivers/firmware/scmi.c +3 -0
@@ -402,6 +402,9 @@ static int scmi_bind(struct udevice *dev)case SCMI_PROTOCOL_ID_CLOCK : drv =DM_GET_DRIVER (scmi_clock);break ; +case SCMI_PROTOCOL_ID_RESET_DOMAIN : + drv =DM_GET_DRIVER (scmi_reset_domain); +break ;default :dev_info (dev,"Ignore unsupported SCMI protocol %u\n" , protocol_id);
drivers/reset/Kconfig +8 -0
@@ -164,4 +164,12 @@ config RESET_RASPBERRYPI relevant. This driver provides a reset controller capable of interfacing with RPi4's co-processor and model these firmware initialization routines as reset lines. + +config RESET_SCMI + bool "Enable SCMI reset domain driver" + select SCMI_FIRMWARE + help + Enable this option if you want to support reset controller + devices exposed by a SCMI agent based on SCMI reset domain + protocol communication with a SCMI server. endmenu
drivers/reset/Makefile +1 -0
@@ -25,3 +25,4 @@ obj-$(CONFIG_RESET_HISILICON) += reset-hisilicon.o obj-$(CONFIG_RESET_IMX7) += reset-imx7.o obj-$(CONFIG_RESET_SYSCON) += reset-syscon.o obj-$(CONFIG_RESET_RASPBERRYPI) += reset-raspberrypi.o +obj-$(CONFIG_RESET_SCMI) += reset-scmi.o
drivers/reset/reset-scmi.c new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 4/4 reset: add reset controller driver for SCMI agents
Hi Etienne,
Quoted 13 lines · Etienne Carriere
This change introduces a reset controller driver for SCMI agent devices. When SCMI agent and SCMI reset domain drivers are enabled, SCMI agent binds a reset controller device for each SCMI reset domain protocol devices enabled in the FDT.
SCMI reset driver is embedded upon
CONFIG_RESET_SCMI=y. If enabled,CONFIG_SCMI_AGENTis also enabled.SCMI Reset Domain protocol is defined in the SCMI specification [1].
Links: [1] https://developer.arm.com/architectures/system-architectures/software-standards/scmi
Signed-off-by Etienne Carriere <[email protected]>
Quoted 8 lines
---
drivers/firmware/scmi.c | 3 ++ drivers/reset/Kconfig | 8 ++++ drivers/reset/Makefile | 1 + drivers/reset/reset-scmi.c | 86 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 drivers/reset/reset-scmi.c
Quoted 103 lines
drivers/firmware/scmi.c +3
-0@@ -402,6 +402,9 @@ static int scmi_bind(struct udevice *dev)case SCMI_PROTOCOL_ID_CLOCK : drv =DM_GET_DRIVER (scmi_clock);break ; +case SCMI_PROTOCOL_ID_RESET_DOMAIN : + drv =DM_GET_DRIVER (scmi_reset_domain); +break ;default :dev_info (dev,"Ignore unsupported SCMI protocol %u\n" , protocol_id);drivers/reset/Kconfig +8
-0@@ -164,4 +164,12 @@ config RESET_RASPBERRYPI relevant. This driver provides a reset controller capable of interfacing with RPi4's co-processor and model these firmware initialization routines as reset lines. + +config RESET_SCMI + bool "Enable SCMI reset domain driver" + select SCMI_FIRMWARE + help + Enable this option if you want to support reset controller + devices exposed by a SCMI agent based on SCMI reset domain + protocol communication with a SCMI server. endmenudrivers/reset/Makefile +1
-0@@ -25,3 +25,4 @@ obj-$(CONFIG_RESET_HISILICON) += reset-hisilicon.o obj-$(CONFIG_RESET_IMX7) += reset-imx7.o obj-$(CONFIG_RESET_SYSCON) += reset-syscon.o obj-$(CONFIG_RESET_RASPBERRYPI) += reset-raspberrypi.o +obj-$(CONFIG_RESET_SCMI) += reset-scmi.odrivers/reset/reset-scmi.c new file +56
-0@@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2019-2020 Linaro Limited +*/ +#include <common.h> +#include <dm.h> +#include <errno.h> +#include <reset-uclass.h> +#include <scmi.h> +#include <asm/types.h> + +enum scmi_reset_domain_message_id { +SCMI_RESET_DOMAIN_RESET =0x4 , +}; + +#define SCMI_RD_RESET_FLAG_ASSERT BIT(1) +#define SCMI_RD_RESET_FLAG_DEASSERT 0 + +struct scmi_rd_reset_in { +u32 domain_id; +u32 flags; +u32 reset_state; +}; + +struct scmi_rd_reset_out { +s32 status; +}; + +static int scmi_reset_set_state (struct reset_ctl *rst,int assert_not_deassert) +{ +struct scmi_rd_reset_in in = { + .domain_id = rst->id, + .flags = assert_not_deassert ?SCMI_RD_RESET_FLAG_ASSERT : +SCMI_RD_RESET_FLAG_DEASSERT , + .reset_state =0 , + }; +struct scmi_rd_reset_out out; +struct scmi_msg scmi_msg = { + .protocol_id =SCMI_PROTOCOL_ID_RESET_DOMAIN , + .message_id =SCMI_RESET_DOMAIN_RESET , + .in_msg = (u8 *)&in, + .in_msg_sz =sizeof (in), + .out_msg = (u8 *)&out, + .out_msg_sz =sizeof (out), + }; +int rc; + + rc =scmi_send_and_process_msg (rst->dev->parent, &scmi_msg); +if (rc) +return rc; + +return scmi_to_linux_errno (out.status); +} + +static int scmi_reset_assert (struct reset_ctl *rst) +{
drivers/reset/reset-scmi.c line 66
Quoted 10 lines
drivers/reset/reset-scmi.c new file +10
-0+return scmi_reset_set_state (rst,SCMI_RD_RESET_FLAG_ASSERT ); +} + +static int scmi_reset_deassert (struct reset_ctl *rst) +{ +return scmi_reset_set_state (rst,SCMI_RD_RESET_FLAG_DEASSERT ); +} + +static int scmi_reset_request (struct reset_ctl *reset_ctl) +{
Do you actually need these two functions if they do nothing?
Quoted 21 lines
drivers/reset/reset-scmi.c new file +20
-1+return 0 ; +} + +static int scmi_reset_rfree (struct reset_ctl *reset_ctl) +{ +return 0 ; +} + +static const struct reset_ops scmi_reset_domain_ops = { + .request = scmi_reset_request, + .rfree = scmi_reset_rfree, + .rst_assert = scmi_reset_assert, + .rst_deassert = scmi_reset_deassert, +}; + +U_BOOT_DRIVER (scmi_reset_domain) = { + .name ="scmi_reset_domain" , + .id =UCLASS_RESET , + .ops = &scmi_reset_domain_ops, +}; --
Quoted 2 lines
2.17.1
Regards,
Simon