blob: 5e166ca93ee1f4dd332f623800e2278a826b715b [file] [log] [blame]
Etienne Carrierea26d0ec2020-09-09 18:44:02 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020 Linaro Limited.
4 */
5
Patrick Delaunay5dd84d42021-02-24 11:19:44 +01006#define LOG_CATEGORY UCLASS_SCMI_AGENT
7
Etienne Carrierea26d0ec2020-09-09 18:44:02 +02008#include <common.h>
9#include <dm.h>
10#include <errno.h>
11#include <scmi_agent.h>
12#include <scmi_agent-uclass.h>
13#include <dm/devres.h>
Patrick Delaunay2f7d3a12021-02-24 11:19:43 +010014#include <dm/device_compat.h>
Etienne Carrierea26d0ec2020-09-09 18:44:02 +020015#include <dm/device-internal.h>
16#include <linux/arm-smccc.h>
17#include <linux/compat.h>
18
19#include "smt.h"
20
21#define SMCCC_RET_NOT_SUPPORTED ((unsigned long)-1)
22
23/**
24 * struct scmi_smccc_channel - Description of an SCMI SMCCC transport
25 * @func_id: SMCCC function ID used by the SCMI transport
26 * @smt: Shared memory buffer
27 */
28struct scmi_smccc_channel {
29 ulong func_id;
30 struct scmi_smt smt;
31};
32
33static int scmi_smccc_process_msg(struct udevice *dev, struct scmi_msg *msg)
34{
Etienne Carriere213d5cf2021-11-08 08:56:10 +010035 struct scmi_smccc_channel *chan = dev_get_plat(dev);
Etienne Carrierea26d0ec2020-09-09 18:44:02 +020036 struct arm_smccc_res res;
37 int ret;
38
39 ret = scmi_write_msg_to_smt(dev, &chan->smt, msg);
40 if (ret)
41 return ret;
42
43 arm_smccc_smc(chan->func_id, 0, 0, 0, 0, 0, 0, 0, &res);
44 if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
45 ret = -ENXIO;
46 else
47 ret = scmi_read_resp_from_smt(dev, &chan->smt, msg);
48
49 scmi_clear_smt_channel(&chan->smt);
50
51 return ret;
52}
53
Etienne Carriere213d5cf2021-11-08 08:56:10 +010054static int scmi_smccc_of_to_plat(struct udevice *dev)
Etienne Carrierea26d0ec2020-09-09 18:44:02 +020055{
Etienne Carriere213d5cf2021-11-08 08:56:10 +010056 struct scmi_smccc_channel *chan = dev_get_plat(dev);
Etienne Carrierea26d0ec2020-09-09 18:44:02 +020057 u32 func_id;
58 int ret;
59
60 if (dev_read_u32(dev, "arm,smc-id", &func_id)) {
61 dev_err(dev, "Missing property func-id\n");
62 return -EINVAL;
63 }
64
65 chan->func_id = func_id;
66
67 ret = scmi_dt_get_smt_buffer(dev, &chan->smt);
Etienne Carrieref6942352021-11-08 08:56:11 +010068 if (ret)
Etienne Carrierea26d0ec2020-09-09 18:44:02 +020069 dev_err(dev, "Failed to get smt resources: %d\n", ret);
Etienne Carrierea26d0ec2020-09-09 18:44:02 +020070
Etienne Carrieref6942352021-11-08 08:56:11 +010071 return ret;
Etienne Carrierea26d0ec2020-09-09 18:44:02 +020072}
73
74static const struct udevice_id scmi_smccc_ids[] = {
75 { .compatible = "arm,scmi-smc" },
76 { }
77};
78
79static const struct scmi_agent_ops scmi_smccc_ops = {
80 .process_msg = scmi_smccc_process_msg,
81};
82
83U_BOOT_DRIVER(scmi_smccc) = {
84 .name = "scmi-over-smccc",
85 .id = UCLASS_SCMI_AGENT,
86 .of_match = scmi_smccc_ids,
Etienne Carriere213d5cf2021-11-08 08:56:10 +010087 .plat_auto = sizeof(struct scmi_smccc_channel),
88 .of_to_plat = scmi_smccc_of_to_plat,
Etienne Carrierea26d0ec2020-09-09 18:44:02 +020089 .ops = &scmi_smccc_ops,
90};