Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2020, Linaro Limited |
| 4 | * |
| 5 | * Tests scmi_agent uclass and the SCMI drivers implemented in other |
| 6 | * uclass devices probe when a SCMI server exposes resources. |
| 7 | * |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 8 | * Note in test.dts the protocol@10 node in scmi node. Protocol 0x10 is not |
Yuepeng Xing | 7943ae2 | 2022-12-02 14:23:07 +0800 | [diff] [blame] | 9 | * implemented in U-Boot SCMI components but the implementation is expected |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 10 | * to not complain on unknown protocol IDs, as long as it is not used. Note |
| 11 | * in test.dts tests that SCMI drivers probing does not fail for such an |
| 12 | * unknown SCMI protocol ID. |
| 13 | */ |
| 14 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 15 | #include <clk.h> |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 16 | #include <dm.h> |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 17 | #include <reset.h> |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 18 | #include <scmi_agent.h> |
AKASHI Takahiro | 93ecae9 | 2023-10-11 19:07:06 +0900 | [diff] [blame] | 19 | #include <scmi_agent-uclass.h> |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 20 | #include <scmi_protocols.h> |
Raymond Mao | cb73fe9 | 2024-05-16 14:11:52 -0700 | [diff] [blame] | 21 | #include <stdio.h> |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 22 | #include <asm/scmi_test.h> |
| 23 | #include <dm/device-internal.h> |
| 24 | #include <dm/test.h> |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 25 | #include <power/regulator.h> |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 26 | #include <test/ut.h> |
| 27 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 28 | static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts, |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 29 | struct sandbox_scmi_agent *agent, |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 30 | struct udevice *dev) |
| 31 | { |
| 32 | struct sandbox_scmi_devices *scmi_devices; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 33 | |
| 34 | /* Device references to check context against test sequence */ |
| 35 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 36 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 37 | ut_asserteq(2, scmi_devices->clk_count); |
Etienne Carriere | c3bba70 | 2021-03-08 22:38:08 +0100 | [diff] [blame] | 38 | ut_asserteq(1, scmi_devices->reset_count); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 39 | ut_asserteq(2, scmi_devices->regul_count); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 40 | |
| 41 | /* State of the simulated SCMI server exposed */ |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 42 | ut_asserteq(3, agent->clk_count); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 43 | ut_assertnonnull(agent->clk); |
| 44 | ut_asserteq(1, agent->reset_count); |
| 45 | ut_assertnonnull(agent->reset); |
| 46 | ut_asserteq(2, agent->voltd_count); |
| 47 | ut_assertnonnull(agent->voltd); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static int load_sandbox_scmi_test_devices(struct unit_test_state *uts, |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 53 | struct sandbox_scmi_agent **ctx, |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 54 | struct udevice **dev) |
| 55 | { |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 56 | struct udevice *agent_dev; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 57 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 58 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 59 | &agent_dev)); |
| 60 | ut_assertnonnull(agent_dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 61 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 62 | *ctx = sandbox_scmi_agent_ctx(agent_dev); |
| 63 | ut_assertnonnull(*ctx); |
| 64 | |
| 65 | /* probe */ |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 66 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_scmi", |
| 67 | dev)); |
| 68 | ut_assertnonnull(*dev); |
| 69 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 70 | return ut_assert_scmi_state_postprobe(uts, *ctx, *dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static int release_sandbox_scmi_test_devices(struct unit_test_state *uts, |
| 74 | struct udevice *dev) |
| 75 | { |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 76 | /* un-probe */ |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 77 | ut_assertok(device_remove(dev, DM_REMOVE_NORMAL)); |
| 78 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 82 | /* |
| 83 | * Test SCMI states when loading and releasing resources |
| 84 | * related to SCMI drivers. |
| 85 | */ |
| 86 | static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts) |
| 87 | { |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 88 | struct sandbox_scmi_agent *ctx; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 89 | struct udevice *dev = NULL; |
| 90 | int ret; |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 91 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 92 | ret = load_sandbox_scmi_test_devices(uts, &ctx, &dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 93 | if (!ret) |
| 94 | ret = release_sandbox_scmi_test_devices(uts, dev); |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 95 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 96 | return ret; |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 97 | } |
Simon Glass | 725c438 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 98 | DM_TEST(dm_test_scmi_sandbox_agent, UTF_SCAN_FDT); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 99 | |
AKASHI Takahiro | 93ecae9 | 2023-10-11 19:07:06 +0900 | [diff] [blame] | 100 | static int dm_test_scmi_base(struct unit_test_state *uts) |
| 101 | { |
| 102 | struct udevice *agent_dev, *base; |
| 103 | struct scmi_agent_priv *priv; |
| 104 | u32 version, num_agents, num_protocols, impl_version; |
| 105 | u32 attributes, agent_id; |
| 106 | u8 *vendor, *agent_name, *protocols; |
| 107 | int ret; |
| 108 | |
| 109 | /* preparation */ |
| 110 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 111 | &agent_dev)); |
| 112 | ut_assertnonnull(agent_dev); |
| 113 | ut_assertnonnull(priv = dev_get_uclass_plat(agent_dev)); |
| 114 | ut_assertnonnull(base = scmi_get_protocol(agent_dev, |
| 115 | SCMI_PROTOCOL_ID_BASE)); |
| 116 | |
| 117 | /* version */ |
| 118 | ret = scmi_base_protocol_version(base, &version); |
| 119 | ut_assertok(ret); |
| 120 | ut_asserteq(priv->version, version); |
| 121 | |
| 122 | /* protocol attributes */ |
| 123 | ret = scmi_base_protocol_attrs(base, &num_agents, &num_protocols); |
| 124 | ut_assertok(ret); |
| 125 | ut_asserteq(priv->num_agents, num_agents); |
| 126 | ut_asserteq(priv->num_protocols, num_protocols); |
| 127 | |
| 128 | /* discover vendor */ |
| 129 | ret = scmi_base_discover_vendor(base, &vendor); |
| 130 | ut_assertok(ret); |
| 131 | ut_asserteq_str(priv->vendor, vendor); |
| 132 | free(vendor); |
| 133 | |
| 134 | /* message attributes */ |
| 135 | ret = scmi_base_protocol_message_attrs(base, |
| 136 | SCMI_BASE_DISCOVER_SUB_VENDOR, |
| 137 | &attributes); |
| 138 | ut_assertok(ret); |
| 139 | ut_assertok(attributes); |
| 140 | |
| 141 | /* discover sub vendor */ |
| 142 | ret = scmi_base_discover_sub_vendor(base, &vendor); |
| 143 | ut_assertok(ret); |
| 144 | ut_asserteq_str(priv->sub_vendor, vendor); |
| 145 | free(vendor); |
| 146 | |
| 147 | /* impl version */ |
| 148 | ret = scmi_base_discover_impl_version(base, &impl_version); |
| 149 | ut_assertok(ret); |
| 150 | ut_asserteq(priv->impl_version, impl_version); |
| 151 | |
| 152 | /* discover agent (my self) */ |
| 153 | ret = scmi_base_discover_agent(base, 0xffffffff, &agent_id, |
| 154 | &agent_name); |
| 155 | ut_assertok(ret); |
| 156 | ut_asserteq(priv->agent_id, agent_id); |
| 157 | ut_asserteq_str(priv->agent_name, agent_name); |
| 158 | free(agent_name); |
| 159 | |
| 160 | /* discover protocols */ |
| 161 | ret = scmi_base_discover_list_protocols(base, &protocols); |
| 162 | ut_asserteq(num_protocols, ret); |
| 163 | ut_asserteq_mem(priv->protocols, protocols, sizeof(u8) * num_protocols); |
| 164 | free(protocols); |
| 165 | |
| 166 | /* |
| 167 | * NOTE: Sandbox SCMI driver handles device-0 only. It supports setting |
| 168 | * access and protocol permissions, but doesn't allow unsetting them nor |
| 169 | * resetting the configurations. |
| 170 | */ |
| 171 | /* set device permissions */ |
| 172 | ret = scmi_base_set_device_permissions(base, agent_id, 0, |
| 173 | SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS); |
| 174 | ut_assertok(ret); /* SCMI_SUCCESS */ |
| 175 | ret = scmi_base_set_device_permissions(base, agent_id, 1, |
| 176 | SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS); |
| 177 | ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */ |
| 178 | ret = scmi_base_set_device_permissions(base, agent_id, 0, 0); |
| 179 | ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ |
| 180 | |
| 181 | /* set protocol permissions */ |
| 182 | ret = scmi_base_set_protocol_permissions(base, agent_id, 0, |
| 183 | SCMI_PROTOCOL_ID_CLOCK, |
| 184 | SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS); |
| 185 | ut_assertok(ret); /* SCMI_SUCCESS */ |
| 186 | ret = scmi_base_set_protocol_permissions(base, agent_id, 1, |
| 187 | SCMI_PROTOCOL_ID_CLOCK, |
| 188 | SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS); |
| 189 | ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */ |
| 190 | ret = scmi_base_set_protocol_permissions(base, agent_id, 0, |
| 191 | SCMI_PROTOCOL_ID_CLOCK, 0); |
| 192 | ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ |
| 193 | |
| 194 | /* reset agent configuration */ |
| 195 | ret = scmi_base_reset_agent_configuration(base, agent_id, 0); |
| 196 | ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ |
| 197 | ret = scmi_base_reset_agent_configuration(base, agent_id, |
| 198 | SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS); |
| 199 | ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ |
| 200 | ret = scmi_base_reset_agent_configuration(base, agent_id, 0); |
| 201 | ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ |
| 202 | |
| 203 | return 0; |
| 204 | } |
Simon Glass | 725c438 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 205 | DM_TEST(dm_test_scmi_base, UTF_SCAN_FDT); |
AKASHI Takahiro | 93ecae9 | 2023-10-11 19:07:06 +0900 | [diff] [blame] | 206 | |
AKASHI Takahiro | 3d6fe58 | 2023-11-14 11:14:28 +0900 | [diff] [blame] | 207 | static int dm_test_scmi_cmd(struct unit_test_state *uts) |
| 208 | { |
| 209 | struct udevice *agent_dev; |
| 210 | int num_proto = 0; |
| 211 | char cmd_out[30]; |
| 212 | |
| 213 | if (!CONFIG_IS_ENABLED(CMD_SCMI)) |
| 214 | return -EAGAIN; |
| 215 | |
| 216 | /* preparation */ |
| 217 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 218 | &agent_dev)); |
| 219 | ut_assertnonnull(agent_dev); |
| 220 | |
| 221 | /* |
| 222 | * Estimate the number of provided protocols. |
| 223 | * This estimation is correct as far as a corresponding |
| 224 | * protocol support is added to sandbox fake serer. |
| 225 | */ |
| 226 | if (CONFIG_IS_ENABLED(POWER_DOMAIN)) |
| 227 | num_proto++; |
| 228 | if (CONFIG_IS_ENABLED(CLK_SCMI)) |
| 229 | num_proto++; |
| 230 | if (CONFIG_IS_ENABLED(RESET_SCMI)) |
| 231 | num_proto++; |
| 232 | if (CONFIG_IS_ENABLED(DM_REGULATOR_SCMI)) |
| 233 | num_proto++; |
| 234 | |
| 235 | /* scmi info */ |
| 236 | ut_assertok(run_command("scmi info", 0)); |
| 237 | |
| 238 | ut_assert_nextline("SCMI device: scmi"); |
| 239 | snprintf(cmd_out, 30, " protocol version: 0x%x", |
| 240 | SCMI_BASE_PROTOCOL_VERSION); |
| 241 | ut_assert_nextline(cmd_out); |
| 242 | ut_assert_nextline(" # of agents: 2"); |
| 243 | ut_assert_nextline(" 0: platform"); |
| 244 | ut_assert_nextline(" > 1: OSPM"); |
| 245 | snprintf(cmd_out, 30, " # of protocols: %d", num_proto); |
| 246 | ut_assert_nextline(cmd_out); |
| 247 | if (CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN)) |
| 248 | ut_assert_nextline(" Power domain management"); |
| 249 | if (CONFIG_IS_ENABLED(CLK_SCMI)) |
| 250 | ut_assert_nextline(" Clock management"); |
| 251 | if (CONFIG_IS_ENABLED(RESET_SCMI)) |
| 252 | ut_assert_nextline(" Reset domain management"); |
| 253 | if (CONFIG_IS_ENABLED(DM_REGULATOR_SCMI)) |
| 254 | ut_assert_nextline(" Voltage domain management"); |
| 255 | ut_assert_nextline(" vendor: U-Boot"); |
| 256 | ut_assert_nextline(" sub vendor: Sandbox"); |
| 257 | ut_assert_nextline(" impl version: 0x1"); |
| 258 | |
| 259 | ut_assert_console_end(); |
| 260 | |
| 261 | /* scmi perm_dev */ |
| 262 | ut_assertok(run_command("scmi perm_dev 1 0 1", 0)); |
| 263 | ut_assert_console_end(); |
| 264 | |
| 265 | ut_assert(run_command("scmi perm_dev 1 0 0", 0)); |
| 266 | ut_assert_nextline("Denying access to device:0 failed (-13)"); |
| 267 | ut_assert_console_end(); |
| 268 | |
| 269 | /* scmi perm_proto */ |
| 270 | ut_assertok(run_command("scmi perm_proto 1 0 14 1", 0)); |
| 271 | ut_assert_console_end(); |
| 272 | |
| 273 | ut_assert(run_command("scmi perm_proto 1 0 14 0", 0)); |
| 274 | ut_assert_nextline("Denying access to protocol:0x14 on device:0 failed (-13)"); |
| 275 | ut_assert_console_end(); |
| 276 | |
| 277 | /* scmi reset */ |
| 278 | ut_assert(run_command("scmi reset 1 1", 0)); |
| 279 | ut_assert_nextline("Reset failed (-13)"); |
| 280 | ut_assert_console_end(); |
| 281 | |
| 282 | return 0; |
| 283 | } |
Simon Glass | 675fde8 | 2024-08-22 07:57:59 -0600 | [diff] [blame] | 284 | DM_TEST(dm_test_scmi_cmd, UTF_SCAN_FDT | UTF_CONSOLE); |
AKASHI Takahiro | 3d6fe58 | 2023-11-14 11:14:28 +0900 | [diff] [blame] | 285 | |
AKASHI Takahiro | 2ba0f82 | 2023-10-16 14:39:46 +0900 | [diff] [blame] | 286 | static int dm_test_scmi_power_domains(struct unit_test_state *uts) |
| 287 | { |
| 288 | struct sandbox_scmi_agent *agent; |
| 289 | struct sandbox_scmi_devices *scmi_devices; |
| 290 | struct udevice *agent_dev, *pwd, *dev; |
| 291 | u32 version, count, attributes, pstate; |
| 292 | u64 stats_addr; |
| 293 | size_t stats_len; |
| 294 | u8 *name; |
| 295 | int ret; |
| 296 | |
AKASHI Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 297 | if (!CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN)) |
| 298 | return -EAGAIN; |
| 299 | |
AKASHI Takahiro | 2ba0f82 | 2023-10-16 14:39:46 +0900 | [diff] [blame] | 300 | /* preparation */ |
| 301 | ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev)); |
| 302 | ut_assertnonnull(agent); |
| 303 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
| 304 | ut_assertnonnull(scmi_devices); |
| 305 | ut_asserteq(2, scmi_devices->pwdom->id); /* in test.dts */ |
| 306 | |
| 307 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 308 | &agent_dev)); |
| 309 | ut_assertnonnull(agent_dev); |
| 310 | pwd = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_POWER_DOMAIN); |
| 311 | ut_assertnonnull(pwd); |
| 312 | |
| 313 | /* |
| 314 | * SCMI Power domain management protocol interfaces |
| 315 | */ |
| 316 | /* version */ |
| 317 | ret = scmi_generic_protocol_version(pwd, SCMI_PROTOCOL_ID_POWER_DOMAIN, |
| 318 | &version); |
| 319 | ut_assertok(ret); |
| 320 | ut_asserteq(agent->pwdom_version, version); |
| 321 | |
| 322 | /* protocol attributes */ |
| 323 | ret = scmi_pwd_protocol_attrs(pwd, &count, &stats_addr, &stats_len); |
| 324 | ut_assertok(ret); |
| 325 | ut_asserteq(agent->pwdom_count, count); |
| 326 | ut_asserteq(0, stats_len); |
| 327 | |
| 328 | /* protocol message attributes */ |
| 329 | ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_SET, |
| 330 | &attributes); |
| 331 | ut_assertok(ret); |
| 332 | ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_NOTIFY, |
| 333 | &attributes); |
| 334 | ut_asserteq(-ENOENT, ret); /* the protocol not supported */ |
| 335 | |
| 336 | /* power domain attributes */ |
| 337 | ret = scmi_pwd_attrs(pwd, 0, &attributes, &name); |
| 338 | ut_assertok(ret); |
| 339 | ut_asserteq_str("power-domain--0", name); |
| 340 | free(name); |
| 341 | |
| 342 | ret = scmi_pwd_attrs(pwd, 10, &attributes, &name); |
| 343 | ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */ |
| 344 | |
| 345 | /* power domain state set/get */ |
| 346 | ret = scmi_pwd_state_set(pwd, 0, 0, 0); |
| 347 | ut_assertok(ret); |
| 348 | ret = scmi_pwd_state_get(pwd, 0, &pstate); |
| 349 | ut_assertok(ret); |
| 350 | ut_asserteq(0, pstate); /* ON */ |
| 351 | |
| 352 | ret = scmi_pwd_state_set(pwd, 0, 0, SCMI_PWD_PSTATE_TYPE_LOST); |
| 353 | ut_assertok(ret); |
| 354 | ret = scmi_pwd_state_get(pwd, 0, &pstate); |
| 355 | ut_assertok(ret); |
| 356 | ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */ |
| 357 | |
| 358 | ret = scmi_pwd_state_set(pwd, 0, 10, 0); |
| 359 | ut_asserteq(-ENOENT, ret); |
| 360 | |
| 361 | /* power domain name get */ |
| 362 | ret = scmi_pwd_name_get(pwd, 0, &name); |
| 363 | ut_assertok(ret); |
| 364 | ut_asserteq_str("power-domain--0-extended", name); |
| 365 | free(name); |
| 366 | |
| 367 | ret = scmi_pwd_name_get(pwd, 10, &name); |
| 368 | ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */ |
| 369 | |
| 370 | /* |
| 371 | * U-Boot driver model interfaces |
| 372 | */ |
| 373 | /* power_domain_on */ |
| 374 | ret = power_domain_on(scmi_devices->pwdom); |
| 375 | ut_assertok(ret); |
| 376 | ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate); |
| 377 | ut_assertok(ret); |
| 378 | ut_asserteq(0, pstate); /* ON */ |
| 379 | |
| 380 | /* power_domain_off */ |
| 381 | ret = power_domain_off(scmi_devices->pwdom); |
| 382 | ut_assertok(ret); |
| 383 | ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate); |
| 384 | ut_assertok(ret); |
| 385 | ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */ |
| 386 | |
| 387 | return release_sandbox_scmi_test_devices(uts, dev); |
| 388 | } |
Simon Glass | 725c438 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 389 | DM_TEST(dm_test_scmi_power_domains, UTF_SCAN_FDT); |
AKASHI Takahiro | 2ba0f82 | 2023-10-16 14:39:46 +0900 | [diff] [blame] | 390 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 391 | static int dm_test_scmi_clocks(struct unit_test_state *uts) |
| 392 | { |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 393 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 394 | struct sandbox_scmi_devices *scmi_devices; |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 395 | struct udevice *agent_dev, *clock_dev, *dev; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 396 | int ret_dev; |
| 397 | int ret; |
| 398 | |
AKASHI Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 399 | if (!CONFIG_IS_ENABLED(CLK_SCMI)) |
| 400 | return -EAGAIN; |
| 401 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 402 | ret = load_sandbox_scmi_test_devices(uts, &agent, &dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 403 | if (ret) |
| 404 | return ret; |
| 405 | |
| 406 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 407 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 408 | |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 409 | /* Sandbox SCMI clock protocol has its own channel */ |
| 410 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 411 | &agent_dev)); |
| 412 | ut_assertnonnull(agent_dev); |
| 413 | clock_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_CLOCK); |
| 414 | ut_assertnonnull(clock_dev); |
| 415 | ut_asserteq(0x14, sandbox_scmi_channel_id(clock_dev)); |
| 416 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 417 | /* Test SCMI clocks rate manipulation */ |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 418 | ut_asserteq(333, agent->clk[0].rate); |
| 419 | ut_asserteq(200, agent->clk[1].rate); |
| 420 | ut_asserteq(1000, agent->clk[2].rate); |
| 421 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 422 | ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); |
| 423 | ut_asserteq(333, clk_get_rate(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 424 | |
| 425 | ret_dev = clk_set_rate(&scmi_devices->clk[1], 1088); |
| 426 | ut_assert(!ret_dev || ret_dev == 1088); |
| 427 | |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 428 | ut_asserteq(1088, agent->clk[0].rate); |
| 429 | ut_asserteq(200, agent->clk[1].rate); |
| 430 | ut_asserteq(1000, agent->clk[2].rate); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 431 | |
| 432 | ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); |
| 433 | ut_asserteq(1088, clk_get_rate(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 434 | |
| 435 | /* restore original rate for further tests */ |
| 436 | ret_dev = clk_set_rate(&scmi_devices->clk[1], 333); |
| 437 | ut_assert(!ret_dev || ret_dev == 333); |
| 438 | |
| 439 | /* Test SCMI clocks gating manipulation */ |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 440 | ut_assert(!agent->clk[0].enabled); |
| 441 | ut_assert(!agent->clk[1].enabled); |
| 442 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 443 | |
| 444 | ut_asserteq(0, clk_enable(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 445 | |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 446 | ut_assert(agent->clk[0].enabled); |
| 447 | ut_assert(!agent->clk[1].enabled); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 448 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 449 | |
| 450 | ut_assertok(clk_disable(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 451 | |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 452 | ut_assert(!agent->clk[0].enabled); |
| 453 | ut_assert(!agent->clk[1].enabled); |
| 454 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 455 | |
| 456 | return release_sandbox_scmi_test_devices(uts, dev); |
| 457 | } |
Simon Glass | 725c438 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 458 | DM_TEST(dm_test_scmi_clocks, UTF_SCAN_FDT); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 459 | |
| 460 | static int dm_test_scmi_resets(struct unit_test_state *uts) |
| 461 | { |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 462 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 463 | struct sandbox_scmi_devices *scmi_devices; |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 464 | struct udevice *agent_dev, *reset_dev, *dev = NULL; |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 465 | int ret; |
| 466 | |
AKASHI Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 467 | if (!CONFIG_IS_ENABLED(RESET_SCMI)) |
| 468 | return -EAGAIN; |
| 469 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 470 | ret = load_sandbox_scmi_test_devices(uts, &agent, &dev); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 471 | if (ret) |
| 472 | return ret; |
| 473 | |
| 474 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 475 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 476 | |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 477 | /* Sandbox SCMI reset protocol doesn't have its own channel */ |
| 478 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 479 | &agent_dev)); |
| 480 | ut_assertnonnull(agent_dev); |
| 481 | reset_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_RESET_DOMAIN); |
| 482 | ut_assertnonnull(reset_dev); |
| 483 | ut_asserteq(0x0, sandbox_scmi_channel_id(reset_dev)); |
| 484 | |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 485 | /* Test SCMI resect controller manipulation */ |
Marek Vasut | fa847bb | 2023-03-10 04:33:13 +0100 | [diff] [blame] | 486 | ut_assert(!agent->reset[0].asserted); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 487 | |
| 488 | ut_assertok(reset_assert(&scmi_devices->reset[0])); |
Marek Vasut | fa847bb | 2023-03-10 04:33:13 +0100 | [diff] [blame] | 489 | ut_assert(agent->reset[0].asserted); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 490 | |
| 491 | ut_assertok(reset_deassert(&scmi_devices->reset[0])); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 492 | ut_assert(!agent->reset[0].asserted); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 493 | |
| 494 | return release_sandbox_scmi_test_devices(uts, dev); |
| 495 | } |
Simon Glass | 725c438 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 496 | DM_TEST(dm_test_scmi_resets, UTF_SCAN_FDT); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 497 | |
| 498 | static int dm_test_scmi_voltage_domains(struct unit_test_state *uts) |
| 499 | { |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 500 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 501 | struct sandbox_scmi_devices *scmi_devices; |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 502 | struct dm_regulator_uclass_plat *uc_pdata; |
| 503 | struct udevice *dev; |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 504 | struct udevice *regul0_dev; |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 505 | |
AKASHI Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 506 | if (!CONFIG_IS_ENABLED(DM_REGULATOR_SCMI)) |
| 507 | return -EAGAIN; |
| 508 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 509 | ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev)); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 510 | |
| 511 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 512 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 513 | |
| 514 | /* Set/Get an SCMI voltage domain level */ |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 515 | regul0_dev = scmi_devices->regul[0]; |
| 516 | ut_assert(regul0_dev); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 517 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 518 | uc_pdata = dev_get_uclass_plat(regul0_dev); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 519 | ut_assert(uc_pdata); |
| 520 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 521 | ut_assertok(regulator_set_value(regul0_dev, uc_pdata->min_uV)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 522 | ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->min_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 523 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 524 | ut_assert(regulator_get_value(regul0_dev) == uc_pdata->min_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 525 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 526 | ut_assertok(regulator_set_value(regul0_dev, uc_pdata->max_uV)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 527 | ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->max_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 528 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 529 | ut_assert(regulator_get_value(regul0_dev) == uc_pdata->max_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 530 | |
| 531 | /* Enable/disable SCMI voltage domains */ |
| 532 | ut_assertok(regulator_set_enable(scmi_devices->regul[0], false)); |
| 533 | ut_assertok(regulator_set_enable(scmi_devices->regul[1], false)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 534 | ut_assert(!agent->voltd[0].enabled); |
| 535 | ut_assert(!agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 536 | |
| 537 | ut_assertok(regulator_set_enable(scmi_devices->regul[0], true)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 538 | ut_assert(agent->voltd[0].enabled); |
| 539 | ut_assert(!agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 540 | |
| 541 | ut_assertok(regulator_set_enable(scmi_devices->regul[1], true)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 542 | ut_assert(agent->voltd[0].enabled); |
| 543 | ut_assert(agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 544 | |
| 545 | ut_assertok(regulator_set_enable(scmi_devices->regul[0], false)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 546 | ut_assert(!agent->voltd[0].enabled); |
| 547 | ut_assert(agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 548 | |
| 549 | return release_sandbox_scmi_test_devices(uts, dev); |
| 550 | } |
Simon Glass | 725c438 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 551 | DM_TEST(dm_test_scmi_voltage_domains, UTF_SCAN_FDT); |