Skip to content

Commit 95a15d8

Browse files
committed
firmware: arm_scmi: Add RESET protocol in SCMI v2.0
SCMIv2.0 adds a new Reset Management Protocol to manage various reset states a given device or domain can enter. Device(s) that can be collectively reset through a common reset signal constitute a reset domain for the firmware. A reset domain can be reset autonomously or explicitly through assertion and de-assertion of the signal. When autonomous reset is chosen, the firmware is responsible for taking the necessary steps to reset the domain and to subsequently bring it out of reset. When explicit reset is chosen, the caller has to specifically assert and then de-assert the reset signal by issuing two separate RESET commands. Add the basic SCMI reset infrastructure that can be used by Linux reset controller driver. Reviewed-by: Peng Fan <[email protected]> Reviewed-by: Philipp Zabel <[email protected]> Signed-off-by: Sudeep Holla <[email protected]>
1 parent ae39913 commit 95a15d8

File tree

3 files changed

+258
-1
lines changed

3 files changed

+258
-1
lines changed

drivers/firmware/arm_scmi/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
obj-y = scmi-bus.o scmi-driver.o scmi-protocols.o
33
scmi-bus-y = bus.o
44
scmi-driver-y = driver.o
5-
scmi-protocols-y = base.o clock.o perf.o power.o sensors.o
5+
scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o
66
obj-$(CONFIG_ARM_SCMI_POWER_DOMAIN) += scmi_pm_domain.o

