blob: 81c2884bb7e59d7bed523d94da1be003afc3aa0b [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
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>
Patrick Delaunay2f7d3a12021-02-24 11:19:43 +010012#include <dm/device_compat.h>
Etienne Carrierea26d0ec2020-09-09 18:44:02 +020013#include <dm/device-internal.h>
14#include <linux/arm-smccc.h>
15#include <linux/compat.h>
16
17#include "smt.h"
18
19#define SMCCC_RET_NOT_SUPPORTED ((unsigned long)-1)
20
21/**
22 * struct scmi_smccc_channel - Description of an SCMI SMCCC transport
23 * @func_id: SMCCC function ID used by the SCMI transport
24 * @smt: Shared memory buffer
25 */
26struct scmi_smccc_channel {
27 ulong func_id;
28 struct scmi_smt smt;
29};
30
31static int scmi_smccc_process_msg(struct udevice *dev, struct scmi_msg *msg)
32{
33 struct scmi_smccc_channel *chan = dev_get_priv(dev);
34 struct arm_smccc_res res;
35 int ret;
36
37 ret = scmi_write_msg_to_smt(dev, &chan->smt, msg);
38 if (ret)
39 return ret;
40
41 arm_smccc_smc(chan->func_id, 0, 0, 0, 0, 0, 0, 0, &res);
42 if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
43 ret = -ENXIO;
44 else
45 ret = scmi_read_resp_from_smt(dev, &chan->smt, msg);
46
47 scmi_clear_smt_channel(&chan->smt);
48
49 return ret;
50}
51
52static int scmi_smccc_probe(struct udevice *dev)
53{
54 struct scmi_smccc_channel *chan = dev_get_priv(dev);
55 u32 func_id;
56 int ret;
57
58 if (dev_read_u32(dev, "arm,smc-id", &func_id)) {
59 dev_err(dev, "Missing property func-id\n");
60 return -EINVAL;
61 }
62
63 chan->func_id = func_id;
64
65 ret = scmi_dt_get_smt_buffer(dev, &chan->smt);
66 if (ret) {
67 dev_err(dev, "Failed to get smt resources: %d\n", ret);
68 return ret;
69 }
70
71 return 0;
72}
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,
Simon Glass8a2b47f2020-12-03 16:55:17 -070087 .priv_auto = sizeof(struct scmi_smccc_channel),
Etienne Carrierea26d0ec2020-09-09 18:44:02 +020088 .probe = scmi_smccc_probe,
89 .ops = &scmi_smccc_ops,
90};