Commit 6cc2c1cb authored by Etienne Carriere's avatar Etienne Carriere Committed by Etienne Carriere
Browse files

drivers/scmi-msg: support for reset domain protocol

Adds SCMI reset domain protocol support in the SCMI message drivers
as defined in SCMI specification v2.0 [1]. Not all the messages
defined in the specification are supported.

scmi_msg_get_rd_handler() sanitizes the message_id value
against any speculative use of reset domain ID as a index since by
SCMI specification, IDs are indices.

This implementation is based on the OP-TEE project implementation [2]
itself based on the SCP-firmware implementation [3] of the SCMI
protocol server side.

Link: [1] http://infocenter.arm.com/help/topic/com.arm.doc.den0056a/DEN0056A_System_Control_and_Management_Interface.pdf
Link: [2] https://github.com/OP-TEE/optee_os/commit/56a1f10ed99d683ee3a8af29b6147a59a99ef3e0
Link: [3] https://github.com/ARM-software/SCP-firmware.git



Change-Id: If7cf13de40a815dedb40dcd5af8b6bb6725d9078
Signed-off-by: default avatarEtienne Carriere <etienne.carriere@linaro.org>
parent c9e83000
......@@ -13,6 +13,7 @@
#include "base.h"
#include "clock.h"
#include "reset_domain.h"
#define SCMI_VERSION 0x20000U
#define SCMI_IMPL_VERSION 0U
......@@ -102,6 +103,13 @@ scmi_msg_handler_t scmi_msg_get_base_handler(struct scmi_msg *msg);
*/
scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg);
/*
* scmi_msg_get_rstd_handler - Return a handler for a reset domain message
* @msg - message to process
* Return a function handler for the message or NULL
*/
scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg);
/*
* Process Read, process and write response for input SCMI message
*
......
......@@ -44,6 +44,9 @@ void scmi_process_message(struct scmi_msg *msg)
case SCMI_PROTOCOL_ID_CLOCK:
handler = scmi_msg_get_clock_handler(msg);
break;
case SCMI_PROTOCOL_ID_RESET_DOMAIN:
handler = scmi_msg_get_rstd_handler(msg);
break;
default:
break;
}
......
// SPDX-License-Identifier: BSD-3-Clause
/*
* Copyright (c) 2015-2020, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2019-2020, Linaro Limited
*/
#include <cdefs.h>
#include <string.h>
#include <drivers/st/scmi-msg.h>
#include <drivers/st/scmi.h>
#include <lib/utils.h>
#include <lib/utils_def.h>
#include "common.h"
static bool message_id_is_supported(unsigned int message_id);
#pragma weak plat_scmi_rstd_count
#pragma weak plat_scmi_rstd_get_name
#pragma weak plat_scmi_rstd_autonomous
#pragma weak plat_scmi_rstd_set_state
size_t plat_scmi_rstd_count(unsigned int agent_id __unused)
{
return 0U;
}
const char *plat_scmi_rstd_get_name(unsigned int agent_id __unused,
unsigned int scmi_id __unused)
{
return NULL;
}
int32_t plat_scmi_rstd_autonomous(unsigned int agent_id __unused,
unsigned int scmi_id __unused,
unsigned int state __unused)
{
return SCMI_NOT_SUPPORTED;
}
int32_t plat_scmi_rstd_set_state(unsigned int agent_id __unused,
unsigned int scmi_id __unused,
bool assert_not_deassert __unused)
{
return SCMI_NOT_SUPPORTED;
}
static void report_version(struct scmi_msg *msg)
{
struct scmi_protocol_version_p2a return_values = {
.status = SCMI_SUCCESS,
.version = SCMI_PROTOCOL_VERSION_RESET_DOMAIN,
};
if (msg->in_size != 0U) {
scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
return;
}
scmi_write_response(msg, &return_values, sizeof(return_values));
}
static void report_attributes(struct scmi_msg *msg)
{
struct scmi_protocol_attributes_p2a return_values = {
.status = SCMI_SUCCESS,
.attributes = plat_scmi_rstd_count(msg->agent_id),
};
if (msg->in_size != 0U) {
scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
return;
}
scmi_write_response(msg, &return_values, sizeof(return_values));
}
static void report_message_attributes(struct scmi_msg *msg)
{
struct scmi_protocol_message_attributes_a2p *in_args = (void *)msg->in;
struct scmi_protocol_message_attributes_p2a return_values = {
.status = SCMI_SUCCESS,
/* For this protocol, attributes shall be zero */
.attributes = 0U,
};
if (msg->in_size != sizeof(*in_args)) {
scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
return;
}
if (!message_id_is_supported(in_args->message_id)) {
scmi_status_response(msg, SCMI_NOT_FOUND);
return;
}
scmi_write_response(msg, &return_values, sizeof(return_values));
}
static void reset_domain_attributes(struct scmi_msg *msg)
{
struct scmi_reset_domain_attributes_a2p *in_args = (void *)msg->in;
struct scmi_reset_domain_attributes_p2a return_values;
const char *name = NULL;
unsigned int domain_id = 0U;
if (msg->in_size != sizeof(*in_args)) {
scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
return;
}
domain_id = SPECULATION_SAFE_VALUE(in_args->domain_id);
if (domain_id >= plat_scmi_rstd_count(msg->agent_id)) {
scmi_status_response(msg, SCMI_INVALID_PARAMETERS);
return;
}
name = plat_scmi_rstd_get_name(msg->agent_id, domain_id);
if (name == NULL) {
scmi_status_response(msg, SCMI_NOT_FOUND);
return;
}
zeromem(&return_values, sizeof(return_values));
COPY_NAME_IDENTIFIER(return_values.name, name);
return_values.status = SCMI_SUCCESS;
return_values.flags = 0U; /* Async and Notif are not supported */
return_values.latency = SCMI_RESET_DOMAIN_ATTR_UNK_LAT;
scmi_write_response(msg, &return_values, sizeof(return_values));
}
static void reset_request(struct scmi_msg *msg)
{
struct scmi_reset_domain_request_a2p *in_args = (void *)msg->in;
struct scmi_reset_domain_request_p2a out_args = {
.status = SCMI_SUCCESS,
};
unsigned int domain_id = 0U;
if (msg->in_size != sizeof(*in_args)) {
scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
return;
}
domain_id = SPECULATION_SAFE_VALUE(in_args->domain_id);
if (domain_id >= plat_scmi_rstd_count(msg->agent_id)) {
scmi_status_response(msg, SCMI_NOT_FOUND);
return;
}
if ((in_args->flags & SCMI_RESET_DOMAIN_AUTO) != 0U) {
out_args.status = plat_scmi_rstd_autonomous(msg->agent_id,
domain_id,
in_args->reset_state);
} else if ((in_args->flags & SCMI_RESET_DOMAIN_EXPLICIT) != 0U) {
out_args.status = plat_scmi_rstd_set_state(msg->agent_id,
domain_id, true);
} else {
out_args.status = plat_scmi_rstd_set_state(msg->agent_id,
domain_id, false);
}
if (out_args.status != SCMI_SUCCESS) {
scmi_status_response(msg, out_args.status);
} else {
scmi_write_response(msg, &out_args, sizeof(out_args));
}
}
static const scmi_msg_handler_t scmi_rstd_handler_table[] = {
[SCMI_PROTOCOL_VERSION] = report_version,
[SCMI_PROTOCOL_ATTRIBUTES] = report_attributes,
[SCMI_PROTOCOL_MESSAGE_ATTRIBUTES] = report_message_attributes,
[SCMI_RESET_DOMAIN_ATTRIBUTES] = reset_domain_attributes,
[SCMI_RESET_DOMAIN_REQUEST] = reset_request,
};
static bool message_id_is_supported(unsigned int message_id)
{
return (message_id < ARRAY_SIZE(scmi_rstd_handler_table)) &&
(scmi_rstd_handler_table[message_id] != NULL);
}
scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg)
{
unsigned int message_id = SPECULATION_SAFE_VALUE(msg->message_id);
if (message_id >= ARRAY_SIZE(scmi_rstd_handler_table)) {
VERBOSE("Reset domain handle not found %u\n", msg->message_id);
return NULL;
}
return scmi_rstd_handler_table[message_id];
}
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2019, Linaro Limited
*/
#ifndef SCMI_MSG_RESET_DOMAIN_H
#define SCMI_MSG_RESET_DOMAIN_H
#include <stdbool.h>
#include <stdint.h>
#include <lib/utils_def.h>
#define SCMI_PROTOCOL_VERSION_RESET_DOMAIN 0x10000U
#define SCMI_RESET_STATE_ARCH BIT(31)
#define SCMI_RESET_STATE_IMPL 0U
/*
* Identifiers of the SCMI Reset Domain Management Protocol commands
*/
enum scmi_reset_domain_command_id {
SCMI_RESET_DOMAIN_ATTRIBUTES = 0x03,
SCMI_RESET_DOMAIN_REQUEST = 0x04,
SCMI_RESET_DOMAIN_NOTIFY = 0x05,
};
/*
* Identifiers of the SCMI Reset Domain Management Protocol responses
*/
enum scmi_reset_domain_response_id {
SCMI_RESET_ISSUED = 0x00,
SCMI_RESET_COMPLETE = 0x04,
};
/*
* PROTOCOL_ATTRIBUTES
*/
#define SCMI_RESET_DOMAIN_COUNT_MASK GENMASK_32(15, 0)
struct scmi_reset_domain_protocol_attributes_p2a {
int32_t status;
uint32_t attributes;
};
/* Value for scmi_reset_domain_attributes_p2a:flags */
#define SCMI_RESET_DOMAIN_ATTR_ASYNC BIT(31)
#define SCMI_RESET_DOMAIN_ATTR_NOTIF BIT(30)
/* Value for scmi_reset_domain_attributes_p2a:latency */
#define SCMI_RESET_DOMAIN_ATTR_UNK_LAT 0x7fffffffU
#define SCMI_RESET_DOMAIN_ATTR_MAX_LAT 0x7ffffffeU
/* Macro for scmi_reset_domain_attributes_p2a:name */
#define SCMI_RESET_DOMAIN_ATTR_NAME_SZ 16U
struct scmi_reset_domain_attributes_a2p {
uint32_t domain_id;
};
struct scmi_reset_domain_attributes_p2a {
int32_t status;
uint32_t flags;
uint32_t latency;
char name[SCMI_RESET_DOMAIN_ATTR_NAME_SZ];
};
/*
* RESET
*/
/* Values for scmi_reset_domain_request_a2p:flags */
#define SCMI_RESET_DOMAIN_ASYNC BIT(2)
#define SCMI_RESET_DOMAIN_EXPLICIT BIT(1)
#define SCMI_RESET_DOMAIN_AUTO BIT(0)
struct scmi_reset_domain_request_a2p {
uint32_t domain_id;
uint32_t flags;
uint32_t reset_state;
};
struct scmi_reset_domain_request_p2a {
int32_t status;
};
/*
* RESET_NOTIFY
*/
/* Values for scmi_reset_notify_p2a:flags */
#define SCMI_RESET_DOMAIN_DO_NOTIFY BIT(0)
struct scmi_reset_domain_notify_a2p {
uint32_t domain_id;
uint32_t notify_enable;
};
struct scmi_reset_domain_notify_p2a {
int32_t status;
};
/*
* RESET_COMPLETE
*/
struct scmi_reset_domain_complete_p2a {
int32_t status;
uint32_t domain_id;
};
/*
* RESET_ISSUED
*/
struct scmi_reset_domain_issued_p2a {
uint32_t domain_id;
uint32_t reset_state;
};
#endif /* SCMI_MSG_RESET_DOMAIN_H */
......@@ -141,4 +141,41 @@ int32_t plat_scmi_clock_get_state(unsigned int agent_id, unsigned int scmi_id);
int32_t plat_scmi_clock_set_state(unsigned int agent_id, unsigned int scmi_id,
bool enable_not_disable);
/* Handlers for SCMI Reset Domain protocol services */
/*
* Return number of reset domains for the agent
* @agent_id: SCMI agent ID
* Return number of reset domains
*/
size_t plat_scmi_rstd_count(unsigned int agent_id);
/*
* Get reset domain string ID (aka name)
* @agent_id: SCMI agent ID
* @scmi_id: SCMI reset domain ID
* Return pointer to name or NULL
*/
const char *plat_scmi_rstd_get_name(unsigned int agent_id, unsigned int scmi_id);
/*
* Perform a reset cycle on a target reset domain
* @agent_id: SCMI agent ID
* @scmi_id: SCMI reset domain ID
* @state: Target reset state (see SCMI specification, 0 means context loss)
* Return a compliant SCMI error code
*/
int32_t plat_scmi_rstd_autonomous(unsigned int agent_id, unsigned int scmi_id,
unsigned int state);
/*
* Assert or deassert target reset domain
* @agent_id: SCMI agent ID
* @scmi_id: SCMI reset domain ID
* @assert_not_deassert: Assert domain if true, otherwise deassert domain
* Return a compliant SCMI error code
*/
int32_t plat_scmi_rstd_set_state(unsigned int agent_id, unsigned int scmi_id,
bool assert_not_deassert);
#endif /* SCMI_MSG_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment