firmware: scmi: support protocols on sandbox only if enabled

This change will be useful when we manually test SCMI on sandbox
by enabling/disabling a specific SCMI protocol.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
AKASHI Takahiro
2023-11-14 11:14:25 +09:00
committed by Tom Rini
parent 63cd0dceea
commit 9c07c0a4fc
2 changed files with 70 additions and 36 deletions

View File

@@ -66,10 +66,10 @@ struct scmi_channel {
}; };
static u8 protocols[] = { static u8 protocols[] = {
SCMI_PROTOCOL_ID_POWER_DOMAIN, CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN, (SCMI_PROTOCOL_ID_POWER_DOMAIN,))
SCMI_PROTOCOL_ID_CLOCK, CONFIG_IS_ENABLED(CLK_SCMI, (SCMI_PROTOCOL_ID_CLOCK,))
SCMI_PROTOCOL_ID_RESET_DOMAIN, CONFIG_IS_ENABLED(RESET_SCMI, (SCMI_PROTOCOL_ID_RESET_DOMAIN,))
SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN, CONFIG_IS_ENABLED(DM_REGULATOR_SCMI, (SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN,))
}; };
#define NUM_PROTOCOLS ARRAY_SIZE(protocols) #define NUM_PROTOCOLS ARRAY_SIZE(protocols)
@@ -1124,6 +1124,13 @@ unsigned int sandbox_scmi_channel_id(struct udevice *dev)
return chan->channel_id; return chan->channel_id;
} }
static int sandbox_proto_not_supported(struct scmi_msg *msg)
{
*(u32 *)msg->out_msg = SCMI_NOT_SUPPORTED;
return 0;
}
static int sandbox_scmi_test_process_msg(struct udevice *dev, static int sandbox_scmi_test_process_msg(struct udevice *dev,
struct scmi_channel *channel, struct scmi_channel *channel,
struct scmi_msg *msg) struct scmi_msg *msg)
@@ -1160,6 +1167,9 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev,
} }
break; break;
case SCMI_PROTOCOL_ID_POWER_DOMAIN: case SCMI_PROTOCOL_ID_POWER_DOMAIN:
if (!CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN))
return sandbox_proto_not_supported(msg);
switch (msg->message_id) { switch (msg->message_id) {
case SCMI_PROTOCOL_VERSION: case SCMI_PROTOCOL_VERSION:
return sandbox_scmi_pwd_protocol_version(dev, msg); return sandbox_scmi_pwd_protocol_version(dev, msg);
@@ -1180,6 +1190,9 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev,
} }
break; break;
case SCMI_PROTOCOL_ID_CLOCK: case SCMI_PROTOCOL_ID_CLOCK:
if (!CONFIG_IS_ENABLED(CLK_SCMI))
return sandbox_proto_not_supported(msg);
switch (msg->message_id) { switch (msg->message_id) {
case SCMI_PROTOCOL_ATTRIBUTES: case SCMI_PROTOCOL_ATTRIBUTES:
return sandbox_scmi_clock_protocol_attribs(dev, msg); return sandbox_scmi_clock_protocol_attribs(dev, msg);
@@ -1196,6 +1209,9 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev,
} }
break; break;
case SCMI_PROTOCOL_ID_RESET_DOMAIN: case SCMI_PROTOCOL_ID_RESET_DOMAIN:
if (!CONFIG_IS_ENABLED(RESET_SCMI))
return sandbox_proto_not_supported(msg);
switch (msg->message_id) { switch (msg->message_id) {
case SCMI_RESET_DOMAIN_ATTRIBUTES: case SCMI_RESET_DOMAIN_ATTRIBUTES:
return sandbox_scmi_rd_attribs(dev, msg); return sandbox_scmi_rd_attribs(dev, msg);
@@ -1206,6 +1222,9 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev,
} }
break; break;
case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN: case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN:
if (!CONFIG_IS_ENABLED(DM_REGULATOR_SCMI))
return sandbox_proto_not_supported(msg);
switch (msg->message_id) { switch (msg->message_id) {
case SCMI_VOLTAGE_DOMAIN_ATTRIBUTES: case SCMI_VOLTAGE_DOMAIN_ATTRIBUTES:
return sandbox_scmi_voltd_attribs(dev, msg); return sandbox_scmi_voltd_attribs(dev, msg);
@@ -1224,8 +1243,7 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev,
case SCMI_PROTOCOL_ID_SYSTEM: case SCMI_PROTOCOL_ID_SYSTEM:
case SCMI_PROTOCOL_ID_PERF: case SCMI_PROTOCOL_ID_PERF:
case SCMI_PROTOCOL_ID_SENSOR: case SCMI_PROTOCOL_ID_SENSOR:
*(u32 *)msg->out_msg = SCMI_NOT_SUPPORTED; return sandbox_proto_not_supported(msg);
return 0;
default: default:
break; break;
} }

