2020-09-09 16:44:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Linaro Limited.
|
|
|
|
*/
|
|
|
|
|
2021-02-24 10:19:44 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_SCMI_AGENT
|
|
|
|
|
2020-09-09 16:44:02 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <scmi_agent.h>
|
|
|
|
#include <scmi_agent-uclass.h>
|
|
|
|
#include <dm/devres.h>
|
2021-02-24 10:19:43 +00:00
|
|
|
#include <dm/device_compat.h>
|
2020-09-09 16:44:02 +00:00
|
|
|
#include <dm/device-internal.h>
|
|
|
|
#include <linux/arm-smccc.h>
|
|
|
|
#include <linux/compat.h>
|
|
|
|
|
|
|
|
#include "smt.h"
|
|
|
|
|
|
|
|
#define SMCCC_RET_NOT_SUPPORTED ((unsigned long)-1)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct scmi_smccc_channel - Description of an SCMI SMCCC transport
|
|
|
|
* @func_id: SMCCC function ID used by the SCMI transport
|
|
|
|
* @smt: Shared memory buffer
|
|
|
|
*/
|
|
|
|
struct scmi_smccc_channel {
|
|
|
|
ulong func_id;
|
|
|
|
struct scmi_smt smt;
|
|
|
|
};
|
|
|
|
|
2022-05-31 16:09:23 +00:00
|
|
|
/**
|
|
|
|
* struct scmi_channel - Channel instance referenced in SCMI drivers
|
|
|
|
* @ref: Reference to local channel instance
|
|
|
|
**/
|
|
|
|
struct scmi_channel {
|
|
|
|
struct scmi_smccc_channel ref;
|
|
|
|
};
|
|
|
|
|
2022-05-31 16:09:19 +00:00
|
|
|
static int scmi_smccc_process_msg(struct udevice *dev,
|
|
|
|
struct scmi_channel *channel,
|
|
|
|
struct scmi_msg *msg)
|
2020-09-09 16:44:02 +00:00
|
|
|
{
|
2022-05-31 16:09:29 +00:00
|
|
|
struct scmi_smccc_channel *chan = &channel->ref;
|
2020-09-09 16:44:02 +00:00
|
|
|
struct arm_smccc_res res;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = scmi_write_msg_to_smt(dev, &chan->smt, msg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
arm_smccc_smc(chan->func_id, 0, 0, 0, 0, 0, 0, 0, &res);
|
|
|
|
if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
|
|
|
|
ret = -ENXIO;
|
|
|
|
else
|
|
|
|
ret = scmi_read_resp_from_smt(dev, &chan->smt, msg);
|
|
|
|
|
|
|
|
scmi_clear_smt_channel(&chan->smt);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-05-31 16:09:23 +00:00
|
|
|
static int setup_channel(struct udevice *dev, struct scmi_smccc_channel *chan)
|
2020-09-09 16:44:02 +00:00
|
|
|
{
|
|
|
|
u32 func_id;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (dev_read_u32(dev, "arm,smc-id", &func_id)) {
|
|
|
|
dev_err(dev, "Missing property func-id\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
chan->func_id = func_id;
|
|
|
|
|
|
|
|
ret = scmi_dt_get_smt_buffer(dev, &chan->smt);
|
2021-11-08 07:56:11 +00:00
|
|
|
if (ret)
|
2020-09-09 16:44:02 +00:00
|
|
|
dev_err(dev, "Failed to get smt resources: %d\n", ret);
|
|
|
|
|
2021-11-08 07:56:11 +00:00
|
|
|
return ret;
|
2020-09-09 16:44:02 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 16:09:23 +00:00
|
|
|
static int scmi_smccc_get_channel(struct udevice *dev,
|
|
|
|
struct scmi_channel **channel)
|
|
|
|
{
|
|
|
|
struct scmi_smccc_channel *base_chan = dev_get_plat(dev->parent);
|
|
|
|
struct scmi_smccc_channel *chan;
|
|
|
|
u32 func_id;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (dev_read_u32(dev, "arm,smc-id", &func_id)) {
|
|
|
|
/* Uses agent base channel */
|
|
|
|
*channel = container_of(base_chan, struct scmi_channel, ref);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup a dedicated channel */
|
|
|
|
chan = calloc(1, sizeof(*chan));
|
|
|
|
if (!chan)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = setup_channel(dev, chan);
|
|
|
|
if (ret) {
|
|
|
|
free(chan);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
*channel = container_of(chan, struct scmi_channel, ref);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int scmi_smccc_of_to_plat(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct scmi_smccc_channel *chan = dev_get_plat(dev);
|
|
|
|
|
|
|
|
return setup_channel(dev, chan);
|
|
|
|
}
|
|
|
|
|
2020-09-09 16:44:02 +00:00
|
|
|
static const struct udevice_id scmi_smccc_ids[] = {
|
|
|
|
{ .compatible = "arm,scmi-smc" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct scmi_agent_ops scmi_smccc_ops = {
|
2022-05-31 16:09:23 +00:00
|
|
|
.of_get_channel = scmi_smccc_get_channel,
|
2020-09-09 16:44:02 +00:00
|
|
|
.process_msg = scmi_smccc_process_msg,
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(scmi_smccc) = {
|
|
|
|
.name = "scmi-over-smccc",
|
|
|
|
.id = UCLASS_SCMI_AGENT,
|
|
|
|
.of_match = scmi_smccc_ids,
|
2021-11-08 07:56:10 +00:00
|
|
|
.plat_auto = sizeof(struct scmi_smccc_channel),
|
|
|
|
.of_to_plat = scmi_smccc_of_to_plat,
|
2020-09-09 16:44:02 +00:00
|
|
|
.ops = &scmi_smccc_ops,
|
|
|
|
};
|