drivers/firmware/arm_scmi/reset.c

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* System Control and Management Interface (SCMI) Reset Protocol
4+
*
5+
* Copyright (C) 2019 ARM Ltd.
6+
*/
7+
8+
#include "common.h"
9+
10+
enum scmi_reset_protocol_cmd {
11+
RESET_DOMAIN_ATTRIBUTES = 0x3,
12+
RESET = 0x4,
13+
RESET_NOTIFY = 0x5,
14+
};
15+
16+
enum scmi_reset_protocol_notify {
17+
RESET_ISSUED = 0x0,
18+
};
19+
20+
#define NUM_RESET_DOMAIN_MASK 0xffff
21+
#define RESET_NOTIFY_ENABLE BIT(0)
22+
23+
struct scmi_msg_resp_reset_domain_attributes {
24+
__le32 attributes;
25+
#define SUPPORTS_ASYNC_RESET(x) ((x) & BIT(31))
26+
#define SUPPORTS_NOTIFY_RESET(x) ((x) & BIT(30))
27+
__le32 latency;
28+
u8 name[SCMI_MAX_STR_SIZE];
29+
};
30+
31+
struct scmi_msg_reset_domain_reset {
32+
__le32 domain_id;
33+
__le32 flags;
34+
#define AUTONOMOUS_RESET BIT(0)
35+
#define EXPLICIT_RESET_ASSERT BIT(1)
36+
#define ASYNCHRONOUS_RESET BIT(2)
37+
__le32 reset_state;
38+
#define ARCH_RESET_TYPE BIT(31)
39+
#define COLD_RESET_STATE BIT(0)
40+
#define ARCH_COLD_RESET (ARCH_RESET_TYPE | COLD_RESET_STATE)
41+
};
42+
43+
struct reset_dom_info {
44+
bool async_reset;
45+
bool reset_notify;
46+
u32 latency_us;
47+
char name[SCMI_MAX_STR_SIZE];
48+
};
49+
50+
struct scmi_reset_info {
51+
int num_domains;
52+
struct reset_dom_info *dom_info;
53+
};
54+
55+
static int scmi_reset_attributes_get(const struct scmi_handle *handle,
56+
struct scmi_reset_info *pi)
57+
{
58+
int ret;
59+
struct scmi_xfer *t;
60+
u32 attr;
61+
62+
ret = scmi_xfer_get_init(handle, PROTOCOL_ATTRIBUTES,
63+
SCMI_PROTOCOL_RESET, 0, sizeof(attr), &t);
64+
if (ret)
65+
return ret;
66+
67+
ret = scmi_do_xfer(handle, t);
68+
if (!ret) {
69+
attr = get_unaligned_le32(t->rx.buf);
70+
pi->num_domains = attr & NUM_RESET_DOMAIN_MASK;
71+
}
72+
73+
scmi_xfer_put(handle, t);
74+
return ret;
75+
}
76+
77+
static int
78+
scmi_reset_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
79+
struct reset_dom_info *dom_info)
80+
{
81+
int ret;
82+
struct scmi_xfer *t;
83+
struct scmi_msg_resp_reset_domain_attributes *attr;
84+
85+
ret = scmi_xfer_get_init(handle, RESET_DOMAIN_ATTRIBUTES,
86+
SCMI_PROTOCOL_RESET, sizeof(domain),
87+
sizeof(*attr), &t);
88+
if (ret)
89+
return ret;
90+
91+
put_unaligned_le32(domain, t->tx.buf);
92+
attr = t->rx.buf;
93+
94+
ret = scmi_do_xfer(handle, t);
95+
if (!ret) {
96+
u32 attributes = le32_to_cpu(attr->attributes);
97+
98+
dom_info->async_reset = SUPPORTS_ASYNC_RESET(attributes);
99+
dom_info->reset_notify = SUPPORTS_NOTIFY_RESET(attributes);
100+
dom_info->latency_us = le32_to_cpu(attr->latency);
101+
if (dom_info->latency_us == U32_MAX)
102+
dom_info->latency_us = 0;
103+
strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
104+
}
105+
106+
scmi_xfer_put(handle, t);
107+
return ret;
108+
}
109+
110+
static int scmi_reset_num_domains_get(const struct scmi_handle *handle)
111+
{
112+
struct scmi_reset_info *pi = handle->reset_priv;
113+
114+
return pi->num_domains;
115+
}
116+
117+
static char *scmi_reset_name_get(const struct scmi_handle *handle, u32 domain)
118+
{
119+
struct scmi_reset_info *pi = handle->reset_priv;
120+
struct reset_dom_info *dom = pi->dom_info + domain;
121+
122+
return dom->name;
123+
}
124+
125+
static int scmi_reset_latency_get(const struct scmi_handle *handle, u32 domain)
126+
{
127+
struct scmi_reset_info *pi = handle->reset_priv;
128+
struct reset_dom_info *dom = pi->dom_info + domain;
129+
130+
return dom->latency_us;
131+
}
132+
133+
static int scmi_domain_reset(const struct scmi_handle *handle, u32 domain,
134+
u32 flags, u32 state)
135+
{
136+
int ret;
137+
struct scmi_xfer *t;
138+
struct scmi_msg_reset_domain_reset *dom;
139+
struct scmi_reset_info *pi = handle->reset_priv;
140+
struct reset_dom_info *rdom = pi->dom_info + domain;
141+
142+
if (rdom->async_reset)
143+
flags |= ASYNCHRONOUS_RESET;
144+
145+
ret = scmi_xfer_get_init(handle, RESET, SCMI_PROTOCOL_RESET,
146+
sizeof(*dom), 0, &t);
147+
if (ret)
148+
return ret;
149+
150+
dom = t->tx.buf;
151+
dom->domain_id = cpu_to_le32(domain);
152+
dom->flags = cpu_to_le32(flags);
153+
dom->domain_id = cpu_to_le32(state);
154+
155+
if (rdom->async_reset)
156+
ret = scmi_do_xfer_with_response(handle, t);
157+
else
158+
ret = scmi_do_xfer(handle, t);
159+
160+
scmi_xfer_put(handle, t);
161+
return ret;
162+
}
163+
164+
static int scmi_reset_domain_reset(const struct scmi_handle *handle, u32 domain)
165+
{
166+
return scmi_domain_reset(handle, domain, AUTONOMOUS_RESET,
167+
ARCH_COLD_RESET);
168+
}
169+
170+
static int
171+
scmi_reset_domain_assert(const struct scmi_handle *handle, u32 domain)
172+
{
173+
return scmi_domain_reset(handle, domain, EXPLICIT_RESET_ASSERT,
174+
ARCH_COLD_RESET);
175+
}
176+
177+
static int
178+
scmi_reset_domain_deassert(const struct scmi_handle *handle, u32 domain)
179+
{
180+
return scmi_domain_reset(handle, domain, 0, ARCH_COLD_RESET);
181+
}
182+
183+
static struct scmi_reset_ops reset_ops = {
184+
.num_domains_get = scmi_reset_num_domains_get,
185+
.name_get = scmi_reset_name_get,
186+
.latency_get = scmi_reset_latency_get,
187+
.reset = scmi_reset_domain_reset,
188+
.assert = scmi_reset_domain_assert,
189+
.deassert = scmi_reset_domain_deassert,
190+
};
191+
192+
static int scmi_reset_protocol_init(struct scmi_handle *handle)
193+
{
194+
int domain;
195+
u32 version;
196+
struct scmi_reset_info *pinfo;
197+
198+
scmi_version_get(handle, SCMI_PROTOCOL_RESET, &version);
199+
200+
dev_dbg(handle->dev, "Reset Version %d.%d\n",
201+
PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));
202+
203+
pinfo = devm_kzalloc(handle->dev, sizeof(*pinfo), GFP_KERNEL);
204+
if (!pinfo)
205+
return -ENOMEM;
206+
207+
scmi_reset_attributes_get(handle, pinfo);
208+
209+
pinfo->dom_info = devm_kcalloc(handle->dev, pinfo->num_domains,
210+
sizeof(*pinfo->dom_info), GFP_KERNEL);
211+
if (!pinfo->dom_info)
212+
return -ENOMEM;
213+
214+
for (domain = 0; domain < pinfo->num_domains; domain++) {
215+
struct reset_dom_info *dom = pinfo->dom_info + domain;
216+
217+
scmi_reset_domain_attributes_get(handle, domain, dom);
218+
}
219+
220+
handle->reset_ops = &reset_ops;
221+
handle->reset_priv = pinfo;
222+
223+
return 0;
224+
}
225+
226+
static int __init scmi_reset_init(void)
227+
{
228+
return scmi_protocol_register(SCMI_PROTOCOL_RESET,
229+
&scmi_reset_protocol_init);
230+
}
231+
subsys_initcall(scmi_reset_init);

