mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-18 18:59:44 +00:00
358599efd8
This change introduces SCMI agent uclass to interact with a firmware using the SCMI protocols [1]. SCMI agent uclass currently supports a single method to request processing of the SCMI message by an identified server. A SCMI message is made of a byte payload associated to a protocol ID and a message ID, all defined by the SCMI specification [1]. On return from process_msg() method, the caller gets the service response. SCMI agent uclass defines a post bind generic sequence for all devices. The sequence binds all the SCMI protocols listed in the FDT for that SCMI agent device. Currently none, but later change will introduce protocols. This change implements a simple sandbox device for the SCMI agent uclass. The sandbox nicely answers SCMI_NOT_SUPPORTED to SCMI messages. To prepare for further test support, the sandbox exposes a architecture function for test application to read the sandbox emulated devices state. Currently supports 2 SCMI agents, identified by an ID in the FDT device name. The simplistic DM test does nothing yet. SCMI agent uclass is designed for platforms that embed a SCMI server in a firmware hosted somewhere, for example in a companion co-processor or in the secure world of the executing processor. SCMI protocols allow an SCMI agent to discover and access external resources as clock, reset controllers and more. SCMI agent and server communicate following the SCMI specification [1]. This SCMI agent implementation complies with the DT bindings defined in the Linux kernel source tree regarding SCMI agent description since v5.8. Links: [1] https://developer.arm.com/architectures/system-architectures/software-standards/scmi Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org> Cc: Simon Glass <sjg@chromium.org> Cc: Peng Fan <peng.fan@nxp.com> Cc: Sudeep Holla <sudeep.holla@arm.com> Reviewed-by: Simon Glass <sjg@chromium.org>
142 lines
3.7 KiB
C
142 lines
3.7 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright (C) 2020, Linaro Limited
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <dm.h>
|
|
#include <malloc.h>
|
|
#include <scmi_agent.h>
|
|
#include <scmi_agent-uclass.h>
|
|
#include <scmi_protocols.h>
|
|
#include <asm/io.h>
|
|
#include <asm/scmi_test.h>
|
|
#include <dm/device_compat.h>
|
|
|
|
/*
|
|
* The sandbox SCMI agent driver simulates to some extend a SCMI message
|
|
* processing. It simulates few of the SCMI services for some of the
|
|
* SCMI protocols embedded in U-Boot. Currently none.
|
|
*
|
|
* This driver simulates 2 SCMI agents for test purpose.
|
|
*
|
|
* This Driver exports sandbox_scmi_service_ct() for the test sequence to
|
|
* get the state of the simulated services (clock state, rate, ...) and
|
|
* check back-end device state reflects the request send through the
|
|
* various uclass devices, currently nothing.
|
|
*/
|
|
|
|
#define SANDBOX_SCMI_AGENT_COUNT 2
|
|
|
|
/* The list saves to simulted end devices references for test purpose */
|
|
struct sandbox_scmi_agent *sandbox_scmi_agent_list[SANDBOX_SCMI_AGENT_COUNT];
|
|
|
|
static struct sandbox_scmi_service sandbox_scmi_service_state = {
|
|
.agent = sandbox_scmi_agent_list,
|
|
.agent_count = SANDBOX_SCMI_AGENT_COUNT,
|
|
};
|
|
|
|
struct sandbox_scmi_service *sandbox_scmi_service_ctx(void)
|
|
{
|
|
return &sandbox_scmi_service_state;
|
|
}
|
|
|
|
static void debug_print_agent_state(struct udevice *dev, char *str)
|
|
{
|
|
struct sandbox_scmi_agent *agent = dev_get_priv(dev);
|
|
|
|
dev_dbg(dev, "Dump sandbox_scmi_agent %u: %s\n", agent->idx, str);
|
|
};
|
|
|
|
static int sandbox_scmi_test_process_msg(struct udevice *dev,
|
|
struct scmi_msg *msg)
|
|
{
|
|
switch (msg->protocol_id) {
|
|
case SCMI_PROTOCOL_ID_BASE:
|
|
case SCMI_PROTOCOL_ID_POWER_DOMAIN:
|
|
case SCMI_PROTOCOL_ID_SYSTEM:
|
|
case SCMI_PROTOCOL_ID_PERF:
|
|
case SCMI_PROTOCOL_ID_CLOCK:
|
|
case SCMI_PROTOCOL_ID_SENSOR:
|
|
case SCMI_PROTOCOL_ID_RESET_DOMAIN:
|
|
*(u32 *)msg->out_msg = SCMI_NOT_SUPPORTED;
|
|
return 0;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
dev_err(dev, "%s(%s): Unhandled protocol_id %#x/message_id %#x\n",
|
|
__func__, dev->name, msg->protocol_id, msg->message_id);
|
|
|
|
if (msg->out_msg_sz < sizeof(u32))
|
|
return -EINVAL;
|
|
|
|
/* Intentionnaly report unhandled IDs through the SCMI return code */
|
|
*(u32 *)msg->out_msg = SCMI_PROTOCOL_ERROR;
|
|
return 0;
|
|
}
|
|
|
|
static int sandbox_scmi_test_remove(struct udevice *dev)
|
|
{
|
|
struct sandbox_scmi_agent *agent = dev_get_priv(dev);
|
|
|
|
debug_print_agent_state(dev, "removed");
|
|
|
|
/* We only need to dereference the agent in the context */
|
|
sandbox_scmi_service_ctx()->agent[agent->idx] = NULL;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int sandbox_scmi_test_probe(struct udevice *dev)
|
|
{
|
|
static const char basename[] = "sandbox-scmi-agent@";
|
|
struct sandbox_scmi_agent *agent = dev_get_priv(dev);
|
|
const size_t basename_size = sizeof(basename) - 1;
|
|
|
|
if (strncmp(basename, dev->name, basename_size))
|
|
return -ENOENT;
|
|
|
|
switch (dev->name[basename_size]) {
|
|
case '0':
|
|
*agent = (struct sandbox_scmi_agent){
|
|
.idx = 0,
|
|
};
|
|
break;
|
|
case '1':
|
|
*agent = (struct sandbox_scmi_agent){
|
|
.idx = 1,
|
|
};
|
|
break;
|
|
default:
|
|
dev_err(dev, "%s(): Unexpected agent ID %s\n",
|
|
__func__, dev->name + basename_size);
|
|
return -ENOENT;
|
|
}
|
|
|
|
debug_print_agent_state(dev, "probed");
|
|
|
|
/* Save reference for tests purpose */
|
|
sandbox_scmi_service_ctx()->agent[agent->idx] = agent;
|
|
|
|
return 0;
|
|
};
|
|
|
|
static const struct udevice_id sandbox_scmi_test_ids[] = {
|
|
{ .compatible = "sandbox,scmi-agent" },
|
|
{ }
|
|
};
|
|
|
|
struct scmi_agent_ops sandbox_scmi_test_ops = {
|
|
.process_msg = sandbox_scmi_test_process_msg,
|
|
};
|
|
|
|
U_BOOT_DRIVER(sandbox_scmi_agent) = {
|
|
.name = "sandbox-scmi_agent",
|
|
.id = UCLASS_SCMI_AGENT,
|
|
.of_match = sandbox_scmi_test_ids,
|
|
.priv_auto_alloc_size = sizeof(struct sandbox_scmi_agent),
|
|
.probe = sandbox_scmi_test_probe,
|
|
.remove = sandbox_scmi_test_remove,
|
|
.ops = &sandbox_scmi_test_ops,
|
|
};
|