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

Commit

Permalink
scmi_validation: scmi perf protocol validation
Browse files Browse the repository at this point in the history
Use scmi API scmi_frame_validation before calling
message handler, update unit test.

Signed-off-by: khaled ali ahmed <[email protected]>
Change-Id: Ib80934ac15096314ca2f1f667ac06c22a2b88da3
  • Loading branch information
khaledAhmed-arm committed May 9, 2024
1 parent 262d3f4 commit cf0c214
Show file tree
Hide file tree
Showing 12 changed files with 1,182 additions and 3,283 deletions.
78 changes: 30 additions & 48 deletions module/scmi_perf/src/scmi_perf_protocol_ops.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Arm SCP/MCP Software
* Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2023-2024, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
Expand Down Expand Up @@ -85,8 +85,7 @@ static int scmi_perf_limits_notify(
static int scmi_perf_level_notify(fwk_id_t service_id, const uint32_t *payload);
#endif

static int (
*handler_table[MOD_SCMI_PERF_COMMAND_COUNT])(fwk_id_t, const uint32_t *) = {
static handler_table_t handler_table[MOD_SCMI_PERF_COMMAND_COUNT] = {
[MOD_SCMI_PROTOCOL_VERSION] = scmi_perf_protocol_version_handler,
[MOD_SCMI_PROTOCOL_ATTRIBUTES] = scmi_perf_protocol_attributes_handler,
[MOD_SCMI_PROTOCOL_MESSAGE_ATTRIBUTES] =
Expand All @@ -106,7 +105,7 @@ static int (
#endif
};

static unsigned int payload_size_table[MOD_SCMI_PERF_COMMAND_COUNT] = {
static size_t payload_size_table[MOD_SCMI_PERF_COMMAND_COUNT] = {
[MOD_SCMI_PROTOCOL_VERSION] = 0,
[MOD_SCMI_PROTOCOL_ATTRIBUTES] = 0,
[MOD_SCMI_PROTOCOL_MESSAGE_ATTRIBUTES] =
Expand Down Expand Up @@ -218,18 +217,6 @@ static int scmi_perf_permissions_handler(
return FWK_E_ACCESS;
}

if (message_id < (unsigned int)MOD_SCMI_PERF_DOMAIN_ATTRIBUTES) {
/*
* PROTOCOL_VERSION, PROTOCOL_ATTRIBUTES & PROTOCOL_MESSAGE_ATRIBUTES
*/
perms = perf_prot_ctx.res_perms_api->agent_has_protocol_permission(
agent_id, MOD_SCMI_PROTOCOL_ID_PERF);
if (perms == MOD_RES_PERMS_ACCESS_ALLOWED) {
return FWK_SUCCESS;
}
return FWK_E_ACCESS;
}

status = get_perf_domain_id(payload, &domain_id);
if (status != FWK_SUCCESS) {
return FWK_E_PARAM;
Expand Down Expand Up @@ -990,48 +977,43 @@ static int scmi_perf_message_handler(
size_t payload_size,
unsigned int message_id)
{
int32_t return_value;
#ifdef BUILD_HAS_MOD_RESOURCE_PERMS
int status;
#endif
int validation_result;

static_assert(
FWK_ARRAY_SIZE(handler_table) == FWK_ARRAY_SIZE(payload_size_table),
"[SCMI] Performance 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 (handler_table[message_id] == NULL) {
return_value = (int32_t)SCMI_NOT_SUPPORTED;
goto error;
}

if (payload_size != payload_size_table[message_id]) {
return_value = (int32_t)SCMI_PROTOCOL_ERROR;
goto error;
}
validation_result =
perf_prot_ctx.scmi_perf_ctx->scmi_api->scmi_message_validation(
MOD_SCMI_PROTOCOL_ID_PERF,
service_id,
payload,
payload_size,
message_id,
payload_size_table,
(unsigned int)MOD_SCMI_PERF_COMMAND_COUNT,
handler_table);

#ifdef BUILD_HAS_MOD_RESOURCE_PERMS
status = scmi_perf_permissions_handler(service_id, payload, message_id);
if (status != FWK_SUCCESS) {
if (status == FWK_E_PARAM) {
return_value = (int32_t)SCMI_NOT_FOUND;
} else {
return_value = (int32_t)SCMI_DENIED;
if ((message_id >= MOD_SCMI_MESSAGE_ID_ATTRIBUTE) &&
(validation_result == SCMI_SUCCESS)) {
int status =
scmi_perf_permissions_handler(service_id, payload, message_id);
if (status != FWK_SUCCESS) {
if (status == FWK_E_PARAM) {
validation_result = (int32_t)SCMI_NOT_FOUND;
} else {
validation_result = (int32_t)SCMI_DENIED;
}
}
goto error;
}
#endif

return handler_table[message_id](service_id, payload);

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

static struct mod_scmi_to_protocol_api scmi_perf_mod_scmi_to_protocol_api = {
Expand Down
25 changes: 24 additions & 1 deletion module/scmi_perf/test/fastchannels/mod_scmi_perf_fch_extra.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Arm SCP/MCP Software
* Copyright (c) 2022-2023, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2022-2024, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
Expand Down Expand Up @@ -233,3 +233,26 @@ int mod_dvfs_domain_api_set_level(
fwk_id_t domain_id,
uintptr_t cookie,
uint32_t level);

/*!
* \brief Validate received protocol message.
*
* \param protocol_id Protocol identifier.
* \param service_id Service identifier.
* \param payload Payload data to write, or NULL if a payload has already
* been written.
* \param payload_size Payload size.
* \param message_id Message identifier.
* \param payload_size_table Expected size of payload per message ID
* \param command_count total number of commands per protocol
* \param handler_table pointer to message handler
*/
int mod_scmi_from_protocol_api_scmi_frame_validation(
uint8_t protocol_id,
fwk_id_t service_id,
const uint32_t *payload,
size_t payload_size,
size_t message_id,
const size_t *payload_size_table,
size_t command_count,
const handler_table_t *handler_table);
24 changes: 16 additions & 8 deletions module/scmi_perf/test/fastchannels/mod_scmi_perf_fch_unit_test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Arm SCP/MCP Software
* Copyright (c) 2022-2023, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2022-2024, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
Expand Down Expand Up @@ -43,6 +43,7 @@ struct mod_scmi_from_protocol_api from_protocol_api = {
.get_max_payload_size = mod_scmi_from_protocol_api_get_max_payload_size,
.write_payload = mod_scmi_from_protocol_api_write_payload,
.respond = mod_scmi_from_protocol_api_respond,
.scmi_message_validation = mod_scmi_from_protocol_api_scmi_frame_validation,
.notify = mod_scmi_from_protocol_api_notify,
};

Expand Down Expand Up @@ -170,7 +171,8 @@ void utest_scmi_perf_protocol_message_attributes_handler_valid_param(void)

mod_scmi_from_protocol_api_respond_Stub(
message_attributes_handler_valid_param_respond_callback);

mod_scmi_from_protocol_api_scmi_frame_validation_ExpectAnyArgsAndReturn(
SCMI_SUCCESS);
status = to_protocol_api->message_handler(
(fwk_id_t)MOD_SCMI_PROTOCOL_ID_PERF,
service_id,
Expand Down Expand Up @@ -208,7 +210,8 @@ void utest_scmi_perf_protocol_message_attributes_handler_invalid_param(void)

mod_scmi_from_protocol_api_respond_Stub(
message_attributes_handler_invalid_param_respond_callback);

mod_scmi_from_protocol_api_scmi_frame_validation_ExpectAnyArgsAndReturn(
SCMI_SUCCESS);
status = to_protocol_api->message_handler(
(fwk_id_t)MOD_SCMI_PROTOCOL_ID_PERF,
service_id,
Expand Down Expand Up @@ -296,7 +299,8 @@ void utest_scmi_perf_domain_attributes_handler_valid_param(void)

mod_scmi_from_protocol_api_respond_Stub(
domain_attributes_handler_valid_param_respond_callback);

mod_scmi_from_protocol_api_scmi_frame_validation_ExpectAnyArgsAndReturn(
SCMI_SUCCESS);
status = to_protocol_api->message_handler(
(fwk_id_t)MOD_SCMI_PROTOCOL_ID_PERF,
service_id,
Expand Down Expand Up @@ -335,7 +339,8 @@ void utest_scmi_perf_domain_attributes_handler_invalid_param(void)

mod_scmi_from_protocol_api_respond_Stub(
domain_attributes_handler_invalid_param_respond_callback);

mod_scmi_from_protocol_api_scmi_frame_validation_ExpectAnyArgsAndReturn(
SCMI_SUCCESS);
status = to_protocol_api->message_handler(
(fwk_id_t)MOD_SCMI_PROTOCOL_ID_PERF,
service_id,
Expand Down Expand Up @@ -420,7 +425,8 @@ void utest_scmi_perf_describe_fast_channels_valid_params(void)

mod_scmi_from_protocol_api_respond_Stub(
describe_fast_channels_valid_params_respond_callback);

mod_scmi_from_protocol_api_scmi_frame_validation_ExpectAnyArgsAndReturn(
SCMI_SUCCESS);
status = to_protocol_api->message_handler(
(fwk_id_t)MOD_SCMI_PROTOCOL_ID_PERF,
service_id,
Expand Down Expand Up @@ -463,7 +469,8 @@ void utest_scmi_perf_describe_fast_channels_invalid_domain_id(void)

mod_scmi_from_protocol_api_respond_Stub(
describe_fast_channels_invalid_domain_id_respond_callback);

mod_scmi_from_protocol_api_scmi_frame_validation_ExpectAnyArgsAndReturn(
SCMI_SUCCESS);
status = to_protocol_api->message_handler(
(fwk_id_t)MOD_SCMI_PROTOCOL_ID_PERF,
service_id,
Expand Down Expand Up @@ -506,7 +513,8 @@ void utest_scmi_perf_describe_fast_channels_invalid_message_id(void)

mod_scmi_from_protocol_api_respond_Stub(
describe_fast_channels_invalid_message_id_respond_callback);

mod_scmi_from_protocol_api_scmi_frame_validation_ExpectAnyArgsAndReturn(
SCMI_SUCCESS);
status = to_protocol_api->message_handler(
(fwk_id_t)MOD_SCMI_PROTOCOL_ID_PERF,
service_id,
Expand Down
Loading

0 comments on commit cf0c214

Please sign in to comment.