Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
scmi_validation: scmi clock protocol validation
Browse files Browse the repository at this point in the history
Use scmi API scmi_message_validation before calling
message handler, update mod_scmi_clock_unit_test.

Change-Id: Idbbe23ce9644c13ec4dd24575cdb75492a1d6735
Signed-off-by: khaled ali ahmed <khaled.aliahmed@arm.com>
  • Loading branch information
khaledAhmed-arm committed May 14, 2024
1 parent 8627e15 commit d5f7efd
Show file tree
Hide file tree
Showing 5 changed files with 1,710 additions and 66 deletions.
49 changes: 19 additions & 30 deletions module/scmi_clock/src/mod_scmi_clock.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Arm SCP/MCP Software
* Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
Expand Down Expand Up @@ -134,9 +134,7 @@ static int scmi_clock_describe_rates_handler(fwk_id_t service_id,
*/
static struct mod_scmi_clock_ctx scmi_clock_ctx;

static int (*const handler_table[MOD_SCMI_CLOCK_COMMAND_COUNT])(
fwk_id_t,
const uint32_t *) = {
static handler_table_t handler_table[MOD_SCMI_CLOCK_COMMAND_COUNT] = {
[MOD_SCMI_PROTOCOL_VERSION] = scmi_clock_protocol_version_handler,
[MOD_SCMI_PROTOCOL_ATTRIBUTES] = scmi_clock_protocol_attributes_handler,
[MOD_SCMI_PROTOCOL_MESSAGE_ATTRIBUTES] =
Expand All @@ -148,7 +146,7 @@ static int (*const handler_table[MOD_SCMI_CLOCK_COMMAND_COUNT])(
[MOD_SCMI_CLOCK_DESCRIBE_RATES] = scmi_clock_describe_rates_handler,
};

static const unsigned int payload_size_table[MOD_SCMI_CLOCK_COMMAND_COUNT] = {
static const size_t payload_size_table[MOD_SCMI_CLOCK_COMMAND_COUNT] = {
[MOD_SCMI_PROTOCOL_VERSION] = 0,
[MOD_SCMI_PROTOCOL_ATTRIBUTES] = 0,
[MOD_SCMI_PROTOCOL_MESSAGE_ATTRIBUTES] =
Expand Down Expand Up @@ -675,15 +673,6 @@ static int scmi_clock_permissions_handler(
return FWK_E_ACCESS;
}

if (message_id < 3) {
perms = scmi_clock_ctx.res_perms_api->agent_has_protocol_permission(
agent_id, MOD_SCMI_PROTOCOL_ID_CLOCK);
if (perms == MOD_RES_PERMS_ACCESS_ALLOWED) {
return FWK_SUCCESS;
}
return FWK_E_ACCESS;
}

perms = scmi_clock_ctx.res_perms_api->agent_has_resource_permission(
agent_id, MOD_SCMI_PROTOCOL_ID_CLOCK, message_id, scmi_clock_idx);

Expand Down Expand Up @@ -1382,28 +1371,28 @@ static int scmi_clock_get_scmi_protocol_id(fwk_id_t protocol_id,
static int scmi_clock_message_handler(fwk_id_t protocol_id, fwk_id_t service_id,
const uint32_t *payload, size_t payload_size, unsigned int message_id)
{
int32_t return_value;
int validation_result;

static_assert(FWK_ARRAY_SIZE(handler_table) ==
FWK_ARRAY_SIZE(payload_size_table),
"[SCMI] Clock management protocol table sizes not consistent");
fwk_assert(payload != NULL);

if (message_id >= FWK_ARRAY_SIZE(handler_table)) {
return_value = (int32_t)SCMI_NOT_FOUND;
goto error;
}

if (payload_size != payload_size_table[message_id]) {
return_value = (int32_t)SCMI_PROTOCOL_ERROR;
goto error;
validation_result = scmi_clock_ctx.scmi_api->scmi_message_validation(
MOD_SCMI_PROTOCOL_ID_CLOCK,
service_id,
payload,
payload_size,
message_id,
payload_size_table,
MOD_SCMI_CLOCK_COMMAND_COUNT,
handler_table);

if (validation_result == SCMI_SUCCESS) {
return handler_table[message_id](service_id, payload);
} else {
return scmi_clock_ctx.scmi_api->respond(
service_id, &validation_result, sizeof(validation_result));
}

return handler_table[message_id](service_id, payload);

error:
return scmi_clock_ctx.scmi_api->respond(
service_id, &return_value, sizeof(return_value));
}

static struct mod_scmi_to_protocol_api scmi_clock_mod_scmi_to_protocol_api = {
Expand Down
Loading

0 comments on commit d5f7efd

Please sign in to comment.