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 #ifndef CONFIG_SPL_BUILD 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 func_id = dev_read_u32_default(dev, "arm,smc-id", -ENODATA); 59 if (func_id == -ENODATA) { 60 dev_err(dev, "Missing property func-id\n"); 61 return -EINVAL; 62 } 63 64 chan->func_id = func_id; 65 66 ret = scmi_dt_get_smt_buffer(dev, &chan->smt); 67 if (ret) { 68 dev_err(dev, "Failed to get smt resources: %d\n", ret); 69 return ret; 70 } 71 72 return 0; 73 } 74 75 static const struct scmi_agent_ops scmi_smccc_ops = { 76 .process_msg = scmi_smccc_process_msg, 77 }; 78 #endif 79 80 static const struct udevice_id scmi_smccc_ids[] = { 81 { .compatible = "arm,scmi-smc" }, 82 { } 83 }; 84 85 U_BOOT_DRIVER(scmi_smccc) = { 86 .name = "scmi-over-smccc", 87 .id = UCLASS_SCMI_AGENT, 88 .of_match = scmi_smccc_ids, 89 .priv_auto_alloc_size = sizeof(struct scmi_smccc_channel), 90 #ifndef CONFIG_SPL_BUILD 91 .probe = scmi_smccc_probe, 92 .ops = &scmi_smccc_ops, 93 #endif 94 }; 95