smccc_agent.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2020 Linaro Limited.
  4. */
  5. #define LOG_CATEGORY UCLASS_SCMI_AGENT
  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>
  12. #include <dm/device_compat.h>
  13. #include <dm/device-internal.h>
  14. #include <linux/arm-smccc.h>
  15. #include <linux/compat.h>
  16. #include "smt.h"
  17. #define SMCCC_RET_NOT_SUPPORTED ((unsigned long)-1)
  18. /**
  19. * struct scmi_smccc_channel - Description of an SCMI SMCCC transport
  20. * @func_id: SMCCC function ID used by the SCMI transport
  21. * @smt: Shared memory buffer
  22. */
  23. struct scmi_smccc_channel {
  24. ulong func_id;
  25. struct scmi_smt smt;
  26. };
  27. static int scmi_smccc_process_msg(struct udevice *dev, struct scmi_msg *msg)
  28. {
  29. struct scmi_smccc_channel *chan = dev_get_priv(dev);
  30. struct arm_smccc_res res;
  31. int ret;
  32. ret = scmi_write_msg_to_smt(dev, &chan->smt, msg);
  33. if (ret)
  34. return ret;
  35. arm_smccc_smc(chan->func_id, 0, 0, 0, 0, 0, 0, 0, &res);
  36. if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
  37. ret = -ENXIO;
  38. else
  39. ret = scmi_read_resp_from_smt(dev, &chan->smt, msg);
  40. scmi_clear_smt_channel(&chan->smt);
  41. return ret;
  42. }
  43. static int scmi_smccc_probe(struct udevice *dev)
  44. {
  45. struct scmi_smccc_channel *chan = dev_get_priv(dev);
  46. u32 func_id;
  47. int ret;
  48. if (dev_read_u32(dev, "arm,smc-id", &func_id)) {
  49. dev_err(dev, "Missing property func-id\n");
  50. return -EINVAL;
  51. }
  52. chan->func_id = func_id;
  53. ret = scmi_dt_get_smt_buffer(dev, &chan->smt);
  54. if (ret) {
  55. dev_err(dev, "Failed to get smt resources: %d\n", ret);
  56. return ret;
  57. }
  58. return 0;
  59. }
  60. static const struct udevice_id scmi_smccc_ids[] = {
  61. { .compatible = "arm,scmi-smc" },
  62. { }
  63. };
  64. static const struct scmi_agent_ops scmi_smccc_ops = {
  65. .process_msg = scmi_smccc_process_msg,
  66. };
  67. U_BOOT_DRIVER(scmi_smccc) = {
  68. .name = "scmi-over-smccc",
  69. .id = UCLASS_SCMI_AGENT,
  70. .of_match = scmi_smccc_ids,
  71. .priv_auto = sizeof(struct scmi_smccc_channel),
  72. .probe = scmi_smccc_probe,
  73. .ops = &scmi_smccc_ops,
  74. };