arm-trusted-firmware/drivers/scmi-msg/common.h

145 lines
4.1 KiB
C
Raw Normal View History

drivers/scmi-msg: driver for processing scmi messages This change introduces drivers to allow a platform to create a basic SCMI service and register handlers for client request (SCMI agent) on system resources. This is the first piece of the drivers: an entry function, the SCMI base protocol support and helpers for create the response message. With this change, scmi_process_message() is the entry function to process an incoming SCMI message. The function expect the message is already copied from shared memory into secure memory. The message structure stores message reference and output buffer reference where response message shall be stored. scmi_process_message() calls the SCMI protocol driver according to the protocol ID in the message. The SCMI protocol driver will call defined platform handlers according to the message content. This change introduces only the SCMI base protocol as defined in SCMI specification v2.0 [1]. Not all the messages defined in the specification are supported. The SCMI message implementation is derived from the OP-TEE project [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/ae8c8068098d291e6e55744dbc237ec39fd9840a Link: [3] https://github.com/ARM-software/SCP-firmware/tree/v2.6.0 Change-Id: I639c4154a39fca60606264baf8d32452641f45e9 Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
2019-11-28 08:13:34 +00:00
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2019-2020, Linaro Limited
*/
#ifndef SCMI_MSG_COMMON_H
#define SCMI_MSG_COMMON_H
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "base.h"
#include "clock.h"
#include "power_domain.h"
#include "reset_domain.h"
drivers/scmi-msg: driver for processing scmi messages This change introduces drivers to allow a platform to create a basic SCMI service and register handlers for client request (SCMI agent) on system resources. This is the first piece of the drivers: an entry function, the SCMI base protocol support and helpers for create the response message. With this change, scmi_process_message() is the entry function to process an incoming SCMI message. The function expect the message is already copied from shared memory into secure memory. The message structure stores message reference and output buffer reference where response message shall be stored. scmi_process_message() calls the SCMI protocol driver according to the protocol ID in the message. The SCMI protocol driver will call defined platform handlers according to the message content. This change introduces only the SCMI base protocol as defined in SCMI specification v2.0 [1]. Not all the messages defined in the specification are supported. The SCMI message implementation is derived from the OP-TEE project [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/ae8c8068098d291e6e55744dbc237ec39fd9840a Link: [3] https://github.com/ARM-software/SCP-firmware/tree/v2.6.0 Change-Id: I639c4154a39fca60606264baf8d32452641f45e9 Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
2019-11-28 08:13:34 +00:00
#define SCMI_VERSION 0x20000U
#define SCMI_IMPL_VERSION 0U
#define SCMI_PLAYLOAD_MAX 92U
/*
* Copy name identifier in target buffer following the SCMI specification
* that state name identifier shall be a null terminated string.
*/
#define COPY_NAME_IDENTIFIER(_dst_array, _name) \
do { \
assert(strlen(_name) < sizeof(_dst_array)); \
strlcpy((_dst_array), (_name), sizeof(_dst_array)); \
} while (0)
/* Common command identifiers shared by all procotols */
enum scmi_common_message_id {
SCMI_PROTOCOL_VERSION = 0x000,
SCMI_PROTOCOL_ATTRIBUTES = 0x001,
SCMI_PROTOCOL_MESSAGE_ATTRIBUTES = 0x002
};
/* Common platform-to-agent (p2a) PROTOCOL_VERSION structure */
struct scmi_protocol_version_p2a {
int32_t status;
uint32_t version;
};
/* Generic platform-to-agent (p2a) PROTOCOL_ATTRIBUTES structure */
struct scmi_protocol_attributes_p2a {
int32_t status;
uint32_t attributes;
};
/* Generic agent-to-platform (a2p) PROTOCOL_MESSAGE_ATTRIBUTES structure */
struct scmi_protocol_message_attributes_a2p {
uint32_t message_id;
};
/* Generic platform-to-agent (p2a) PROTOCOL_MESSAGE_ATTRIBUTES structure */
struct scmi_protocol_message_attributes_p2a {
int32_t status;
uint32_t attributes;
};
/*
* struct scmi_msg - SCMI message context
*
* @agent_id: SCMI agent ID, safely set from secure world
* @protocol_id: SCMI protocol ID for the related message, set by caller agent
* @message_id: SCMI message ID for the related message, set by caller agent
* @in: Address of the incoming message payload copied in secure memory
* @in_size: Byte length of the incoming message payload, set by caller agent
* @out: Address of of the output message payload message in non-secure memory
* @out_size: Byte length of the provisionned output buffer
* @out_size_out: Byte length of the output message payload
*/
struct scmi_msg {
unsigned int agent_id;
unsigned int protocol_id;
unsigned int message_id;
char *in;
size_t in_size;
char *out;
size_t out_size;
size_t out_size_out;
};
/*
* Type scmi_msg_handler_t is used by procotol drivers to safely find
* the handler function for the incoming message ID.
*/
typedef void (*scmi_msg_handler_t)(struct scmi_msg *msg);
/*
* scmi_msg_get_base_handler - Return a handler for a base message
* @msg - message to process
* Return a function handler for the message or NULL
*/
scmi_msg_handler_t scmi_msg_get_base_handler(struct scmi_msg *msg);
/*
* scmi_msg_get_clock_handler - Return a handler for a clock message
* @msg - message to process
* Return a function handler for the message or NULL
*/
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);
/*
* scmi_msg_get_pd_handler - Return a handler for a power domain message
* @msg - message to process
* Return a function handler for the message or NULL
*/
scmi_msg_handler_t scmi_msg_get_pd_handler(struct scmi_msg *msg);
drivers/scmi-msg: driver for processing scmi messages This change introduces drivers to allow a platform to create a basic SCMI service and register handlers for client request (SCMI agent) on system resources. This is the first piece of the drivers: an entry function, the SCMI base protocol support and helpers for create the response message. With this change, scmi_process_message() is the entry function to process an incoming SCMI message. The function expect the message is already copied from shared memory into secure memory. The message structure stores message reference and output buffer reference where response message shall be stored. scmi_process_message() calls the SCMI protocol driver according to the protocol ID in the message. The SCMI protocol driver will call defined platform handlers according to the message content. This change introduces only the SCMI base protocol as defined in SCMI specification v2.0 [1]. Not all the messages defined in the specification are supported. The SCMI message implementation is derived from the OP-TEE project [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/ae8c8068098d291e6e55744dbc237ec39fd9840a Link: [3] https://github.com/ARM-software/SCP-firmware/tree/v2.6.0 Change-Id: I639c4154a39fca60606264baf8d32452641f45e9 Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
2019-11-28 08:13:34 +00:00
/*
* Process Read, process and write response for input SCMI message
*
* @msg: SCMI message context
*/
void scmi_process_message(struct scmi_msg *msg);
/*
* Write SCMI response payload to output message shared memory
*
* @msg: SCMI message context
* @payload: Output message payload
* @size: Byte size of output message payload
*/
void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size);
/*
* Write status only SCMI response payload to output message shared memory
*
* @msg: SCMI message context
* @status: SCMI status value returned to caller
*/
void scmi_status_response(struct scmi_msg *msg, int32_t status);
#endif /* SCMI_MSG_COMMON_H */