blob: 85dbf9195e04608fd3a85e109f584e6da2506434 [file] [log] [blame]
Etienne Carriere1e359132020-09-09 18:44:02 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020 Linaro Limited.
4 */
5
6#include <common.h>
7#include <dm.h>
8#include <errno.h>
9#include <scmi_agent.h>
10#include <scmi_agent-uclass.h>
11#include <dm/devres.h>
12#include <dm/device-internal.h>
13#include <linux/arm-smccc.h>
14#include <linux/compat.h>
15
16#include "smt.h"
17
18#define SMCCC_RET_NOT_SUPPORTED ((unsigned long)-1)
19
20/**
21 * struct scmi_smccc_channel - Description of an SCMI SMCCC transport
22 * @func_id: SMCCC function ID used by the SCMI transport
23 * @smt: Shared memory buffer
24 */
25struct scmi_smccc_channel {
26 ulong func_id;
27 struct scmi_smt smt;
28};
29
30static int scmi_smccc_process_msg(struct udevice *dev, struct scmi_msg *msg)
31{
32 struct scmi_smccc_channel *chan = dev_get_priv(dev);
33 struct arm_smccc_res res;
34 int ret;
35
36 ret = scmi_write_msg_to_smt(dev, &chan->smt, msg);
37 if (ret)
38 return ret;
39
40 arm_smccc_smc(chan->func_id, 0, 0, 0, 0, 0, 0, 0, &res);
41 if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
42 ret = -ENXIO;
43 else
44 ret = scmi_read_resp_from_smt(dev, &chan->smt, msg);
45
46 scmi_clear_smt_channel(&chan->smt);
47
48 return ret;
49}
50
51static int scmi_smccc_probe(struct udevice *dev)
52{
53 struct scmi_smccc_channel *chan = dev_get_priv(dev);
54 u32 func_id;
55 int ret;
56
57 if (dev_read_u32(dev, "arm,smc-id", &func_id)) {
58 dev_err(dev, "Missing property func-id\n");
59 return -EINVAL;
60 }
61
62 chan->func_id = func_id;
63
64 ret = scmi_dt_get_smt_buffer(dev, &chan->smt);
65 if (ret) {
66 dev_err(dev, "Failed to get smt resources: %d\n", ret);
67 return ret;
68 }
69
70 return 0;
71}
72
73static const struct udevice_id scmi_smccc_ids[] = {
74 { .compatible = "arm,scmi-smc" },
75 { }
76};
77
78static const struct scmi_agent_ops scmi_smccc_ops = {
79 .process_msg = scmi_smccc_process_msg,
80};
81
82U_BOOT_DRIVER(scmi_smccc) = {
83 .name = "scmi-over-smccc",
84 .id = UCLASS_SCMI_AGENT,
85 .of_match = scmi_smccc_ids,
86 .priv_auto_alloc_size = sizeof(struct scmi_smccc_channel),
87 .probe = scmi_smccc_probe,
88 .ops = &scmi_smccc_ops,
89};