Re: [PATCH v3 2/5] firmware: scmi: support protocols on sandbox only if enabled

2023-11-14 Thread Simon Glass
On Mon, 13 Nov 2023 at 19:14, AKASHI Takahiro
 wrote:
>
> This change will be useful when we manually test SCMI on sandbox
> by enabling/disabling a specific SCMI protocol.
>
> Signed-off-by: AKASHI Takahiro 
> ---
> v9
> * use CONFIG_IS_ENABLED() rather than IS_ENABLED()
> * remove goto by introducing a not_supported() function
> ---
>  drivers/firmware/scmi/sandbox-scmi_agent.c   | 30 ++--
>  drivers/firmware/scmi/sandbox-scmi_devices.c | 78 
>  2 files changed, 71 insertions(+), 37 deletions(-)

Reviewed-by: Simon Glass 


[PATCH v3 2/5] firmware: scmi: support protocols on sandbox only if enabled

2023-11-13 Thread AKASHI Takahiro
This change will be useful when we manually test SCMI on sandbox
by enabling/disabling a specific SCMI protocol.

Signed-off-by: AKASHI Takahiro 
---
v9
* use CONFIG_IS_ENABLED() rather than IS_ENABLED()
* remove goto by introducing a not_supported() function
---
 drivers/firmware/scmi/sandbox-scmi_agent.c   | 30 ++--
 drivers/firmware/scmi/sandbox-scmi_devices.c | 78 
 2 files changed, 71 insertions(+), 37 deletions(-)

diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c 
b/drivers/firmware/scmi/sandbox-scmi_agent.c
index d13180962662..cc9011c7312f 100644
--- a/drivers/firmware/scmi/sandbox-scmi_agent.c
+++ b/drivers/firmware/scmi/sandbox-scmi_agent.c
@@ -66,10 +66,10 @@ struct scmi_channel {
 };
 
 static u8 protocols[] = {
-   SCMI_PROTOCOL_ID_POWER_DOMAIN,
-   SCMI_PROTOCOL_ID_CLOCK,
-   SCMI_PROTOCOL_ID_RESET_DOMAIN,
-   SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN,
+   CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN, (SCMI_PROTOCOL_ID_POWER_DOMAIN,))
+   CONFIG_IS_ENABLED(CLK_SCMI, (SCMI_PROTOCOL_ID_CLOCK,))
+   CONFIG_IS_ENABLED(RESET_SCMI, (SCMI_PROTOCOL_ID_RESET_DOMAIN,))
+   CONFIG_IS_ENABLED(DM_REGULATOR_SCMI, (SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN,))
 };
 
 #define NUM_PROTOCOLS ARRAY_SIZE(protocols)
@@ -1124,6 +1124,13 @@ unsigned int sandbox_scmi_channel_id(struct udevice *dev)
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,
 struct scmi_channel *channel,
 struct scmi_msg *msg)
@@ -1160,6 +1167,9 @@ static int sandbox_scmi_test_process_msg(struct udevice 
*dev,
}
break;
case SCMI_PROTOCOL_ID_POWER_DOMAIN:
+   if (!CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN))
+   return sandbox_proto_not_supported(msg);
+
switch (msg->message_id) {
case SCMI_PROTOCOL_VERSION:
return sandbox_scmi_pwd_protocol_version(dev, msg);
@@ -1180,6 +1190,9 @@ static int sandbox_scmi_test_process_msg(struct udevice 
*dev,
}
break;
case SCMI_PROTOCOL_ID_CLOCK:
+   if (!CONFIG_IS_ENABLED(CLK_SCMI))
+   return sandbox_proto_not_supported(msg);
+
switch (msg->message_id) {
case SCMI_PROTOCOL_ATTRIBUTES:
return sandbox_scmi_clock_protocol_attribs(dev, msg);
@@ -1196,6 +1209,9 @@ static int sandbox_scmi_test_process_msg(struct udevice 
*dev,
}
break;
case SCMI_PROTOCOL_ID_RESET_DOMAIN:
+   if (!CONFIG_IS_ENABLED(RESET_SCMI))
+   return sandbox_proto_not_supported(msg);
+
switch (msg->message_id) {
case SCMI_RESET_DOMAIN_ATTRIBUTES:
return sandbox_scmi_rd_attribs(dev, msg);
@@ -1206,6 +1222,9 @@ static int sandbox_scmi_test_process_msg(struct udevice 
*dev,
}
break;
case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN:
+   if (!CONFIG_IS_ENABLED(DM_REGULATOR_SCMI))
+   return sandbox_proto_not_supported(msg);
+
switch (msg->message_id) {
case SCMI_VOLTAGE_DOMAIN_ATTRIBUTES:
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_PERF:
case SCMI_PROTOCOL_ID_SENSOR:
-   *(u32 *)msg->out_msg = SCMI_NOT_SUPPORTED;
-   return 0;
+   return sandbox_proto_not_supported(msg);
default:
break;
}
diff --git a/drivers/firmware/scmi/sandbox-scmi_devices.c 
b/drivers/firmware/scmi/sandbox-scmi_devices.c
index facb5b06ffb5..603e2bb40aff 100644
--- a/drivers/firmware/scmi/sandbox-scmi_devices.c
+++ b/drivers/firmware/scmi/sandbox-scmi_devices.c
@@ -62,12 +62,13 @@ static int sandbox_scmi_devices_remove(struct udevice *dev)
if (!devices)
return 0;
 
-   for (n = 0; n < SCMI_TEST_DEVICES_RD_COUNT; n++) {
-   int ret2 = reset_free(devices->reset + n);
+   if (CONFIG_IS_ENABLED(RESET_SCMI))
+   for (n = 0; n < SCMI_TEST_DEVICES_RD_COUNT; n++) {
+   int ret2 = reset_free(devices->reset + n);
 
-   if (ret2 && !ret)
-   ret = ret2;
-   }
+   if (ret2 && !ret)
+   ret = ret2;
+   }
 
return ret;
 }
@@ -89,39 +90,53 @@ static int sandbox_scmi_devices_probe(struct udevice *dev)
.regul_count = SCMI_TEST_DEVICES_VOLTD_COUNT,
};
 
-   ret =