Etienne Carriere | a26d0ec | 2020-09-09 18:44:02 +0200 | [diff] [blame] | 1 | // 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 Delaunay | 2f7d3a1 | 2021-02-24 11:19:43 +0100 | [diff] [blame^] | 12 | #include <dm/device_compat.h> |
Etienne Carriere | a26d0ec | 2020-09-09 18:44:02 +0200 | [diff] [blame] | 13 | #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 | */ |
| 26 | struct scmi_smccc_channel { |
| 27 | ulong func_id; |
| 28 | struct scmi_smt smt; |
| 29 | }; |
| 30 | |
| 31 | static 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 | |
| 52 | static 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 | |
| 74 | static const struct udevice_id scmi_smccc_ids[] = { |
| 75 | { .compatible = "arm,scmi-smc" }, |
| 76 | { } |
| 77 | }; |
| 78 | |
| 79 | static const struct scmi_agent_ops scmi_smccc_ops = { |
| 80 | .process_msg = scmi_smccc_process_msg, |
| 81 | }; |
| 82 | |
| 83 | U_BOOT_DRIVER(scmi_smccc) = { |
| 84 | .name = "scmi-over-smccc", |
| 85 | .id = UCLASS_SCMI_AGENT, |
| 86 | .of_match = scmi_smccc_ids, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 87 | .priv_auto = sizeof(struct scmi_smccc_channel), |
Etienne Carriere | a26d0ec | 2020-09-09 18:44:02 +0200 | [diff] [blame] | 88 | .probe = scmi_smccc_probe, |
| 89 | .ops = &scmi_smccc_ops, |
| 90 | }; |