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/device-internal.h> 12 #include <dm/read.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 */ 25 struct scmi_smccc_channel { 26 ulong func_id; 27 struct scmi_smt smt; 28 }; 29 30 static 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 51 static 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 func_id = dev_read_u32_default(dev, "arm,smc-id", -ENODATA); 58 if (func_id == -ENODATA) { 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, 87 .priv_auto_alloc_size = sizeof(struct scmi_smccc_channel), 88 .probe = scmi_smccc_probe, 89 .ops = &scmi_smccc_ops, 90 }; 91