~kameliya/u-boot

ref: e8a10a02bd9ce6988942c393373d89dee5704c59 u-boot/drivers/firmware/scmi/smccc_agent.c -rw-r--r-- 2.0 KiB
e8a10a02 — Tom Rini Merge tag 'u-boot-stm32-20210312' of https://source.denx.de/u-boot/custodians/u-boot-stm 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2020 Linaro Limited.
 */

#define LOG_CATEGORY UCLASS_SCMI_AGENT

#include <common.h>
#include <dm.h>
#include <errno.h>
#include <scmi_agent.h>
#include <scmi_agent-uclass.h>
#include <dm/devres.h>
#include <dm/device_compat.h>
#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;
};

static int scmi_smccc_process_msg(struct udevice *dev, struct scmi_msg *msg)
{
	struct scmi_smccc_channel *chan = dev_get_priv(dev);
	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;
}

static int scmi_smccc_probe(struct udevice *dev)
{
	struct scmi_smccc_channel *chan = dev_get_priv(dev);
	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);
	if (ret) {
		dev_err(dev, "Failed to get smt resources: %d\n", ret);
		return ret;
	}

	return 0;
}

static const struct udevice_id scmi_smccc_ids[] = {
	{ .compatible = "arm,scmi-smc" },
	{ }
};

static const struct scmi_agent_ops scmi_smccc_ops = {
	.process_msg = scmi_smccc_process_msg,
};

U_BOOT_DRIVER(scmi_smccc) = {
	.name		= "scmi-over-smccc",
	.id		= UCLASS_SCMI_AGENT,
	.of_match	= scmi_smccc_ids,
	.priv_auto	= sizeof(struct scmi_smccc_channel),
	.probe		= scmi_smccc_probe,
	.ops		= &scmi_smccc_ops,
};