Skip to content

Commit

Permalink
drivers/scmi-msg: support for reset domain protocol
Browse files Browse the repository at this point in the history
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.

Embedded upon CFG_SCMI_MSG_RESET_DOMAIN=y.

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.

SCMI resource in this implementation are dumped or inspired by the
SCP-firmware implementation [2] 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/ARM-software/SCP-firmware.git

Signed-off-by: Etienne Carriere <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
  • Loading branch information
etienne-lms authored and jforissier committed Apr 3, 2020
1 parent a7a9e3b commit 56a1f10
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/drivers/scmi-msg/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "base.h"
#include "clock.h"
#include "reset_domain.h"

#define SCMI_VERSION 0x20000
#define SCMI_IMPL_VERSION 0
Expand Down Expand Up @@ -105,6 +106,15 @@ 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);
#endif

#ifdef CFG_SCMI_MSG_RESET_DOMAIN
/*
* scmi_msg_get_rd_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_rd_handler(struct scmi_msg *msg);
#endif

/*
* Process Read, process and write response for input SCMI message
*
Expand Down
6 changes: 6 additions & 0 deletions core/drivers/scmi-msg/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base.h"
#include "clock.h"
#include "common.h"
#include "reset_domain.h"

void scmi_status_response(struct scmi_msg *msg, int32_t status)
{
Expand Down Expand Up @@ -46,6 +47,11 @@ void scmi_process_message(struct scmi_msg *msg)
case SCMI_PROTOCOL_ID_CLOCK:
handler = scmi_msg_get_clock_handler(msg);
break;
#endif
#ifdef CFG_SCMI_MSG_RESET_DOMAIN
case SCMI_PROTOCOL_ID_RESET_DOMAIN:
handler = scmi_msg_get_rd_handler(msg);
break;
#endif
default:
break;
Expand Down
194 changes: 194 additions & 0 deletions core/drivers/scmi-msg/reset_domain.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
// SPDX-License-Identifier: BSD-3-Clause
/*
* Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2019, Linaro Limited
*/
#include <assert.h>
#include <confine_array_index.h>
#include <drivers/scmi-msg.h>
#include <drivers/scmi.h>
#include <string.h>
#include <util.h>

#include "common.h"
#include "reset_domain.h"

static bool message_id_is_supported(unsigned int message_id);

size_t __weak plat_scmi_rd_count(unsigned int agent_id __unused)
{
return 0;
}

const char __weak *plat_scmi_rd_get_name(unsigned int agent_id __unused,
unsigned int scmi_id __unused)
{
return NULL;
}

int32_t __weak plat_scmi_rd_autonomous(unsigned int agent_id __unused,
unsigned int scmi_id __unused,
unsigned int state __unused)
{
return SCMI_NOT_SUPPORTED;
}

int32_t __weak plat_scmi_rd_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) {
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_rd_count(msg->agent_id),
};

if (msg->in_size) {
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 = 0,
};

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 = 0;

if (msg->in_size != sizeof(*in_args)) {
scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
return;
}

if (in_args->domain_id >= plat_scmi_rd_count(msg->agent_id)) {
scmi_status_response(msg, SCMI_INVALID_PARAMETERS);
return;
}

domain_id = confine_array_index(in_args->domain_id,
plat_scmi_rd_count(msg->agent_id));

name = plat_scmi_rd_get_name(msg->agent_id, domain_id);
if (!name) {
scmi_status_response(msg, SCMI_NOT_FOUND);
return;
}

COPY_NAME_IDENTIFIER(return_values.name, name);
return_values.status = SCMI_SUCCESS;
return_values.flags = 0; /* 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 = 0;

domain_id = confine_array_index(in_args->domain_id,
plat_scmi_rd_count(msg->agent_id));

if (msg->in_size != sizeof(*in_args)) {
scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
return;
}

if (in_args->domain_id >= plat_scmi_rd_count(msg->agent_id)) {
scmi_status_response(msg, SCMI_INVALID_PARAMETERS);
return;
}

if (in_args->flags & SCMI_RESET_DOMAIN_AUTO)
out_args.status = plat_scmi_rd_autonomous(msg->agent_id,
domain_id,
in_args->reset_state);
else if (in_args->flags & SCMI_RESET_DOMAIN_EXPLICIT)
out_args.status = plat_scmi_rd_set_state(msg->agent_id,
domain_id, true);
else
out_args.status = plat_scmi_rd_set_state(msg->agent_id,
domain_id, false);

if (out_args.status)
scmi_status_response(msg, out_args.status);
else
scmi_write_response(msg, &out_args, sizeof(out_args));
}

static const scmi_msg_handler_t scmi_rd_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_rd_handler_table) &&
scmi_rd_handler_table[message_id];
}

scmi_msg_handler_t scmi_msg_get_rd_handler(struct scmi_msg *msg)
{
const size_t array_size = ARRAY_SIZE(scmi_rd_handler_table);
unsigned int message_id = 0;

if (msg->message_id >= array_size) {
DMSG("Reset domain handle not found %u", msg->message_id);
return NULL;
}

message_id = confine_array_index(msg->message_id, array_size);

return scmi_rd_handler_table[message_id];
}
123 changes: 123 additions & 0 deletions core/drivers/scmi-msg/reset_domain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/* SPDX-License-Identifier: BSD-2-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 <compiler.h>
#include <stdbool.h>
#include <stdint.h>
#include <types_ext.h>
#include <util.h>

#define SCMI_PROTOCOL_VERSION_RESET_DOMAIN 0x10000

#define SCMI_RESET_STATE_ARCH BIT(31)
#define SCMI_RESET_STATE_IMPL 0

/*
* 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 0x7fffffff
#define SCMI_RESET_DOMAIN_ATTR_MAX_LAT 0x7ffffffe

/* Macro for scmi_reset_domain_attributes_p2a:name */
#define SCMI_RESET_DOMAIN_ATTR_NAME_SZ 16

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 */
1 change: 1 addition & 0 deletions core/drivers/scmi-msg/sub.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
srcs-y += base.c
srcs-$(CFG_SCMI_MSG_CLOCK) += clock.c
srcs-y += entry.c
srcs-$(CFG_SCMI_MSG_RESET_DOMAIN) += reset_domain.c
Loading

0 comments on commit 56a1f10

Please sign in to comment.