include/linux/scmi_protocol.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,26 @@ struct scmi_sensor_ops {
187187
u64 *value);
188188
};
189189

190+
/**
191+
* struct scmi_reset_ops - represents the various operations provided
192+
* by SCMI Reset Protocol
193+
*
194+
* @num_domains_get: get the count of reset domains provided by SCMI
195+
* @name_get: gets the name of a reset domain
196+
* @latency_get: gets the reset latency for the specified reset domain
197+
* @reset: resets the specified reset domain
198+
* @assert: explicitly assert reset signal of the specified reset domain
199+
* @deassert: explicitly deassert reset signal of the specified reset domain
200+
*/
201+
struct scmi_reset_ops {
202+
int (*num_domains_get)(const struct scmi_handle *handle);
203+
char *(*name_get)(const struct scmi_handle *handle, u32 domain);
204+
int (*latency_get)(const struct scmi_handle *handle, u32 domain);
205+
int (*reset)(const struct scmi_handle *handle, u32 domain);
206+
int (*assert)(const struct scmi_handle *handle, u32 domain);
207+
int (*deassert)(const struct scmi_handle *handle, u32 domain);
208+
};
209+
190210
/**
191211
* struct scmi_handle - Handle returned to ARM SCMI clients for usage.
192212
*
@@ -196,6 +216,7 @@ struct scmi_sensor_ops {
196216
* @perf_ops: pointer to set of performance protocol operations
197217
* @clk_ops: pointer to set of clock protocol operations
198218
* @sensor_ops: pointer to set of sensor protocol operations
219+
* @reset_ops: pointer to set of reset protocol operations
199220
* @perf_priv: pointer to private data structure specific to performance
200221
* protocol(for internal use only)
201222
* @clk_priv: pointer to private data structure specific to clock
@@ -204,6 +225,8 @@ struct scmi_sensor_ops {
204225
* protocol(for internal use only)
205226
* @sensor_priv: pointer to private data structure specific to sensors
206227
* protocol(for internal use only)
228+
* @reset_priv: pointer to private data structure specific to reset
229+
* protocol(for internal use only)
207230
*/
208231
struct scmi_handle {
209232
struct device *dev;
@@ -212,11 +235,13 @@ struct scmi_handle {
212235
struct scmi_clk_ops *clk_ops;
213236
struct scmi_power_ops *power_ops;
214237
struct scmi_sensor_ops *sensor_ops;
238+
struct scmi_reset_ops *reset_ops;
215239
/* for protocol internal use */
216240
void *perf_priv;
217241
void *clk_priv;
218242
void *power_priv;
219243
void *sensor_priv;
244+
void *reset_priv;
220245
};
221246

222247
enum scmi_std_protocol {
@@ -226,6 +251,7 @@ enum scmi_std_protocol {
226251
SCMI_PROTOCOL_PERF = 0x13,
227252
SCMI_PROTOCOL_CLOCK = 0x14,
228253
SCMI_PROTOCOL_SENSOR = 0x15,
254+
SCMI_PROTOCOL_RESET = 0x16,
229255
};
230256

231257
struct scmi_device {

0 commit comments

Comments
 (0)