1.. _arm_scmi:
2
3ARM System Control and Management Interface
4###########################################
5
6Overview
7********
8
9What is SCMI?
10*************
11
12System Control and Management Interface (SCMI) is a specification developed by
13ARM, which describes a set of OS-agnostic software interfaces used to perform
14system management (e.g: clock control, pinctrl, etc...).
15
16
17Agent, platform, protocol and transport
18***************************************
19
20The SCMI specification defines **four** key terms, which will also be used throughout
21this documentation:
22
23	#. Agent
24		Entity that performs SCMI requests (e.g: gating a clock or configuring
25		a pin). In this context, Zephyr itself is an agent.
26	#. Platform
27		This refers to a set of hardware components that handle the requests from
28		agents and provide the necessary functionality. In some cases, the requests
29		are handled by a firmware, running on a core dedicated to performing system
30		management tasks.
31	#. Protocol
32		A protocol is a set of messages grouped by functionality. Intuitively, a message
33		can be thought of as a remote procedure call.
34
35		The SCMI specification defines ten standard protocols:
36
37		#. **Base** (0x10)
38		#. **Power domain management** (0x11)
39		#. **System power management** (0x12)
40		#. **Performance domain management** (0x13)
41		#. **Clock management** (0x14)
42		#. **Sensor management** (0x15)
43		#. **Reset domain management** (0x16)
44		#. **Voltage domain management** (0x17)
45		#. **Power capping and monitoring** (0x18)
46		#. **Pin Control** (0x19)
47
48		where each of these protocols is identified by an unique protocol ID
49		(listed between brackets).
50
51		Apart from the standard protocols, the SCMI specification reserves the
52		**0x80-0xFF** protocol ID range for vendor-specific protocols.
53
54
55	#. Transport
56		This describes how messages are exchanged between agents and the platform.
57		The communication itself happens through channels.
58
59.. note::
60	A system may have more than one agent.
61
62Channels
63********
64
65A **channel** is the medium through which agents and the platform exchange messages.
66The structure of a channel and the way it works is solely dependent on the transport.
67
68Each agent has its own distinct set of channels, meaning some channel A cannot be used
69by two different agents for example.
70
71Channels are **bidirectional** (exception: FastChannels), and, depending on which entity
72initiates the communication, can be one of **two** types:
73
74	#. A2P (agent to platform)
75		The agent is the initiator/requester. The messages passed through these
76		channels are known as **commands**.
77	#. P2A (platform to agent)
78		The platform is the initiator/requester.
79
80Messages
81********
82
83The SCMI specification defines **four** types of messages:
84
85	#. Synchronous
86		These are commands that block until the platform has completed the
87		requested work and are sent over A2P channels.
88	#. Asynchronous
89		For these commands, the platform schedules the requested work to
90		be performed at a later time. As such, they return almost immediately.
91		These commands are sent over A2P channels.
92	#. Delayed response
93		These messages indicate the completion of the work associated
94		with an asynchronous command. These are sent over P2A channels.
95
96	#. Notification
97		These messages are used to notify agents of events that take place on
98		the platform. These are sent over P2A channels.
99
100The Zephyr support for SCMI is based on the documentation provided by ARM:
101`DEN0056E <https://developer.arm.com/documentation/den0056/latest/>`_. For more details
102on the specification, the readers are encouraged to have a look at it.
103
104SCMI support in Zephyr
105**********************
106
107Shared memory and doorbell-based transport
108******************************************
109
110This form of transport uses shared memory for reading/writing messages
111and doorbells for signaling. The interaction with the shared
112memory area is performed using a driver (:file:`drivers/firmware/scmi/shmem.c`),
113which offers a set of functions for this exact purpose. Furthermore,
114signaling is performed using the Zephyr MBOX API (signaling mode only, no message passing).
115
116Interacting with the shared memory area and signaling are abstracted by the
117transport API, which is implemented by the shared memory and doorbell-based
118transport driver (:file:`drivers/firmware/scmi/mailbox.c`).
119
120The steps below exemplify how the communication between the Zephyr agent
121and the platform may happen using this transport:
122
123	#. Write message to the shared memory area.
124	#. Zephyr rings request doorbell. If in ``PRE_KERNEL_1`` or ``PRE_KERNEL_2`` phase start polling for reply, otherwise wait for reply doorbell ring.
125	#. Platform reads message from shared memory area, processes it, writes the reply back to the same area and rings the reply doorbell.
126	#. Zephyr reads reply from the shared memory area.
127
128In the context of this transport, a channel is comprised of a **single** shared
129memory area and one or more mailbox channels. This is because users may need/want
130to use different mailbox channels for the request/reply doorbells.
131
132
133Protocols
134*********
135
136Currently, Zephyr has support for the following standard protocols:
137
138	#. **Clock management**
139	#. **Pin Control**
140
141
142Clock management protocol
143*************************
144
145This protocol is used to perform clock management operations. This is done
146via a driver (:file:`drivers/clock_control/clock_control_arm_scmi.c`), which
147implements the Zephyr clock control subsystem API. As such, from the user's
148perspective, using this driver is no different than using any other clock
149management driver.
150
151.. note::
152	This driver is vendor-agnostic. As such, it may be used on any
153	system that uses SCMI for clock management operations.
154
155Pin Control protocol
156********************
157
158This protocol is used to perform pin configuration operations. This is done
159via a set of functions implementing various commands. Currently, the only
160supported command is ``PINCTRL_SETTINGS_CONFIGURE``.
161
162.. note::
163	The support for this protocol **does not** include a definition for
164	the :code:`pinctrl_configure_pins` function. Each vendor should use
165	their own definition of :code:`pinctrl_configure_pins`, which should
166	call into the SCMI pin control protocol function implementing the
167	``PINCTRL_SETTINGS_CONFIGURE`` command.
168
169
170Enabling the SCMI support
171*************************
172
173To use the SCMI support, each vendor is required to add an ``scmi`` DT
174node (used for transport driver binding) and a ``protocol`` node under the ``scmi``
175node for each supported protocol.
176
177.. note::
178	Zephyr has no support for protocol discovery. As such, if users
179	add a DT node for a certain protocol it's assumed the platform
180	supports said protocol.
181
182The example below shows how a DT may be configured in order to use the
183SCMI support. It's assumed that the only protocol required is the clock
184management protocol.
185
186.. code-block:: devicetree
187
188	#include <mem.h>
189
190	#define MY_CLOCK_CONSUMER_CLK_ID 123
191
192	scmi_res0: memory@cafebabe {
193		/* mandatory to use shared memory driver */
194		compatible = "arm,scmi-shmem";
195		reg = <0xcafebabe DT_SIZE_K(1)>;
196	};
197
198	scmi {
199		/* compatible for shared memory and doorbell-based transport */
200		compatible = "arm,scmi";
201
202		/* one SCMI channel => A2P/transmit channel */
203		shmem = <&scmi_res0>;
204
205		/* two mailbox channels */
206		mboxes = <&my_mbox_ip 0>, <&my_mbox_ip 1>;
207		mbox-names = "tx", "tx_reply";
208
209		scmi_clk: protocol@14 {
210			compatible = "arm,scmi-clock";
211
212			/* matches the clock management protocol ID */
213			reg = <0x14>;
214
215			/* vendor-agnostic - always 1 */
216			#clock-cells = <1>;
217		};
218	};
219
220	my_mbox_ip: mailbox@deadbeef {
221		compatible = "vnd,mbox-ip";
222		reg = <0xdeadbeef DT_SIZE_K(1)>;
223		#mbox-cells = <1>;
224	};
225
226	my_clock_consumer_ip: serial@12345678 {
227		compatible = "vnd,consumer-ip";
228		reg = <0x12345678 DT_SIZE_K(1)>;
229		/* clock ID is vendor specific */
230		clocks = <&scmi_clk MY_CLOCK_CONSUMER_CLK_ID>;
231	};
232
233
234Finally, all that's left to do is enable :kconfig:option:`CONFIG_ARM_SCMI`.
235