entry.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SPDX-License-Identifier: BSD-3-Clause
  2. /*
  3. * Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved.
  4. * Copyright (c) 2019-2020, Linaro Limited
  5. */
  6. #include <assert.h>
  7. #include <drivers/scmi-msg.h>
  8. #include <drivers/scmi.h>
  9. #include "common.h"
  10. #pragma weak scmi_msg_get_clock_handler
  11. #pragma weak scmi_msg_get_rstd_handler
  12. #pragma weak scmi_msg_get_pd_handler
  13. #pragma weak scmi_msg_get_voltage_handler
  14. #pragma weak scmi_msg_get_sensor_handler
  15. scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg __unused)
  16. {
  17. return NULL;
  18. }
  19. scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg __unused)
  20. {
  21. return NULL;
  22. }
  23. scmi_msg_handler_t scmi_msg_get_pd_handler(struct scmi_msg *msg __unused)
  24. {
  25. return NULL;
  26. }
  27. scmi_msg_handler_t scmi_msg_get_voltage_handler(struct scmi_msg *msg __unused)
  28. {
  29. return NULL;
  30. }
  31. scmi_msg_handler_t scmi_msg_get_sensor_handler(struct scmi_msg *msg __unused)
  32. {
  33. return NULL;
  34. }
  35. void scmi_status_response(struct scmi_msg *msg, int32_t status)
  36. {
  37. assert(msg->out && msg->out_size >= sizeof(int32_t));
  38. memcpy(msg->out, &status, sizeof(int32_t));
  39. msg->out_size_out = sizeof(int32_t);
  40. }
  41. void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size)
  42. {
  43. /*
  44. * Output payload shall be at least the size of the status
  45. * Output buffer shall be at least be the size of the status
  46. * Output paylaod shall fit in output buffer
  47. */
  48. assert(payload && size >= sizeof(int32_t) && size <= msg->out_size &&
  49. msg->out && msg->out_size >= sizeof(int32_t));
  50. memcpy(msg->out, payload, size);
  51. msg->out_size_out = size;
  52. }
  53. void scmi_process_message(struct scmi_msg *msg)
  54. {
  55. scmi_msg_handler_t handler = NULL;
  56. switch (msg->protocol_id) {
  57. case SCMI_PROTOCOL_ID_BASE:
  58. handler = scmi_msg_get_base_handler(msg);
  59. break;
  60. case SCMI_PROTOCOL_ID_CLOCK:
  61. handler = scmi_msg_get_clock_handler(msg);
  62. break;
  63. case SCMI_PROTOCOL_ID_RESET_DOMAIN:
  64. handler = scmi_msg_get_rstd_handler(msg);
  65. break;
  66. case SCMI_PROTOCOL_ID_POWER_DOMAIN:
  67. handler = scmi_msg_get_pd_handler(msg);
  68. break;
  69. case SCMI_PROTOCOL_ID_SENSOR:
  70. handler = scmi_msg_get_sensor_handler(msg);
  71. break;
  72. default:
  73. break;
  74. }
  75. if (handler) {
  76. handler(msg);
  77. return;
  78. }
  79. ERROR("Agent %u Protocol 0x%x Message 0x%x: not supported\n",
  80. msg->agent_id, msg->protocol_id, msg->message_id);
  81. scmi_status_response(msg, SCMI_NOT_SUPPORTED);
  82. }