View File

@@ -62,12 +62,13 @@ static int sandbox_scmi_devices_remove(struct udevice *dev)
if (!devices) if (!devices)
return 0; return 0;
for (n = 0; n < SCMI_TEST_DEVICES_RD_COUNT; n++) { if (CONFIG_IS_ENABLED(RESET_SCMI))
int ret2 = reset_free(devices->reset + n); for (n = 0; n < SCMI_TEST_DEVICES_RD_COUNT; n++) {
int ret2 = reset_free(devices->reset + n);
if (ret2 && !ret) if (ret2 && !ret)
ret = ret2; ret = ret2;
} }
return ret; return ret;
} }
@@ -89,39 +90,53 @@ static int sandbox_scmi_devices_probe(struct udevice *dev)
.regul_count = SCMI_TEST_DEVICES_VOLTD_COUNT, .regul_count = SCMI_TEST_DEVICES_VOLTD_COUNT,
}; };
ret = power_domain_get_by_index(dev, priv->devices.pwdom, 0); if (CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN)) {
if (ret) { ret = power_domain_get_by_index(dev, priv->devices.pwdom, 0);
dev_err(dev, "%s: Failed on power domain\n", __func__);
return ret;
}
for (n = 0; n < SCMI_TEST_DEVICES_CLK_COUNT; n++) {
ret = clk_get_by_index(dev, n, priv->devices.clk + n);
if (ret) { if (ret) {
dev_err(dev, "%s: Failed on clk %zu\n", __func__, n); dev_err(dev, "%s: Failed on power domain\n", __func__);
return ret; return ret;
} }
} }
for (n = 0; n < SCMI_TEST_DEVICES_RD_COUNT; n++) { if (CONFIG_IS_ENABLED(CLK_SCMI)) {
ret = reset_get_by_index(dev, n, priv->devices.reset + n); for (n = 0; n < SCMI_TEST_DEVICES_CLK_COUNT; n++) {
if (ret) { ret = clk_get_by_index(dev, n, priv->devices.clk + n);
dev_err(dev, "%s: Failed on reset %zu\n", __func__, n); if (ret) {
goto err_reset; dev_err(dev, "%s: Failed on clk %zu\n",
__func__, n);
return ret;
}
} }
} }
for (n = 0; n < SCMI_TEST_DEVICES_VOLTD_COUNT; n++) { if (CONFIG_IS_ENABLED(RESET_SCMI)) {
char name[32]; for (n = 0; n < SCMI_TEST_DEVICES_RD_COUNT; n++) {
ret = reset_get_by_index(dev, n,
priv->devices.reset + n);
if (ret) {
dev_err(dev, "%s: Failed on reset %zu\n",
__func__, n);
goto err_reset;
}
}
}
ret = snprintf(name, sizeof(name), "regul%zu-supply", n); if (CONFIG_IS_ENABLED(DM_REGULATOR_SCMI)) {
assert(ret >= 0 && ret < sizeof(name)); for (n = 0; n < SCMI_TEST_DEVICES_VOLTD_COUNT; n++) {
char name[32];
ret = device_get_supply_regulator(dev, name, ret = snprintf(name, sizeof(name), "regul%zu-supply",
priv->devices.regul + n); n);
if (ret) { assert(ret >= 0 && ret < sizeof(name));
dev_err(dev, "%s: Failed on voltd %zu\n", __func__, n);
goto err_regul; ret = device_get_supply_regulator(dev, name,
priv->devices.regul
+ n);
if (ret) {
dev_err(dev, "%s: Failed on voltd %zu\n",
__func__, n);
goto err_regul;
}
} }
} }
@@ -130,8 +145,9 @@ static int sandbox_scmi_devices_probe(struct udevice *dev)
err_regul: err_regul:
n = SCMI_TEST_DEVICES_RD_COUNT; n = SCMI_TEST_DEVICES_RD_COUNT;
err_reset: err_reset:
for (; n > 0; n--) if (CONFIG_IS_ENABLED(RESET_SCMI))
reset_free(priv->devices.reset + n - 1); for (; n > 0; n--)
reset_free(priv->devices.reset + n - 1);
return ret; return ret;
} }